Skip to content

Commit

Permalink
fix sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
strehle committed Sep 19, 2023
1 parent 379fe73 commit 5a85e54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand Down Expand Up @@ -543,7 +544,7 @@ public ActionResult changeSecret(@PathVariable String client_id, @RequestBody Se
return result;
}

@RequestMapping(value = "/oauth/clients/{client_id}/clientjwt", method = RequestMethod.PUT)
@PutMapping(value = "/oauth/clients/{client_id}/clientjwt")
@ResponseBody
public ActionResult changeClientJwt(@PathVariable String client_id, @RequestBody ClientJwtChangeRequest change) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,13 @@ private static ClientJwtConfiguration parseJwkSet(String privateKeyJwt) {
}

private static ClientJwtConfiguration parseJwksUri(String privateKeyUrl) {
ClientJwtConfiguration clientJwtConfiguration;
String normalizedUri = null;
String normalizedUri;
try {
normalizedUri = UaaUrlUtils.normalizeUri(privateKeyUrl);
} catch (IllegalArgumentException e) {
throw new InvalidClientDetailsException("Client jwt configuration with invalid URI", e);
}
clientJwtConfiguration = new ClientJwtConfiguration(normalizedUri, null);
ClientJwtConfiguration clientJwtConfiguration = new ClientJwtConfiguration(normalizedUri, null);
clientJwtConfiguration.validateJwksUri();
return clientJwtConfiguration;
}
Expand All @@ -167,7 +166,7 @@ private boolean validateJwkSet() {
throw new InvalidClientDetailsException("Invalid private_key_jwt: jwk set is empty of exceeds to maximum of keys. max: + " + MAX_KEY_SIZE);
}
Set<String> keyId = new HashSet<>();
keyList.forEach(key -> {
keyList.forEach((JsonWebKey key) -> {
if (!StringUtils.hasText(key.getKid())) {
throw new InvalidClientDetailsException("Invalid private_key_jwt: kid is required attribute");
}
Expand All @@ -180,19 +179,19 @@ private boolean validateJwkSet() {
}

private boolean validateJwksUri() {
URI jwksUri;
URI validateJwksUri;
try {
jwksUri = URI.create(this.jwksUri);
validateJwksUri = URI.create(this.jwksUri);
} catch (IllegalArgumentException e) {
throw new InvalidClientDetailsException("Invalid private_key_jwt: jwks_uri must be URI complaint", e);
}
if (!jwksUri.isAbsolute()) {
if (!validateJwksUri.isAbsolute()) {
throw new InvalidClientDetailsException("Invalid private_key_jwt: jwks_uri must be an absolute URL");
}
if (!"https".equals(jwksUri.getScheme()) && !"http".equals(jwksUri.getScheme())) {
if (!"https".equals(validateJwksUri.getScheme()) && !"http".equals(validateJwksUri.getScheme())) {
throw new InvalidClientDetailsException("Invalid private_key_jwt: jwks_uri must be either using https or http");
}
if ("http".equals(jwksUri.getScheme()) && !jwksUri.getHost().endsWith("localhost")) {
if ("http".equals(validateJwksUri.getScheme()) && !validateJwksUri.getHost().endsWith("localhost")) {
throw new InvalidClientDetailsException("Invalid private_key_jwt: jwks_uri with http is not on localhost");
}
return true;
Expand All @@ -212,7 +211,7 @@ public static ClientJwtConfiguration readValue(UaaClientDetails clientDetails) {
!(clientDetails.getClientJwtConfig() instanceof String)) {
return null;
}
return JsonUtils.readValue((String) clientDetails.getClientJwtConfig(), ClientJwtConfiguration.class);
return JsonUtils.readValue(clientDetails.getClientJwtConfig(), ClientJwtConfiguration.class);
}

/**
Expand Down Expand Up @@ -272,7 +271,7 @@ public static ClientJwtConfiguration merge(ClientJwtConfiguration existingConfig
JsonWebKeySet<JsonWebKey> existingKeySet = existingConfig.jwkSet;
List<JsonWebKey> existingKeys = new ArrayList<>(existingKeySet.getKeys());
List<JsonWebKey> newKeys = new ArrayList<>();
newConfig.getJwkSet().getKeys().forEach(key -> {
newConfig.getJwkSet().getKeys().forEach((JsonWebKey key) -> {
if (existingKeys.contains(key)) {
if (overwrite) {
existingKeys.remove(key);
Expand Down

0 comments on commit 5a85e54

Please sign in to comment.