Skip to content

Commit

Permalink
Merge branch 'feature/sse_code_smells_removals' into 'develop'
Browse files Browse the repository at this point in the history
added lombok.config

See merge request adorsys/xs2a/ledgers!606
  • Loading branch information
Serhii Semenykhin committed Nov 27, 2023
2 parents 178b4a0 + 410c282 commit ad3e27e
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
@Service
@RequiredArgsConstructor
public class KeycloakTokenServiceImpl implements KeycloakTokenService {
private static final String CLIENT_ID_KEY = "client_id";
private static final String CLIENT_SECRET_KEY = "client_secret";
private static final String ACCESS_TOKEN_KEY = "access_token";
private static final String REFRESH_TOKEN_KEY = "refresh_token";
private static final String GRANT_TYPE_KEY = "grant_type";
private static final String PASSWORD_KEY = "password";

@Value("${keycloak.resource:}")
private String clientId;
@Value("${keycloak.credentials.secret:}")
Expand All @@ -42,20 +49,20 @@ public class KeycloakTokenServiceImpl implements KeycloakTokenService {
@Override
public BearerTokenTO login(String username, String password) {
MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
formParams.add("grant_type", "password");
formParams.add(GRANT_TYPE_KEY, "password");
formParams.add("username", username);
formParams.add("password", password);
formParams.add("client_id", clientId);
formParams.add("client_secret", clientSecret);
formParams.add(PASSWORD_KEY, password);
formParams.add(CLIENT_ID_KEY, clientId);
formParams.add(CLIENT_SECRET_KEY, clientSecret);
ResponseEntity<Map<String, ?>> resp = keycloakTokenRestClient.login(formParams);
HttpStatus statusCode = (HttpStatus) resp.getStatusCode();
if (HttpStatus.OK != statusCode) {
log.error("Could not obtain token by user credentials [{}]", username); //todo: throw specific exception
log.error("Could not obtain token by user credentials [{}]", username);
}
Map<String, ?> body = Objects.requireNonNull(resp).getBody();
BearerTokenTO bearerTokenTO = new BearerTokenTO();
bearerTokenTO.setAccess_token((String) Objects.requireNonNull(body).get("access_token"));
bearerTokenTO.setRefresh_token((String) Objects.requireNonNull(body).get("refresh_token"));
bearerTokenTO.setAccess_token((String) Objects.requireNonNull(body).get(ACCESS_TOKEN_KEY));
bearerTokenTO.setRefresh_token((String) Objects.requireNonNull(body).get(REFRESH_TOKEN_KEY));
return bearerTokenTO;
}

Expand All @@ -71,12 +78,12 @@ public BearerTokenTO exchangeToken(String oldToken, Integer timeToLive, String s
public BearerTokenTO validate(String token) {
MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
formParams.add("token", token);
formParams.add("client_id", clientId);
formParams.add("client_secret", clientSecret);
formParams.add(CLIENT_ID_KEY, clientId);
formParams.add(CLIENT_SECRET_KEY, clientSecret);
ResponseEntity<AccessToken> resp = keycloakTokenRestClient.validate(formParams);
HttpStatus statusCode = (HttpStatus) resp.getStatusCode();
if (HttpStatus.OK != statusCode) {
log.error("Could not validate token"); //todo: throw specific exception
log.error("Could not validate token");
}
Map<String, Object> claimsMap = Optional.ofNullable(resp.getBody())
.map(JsonWebToken::getOtherClaims)
Expand All @@ -90,10 +97,10 @@ public BearerTokenTO validate(String token) {
@Override
public BearerTokenTO refreshToken(String refreshToken) {
MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
formParams.add("grant_type", "refresh_token");
formParams.add("client_id", clientId);
formParams.add("client_secret", clientSecret);
formParams.add("refresh_token", refreshToken);
formParams.add(GRANT_TYPE_KEY, "refresh_token");
formParams.add(CLIENT_ID_KEY, clientId);
formParams.add(CLIENT_SECRET_KEY, clientSecret);
formParams.add(REFRESH_TOKEN_KEY, refreshToken);
ResponseEntity<Map<String, ?>> resp = keycloakTokenRestClient.login(formParams);
HttpStatus statusCode = (HttpStatus) resp.getStatusCode();
if (HttpStatus.OK != statusCode) {
Expand All @@ -102,8 +109,8 @@ public BearerTokenTO refreshToken(String refreshToken) {
}
Map<String, ?> body = Objects.requireNonNull(resp).getBody();
BearerTokenTO bearerTokenTO = new BearerTokenTO();
bearerTokenTO.setAccess_token((String) Objects.requireNonNull(body).get("access_token"));
bearerTokenTO.setRefresh_token((String) Objects.requireNonNull(body).get("refresh_token"));
bearerTokenTO.setAccess_token((String) Objects.requireNonNull(body).get(ACCESS_TOKEN_KEY));
bearerTokenTO.setRefresh_token((String) Objects.requireNonNull(body).get(REFRESH_TOKEN_KEY));

return bearerTokenTO;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ default AccessTokenTO toAccessTokenFromJwt(Jwt source) {
token.setIat(Date.from(source.getIssuedAt()));
token.setRole(getLedgersUserRolesFromJwt(source));
token.setSub(source.getClaimAsString("sub"));
token.setScopes(new HashSet(Arrays.asList(source.getClaimAsString("scope").split(" "))));
token.setScopes(new HashSet<>(Arrays.asList(source.getClaimAsString("scope").split(" "))));
token.setLogin(source.getClaimAsString("name"));
token.setExp(Date.from(source.getExpiresAt()));
token.setJti(source.getClaimAsString("jti"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ default KeycloakUser toKeycloakUser(UserRepresentation userRepresentation) {
}

default UserRepresentation toUpdateUserPresentation(UserRepresentation userRepresentation, KeycloakUser user) {
//NOSONAR TODO: add fields to update if needed
userRepresentation.setUsername(user.getLogin());
userRepresentation.setFirstName(user.getFirstName());
userRepresentation.setLastName(user.getLastName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private AccessTokenResponse buildResponse(RealmModel realm,
}

private void updateTokenExpiration(AccessToken token, TokenConfiguration tokenConfiguration) {
token.expiration(tokenConfiguration.computeTokenExpiration(token.getExpiration(), true));
token.expiration(tokenConfiguration.computeTokenExpiration(token.getExp().intValue(), true));
}

private void updateScope(AccessToken token, TokenConfiguration tokenConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ public void createAccounts() {
} finally {
DepositAccountDetailsBO account = depositAccountService.getAccountDetailsByIbanAndCurrency(details.getIban(), details.getCurrency(), LocalDateTime.now(), true);
mockbankInitData.getUserIdByIban(details.getIban(), userId)
.forEach(id -> {
mockbankInitData.getAccountAccess(details.getIban(), id)
.ifPresent(accountAccessTO -> {
updateAccountAccess(accountAccessTO, scaInfoTO, account, id);
});
});
.forEach(id -> mockbankInitData.getAccountAccess(details.getIban(), id)
.ifPresent(accountAccessTO -> updateAccountAccess(accountAccessTO, scaInfoTO, account, id))
);
updateBalanceIfRequired(details, account);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void testGetAccountAccess() {
Optional<AccountAccessTO> result = mockbankInitData.getAccountAccess("DE32760700240271232100", "g.manager");
Assertions.assertFalse(result.isEmpty());
AccountAccessTO accountAccessTO = result.get();
Assertions.assertEquals(accountAccessTO.getScaWeight(), 90);
Assertions.assertEquals(90, accountAccessTO.getScaWeight());
Assertions.assertEquals(accountAccessTO.getCurrency(), Currency.getInstance("EUR"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class DepositAccountTransactionServiceImplTest {

private static final ObjectMapper STATIC_MAPPER;

private DepositAccountMapper depositAccountMapper = Mappers.getMapper(DepositAccountMapper.class);
private final DepositAccountMapper depositAccountMapper = Mappers.getMapper(DepositAccountMapper.class);

static {
STATIC_MAPPER = new ObjectMapper()
Expand Down Expand Up @@ -172,8 +172,8 @@ void depositCash_OK() throws IOException {
assertThat(transactionDetails.getEndToEndId()).isEqualTo(line.getId());
assertThat(transactionDetails.getTransactionId()).isNotBlank();
assertThat(transactionDetails.getBookingDate()).isEqualTo(transactionDetails.getValueDate());
assertThat(transactionDetails.getCreditorAccount()).isEqualToComparingFieldByField(depositAccountMapper.toAccountReferenceBO(getDepositAccount()));
assertThat(transactionDetails.getTransactionAmount()).isEqualToComparingFieldByField(amount);
assertThat(transactionDetails.getCreditorAccount()).usingRecursiveComparison().isEqualTo(depositAccountMapper.toAccountReferenceBO(getDepositAccount()));
assertThat(transactionDetails.getTransactionAmount()).usingRecursiveComparison().isEqualTo(amount);
}
}

Expand Down Expand Up @@ -206,7 +206,7 @@ void bookPayment_single_same_currency() throws IOException {

PostingBO posting = postingCaptor.getValue();
List<PostingLineBO> lines = posting.getLines();
assertThat(lines.size()).isEqualTo(2);
assertThat(lines).hasSize(2);
assertThat(dcAmountOk(lines)).isTrue();

PostingLineBO line1 = lines.get(0);
Expand Down Expand Up @@ -249,7 +249,7 @@ void bookPayment_single_two_different_currency() throws IOException {

PostingBO posting = postingCaptor.getValue();
List<PostingLineBO> lines = posting.getLines();
assertThat(lines.size()).isEqualTo(4);
assertThat(lines).hasSize(4);
assertThat(dcAmountOk(lines)).isTrue();

PostingLineBO line1 = lines.get(0);
Expand Down Expand Up @@ -325,7 +325,7 @@ void bookPayment_single_three_different_currency() throws IOException {

PostingBO posting = postingCaptor.getValue();
List<PostingLineBO> lines = posting.getLines();
assertThat(lines.size()).isEqualTo(4);
assertThat(lines).hasSize(4);
assertThat(dcAmountOk(lines)).isTrue();

PostingLineBO line1 = lines.get(0);
Expand Down Expand Up @@ -384,7 +384,7 @@ void bookPayment_bulk_same_currency_batchBookingPreferredTrue() throws IOExcepti

PostingBO posting = postingCaptor.getValue();
List<PostingLineBO> lines = posting.getLines();
assertThat(lines.size()).isEqualTo(2);
assertThat(lines).hasSize(2);
assertThat(dcAmountOk(lines)).isTrue();

PostingLineBO line1 = lines.get(0);
Expand Down Expand Up @@ -428,7 +428,7 @@ void bookPayment_bulk_same_currency_batchBookingPreferredFalse() throws IOExcept

PostingBO posting = postingCaptor.getValue();
List<PostingLineBO> lines = posting.getLines();
assertThat(lines.size()).isEqualTo(2);
assertThat(lines).hasSize(2);
assertThat(dcAmountOk(lines)).isTrue();

PostingLineBO line1 = lines.get(0);
Expand Down Expand Up @@ -473,11 +473,11 @@ void bookPayment_bulk_two_different_currency() {

PostingBO posting = postingCaptor.getValue();
List<PostingLineBO> lines = posting.getLines();
assertThat(lines.size()).isEqualTo(7);
assertThat(lines).hasSize(7);
List<PostingLineBO> creditLines = lines.stream().filter(l -> l.getCreditAmount().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
List<PostingLineBO> debitLines = lines.stream().filter(l -> l.getDebitAmount().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
assertThat(creditLines.size()).isEqualTo(4);
assertThat(debitLines.size()).isEqualTo(3);
assertThat(creditLines).hasSize(4);
assertThat(debitLines).hasSize(3);
assertEquals(debitLines.stream().map(PostingLineBO::getDebitAmount).reduce(BigDecimal::add),
creditLines.stream().map(PostingLineBO::getCreditAmount).reduce(BigDecimal::add));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private boolean hasAnyScope(String... scopes) {

private Set<String> getScopes() {
Jwt credentials = (Jwt) getAuthentication().getCredentials();
return new HashSet(Arrays.asList(credentials.getClaimAsString("scope").split(" ")));
return new HashSet<>(Arrays.asList(credentials.getClaimAsString("scope").split(" ")));
}

private boolean isEnabledAccountIban(String iban) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public enum AccountStatusTO {
DELETED("deleted"),
BLOCKED("blocked");

private final static Map<String, AccountStatusTO> container = new HashMap<>();
private static final Map<String, AccountStatusTO> container = new HashMap<>();

static {
for (AccountStatusTO accountStatus : values()) {
container.put(accountStatus.getValue(), accountStatus);
}
}

private String value;
private final String value;

AccountStatusTO(String value) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public enum UsageTypeTO {
PRIV("PRIV"),
ORGA("ORGA");

private final static Map<String, UsageTypeTO> container = new HashMap<>();
private static final Map<String, UsageTypeTO> container = new HashMap<>();

static {
for (UsageTypeTO usageType : values()) {
container.put(usageType.getValue(), usageType);
}
}

private String value;
private final String value;


UsageTypeTO(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public class Posting extends HashRecord {
@Convert(converter = LocalDateTimeConverter.class)
private LocalDateTime valTime;

// todo: add description to this field
@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL}, orphanRemoval = true)
@JoinColumn(name = "posting_id")
private List<PostingLine> lines = new ArrayList<>();
Expand All @@ -162,7 +161,7 @@ public class Posting extends HashRecord {
private String discardingId;

public Posting hash() {
// Skipp computation if a hash exists. Original value
// Skip computation if a hash exists. Original value
// shall not be overriden.
if (hash != null) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ public abstract class NamedBO {

private LocalDateTime created;

// todo: seems this property should be moved from base class
private String userDetails;

// todo: seems this property should be moved from base class
/*The short description of this entity*/
private String shortDesc;

// todo: seems this property should be moved from base class
/*The long description of this entity*/
private String longDesc;

Expand Down
Loading

0 comments on commit ad3e27e

Please sign in to comment.