Skip to content

Commit

Permalink
Renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
strehle committed Aug 24, 2023
1 parent c69b748 commit 97c06aa
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class ClientDetailsCreation extends BaseClientDetails {
@JsonProperty("secondary_client_secret")
private String secondaryClientSecret;

@JsonProperty("private_key_url")
private String privateKeyUrl;
@JsonProperty("jwks_uri")
private String jsonWebKeyUri;

@JsonProperty("private_key_set")
private String privateKeySet;
@JsonProperty("jwks")
private String jsonWebKeySet;

@JsonIgnore
public String getSecondaryClientSecret() {
Expand All @@ -28,19 +28,19 @@ public void setSecondaryClientSecret(final String secondaryClientSecret) {
this.secondaryClientSecret = secondaryClientSecret;
}

public String getPrivateKeyUrl() {
return privateKeyUrl;
public String getJsonWebKeyUri() {
return jsonWebKeyUri;
}

public void setPrivateKeyUrl(String privateKeyUrl) {
this.privateKeyUrl = privateKeyUrl;
public void setJsonWebKeyUri(String jsonWebKeyUri) {
this.jsonWebKeyUri = jsonWebKeyUri;
}

public String getPrivateKeySet() {
return privateKeySet;
public String getJsonWebKeySet() {
return jsonWebKeySet;
}

public void setPrivateKeySet(String privateKeySet) {
this.privateKeySet = privateKeySet;
public void setJsonWebKeySet(String jsonWebKeySet) {
this.jsonWebKeySet = jsonWebKeySet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@ public enum ChangeMode {
@JsonProperty("kid")
private String keyId;
@JsonProperty("jwks_uri")
private String keyUrl;
private String jsonWebKeyUri;
@JsonProperty("jwks")
private String keyConfig;
private String jsonWebKeySet;
@JsonProperty("client_id")
private String clientId;
private ChangeMode changeMode = ADD;

public ClientJwtChangeRequest() {
}

public ClientJwtChangeRequest(String clientId, String keyUrl, String keyConfig) {
this.keyUrl = keyUrl;
this.keyConfig = keyConfig;
public ClientJwtChangeRequest(String clientId, String jsonWebKeyUri, String jsonWebKeySet) {
this.jsonWebKeyUri = jsonWebKeyUri;
this.jsonWebKeySet = jsonWebKeySet;
this.clientId = clientId;
}

public String getKeyUrl() {
return keyUrl;
public String getJsonWebKeyUri() {
return jsonWebKeyUri;
}

public void setKeyUrl(String keyUrl) {
this.keyUrl = keyUrl;
public void setJsonWebKeyUri(String jsonWebKeyUri) {
this.jsonWebKeyUri = jsonWebKeyUri;
}

public String getKeyConfig() {
return keyConfig;
public String getJsonWebKeySet() {
return jsonWebKeySet;
}

public void setKeyConfig(String keyConfig) {
this.keyConfig = keyConfig;
public void setJsonWebKeySet(String jsonWebKeySet) {
this.jsonWebKeySet = jsonWebKeySet;
}

public String getClientId() {
Expand All @@ -76,6 +76,6 @@ public void setKeyId(String keyId) {
}

public String getKey() {
return keyUrl != null ? keyUrl : keyConfig;
return jsonWebKeyUri != null ? jsonWebKeyUri : jsonWebKeySet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ void testRequestSerialization() {
ClientJwtChangeRequest def = new ClientJwtChangeRequest(null, null, null);
def.setKeyId("key-1");
def.setChangeMode(ClientJwtChangeRequest.ChangeMode.DELETE);
def.setKeyUrl("http://localhost:8080/uaa/token_key");
def.setKeyConfig("{}");
def.setJsonWebKeyUri("http://localhost:8080/uaa/token_key");
def.setJsonWebKeySet("{}");
def.setClientId("admin");
String jsonRequest = JsonUtils.writeValueAsString(def);
ClientJwtChangeRequest request = JsonUtils.readValue(jsonRequest, ClientJwtChangeRequest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ private void addNewClients() {
String jwksUri = (String) map.get("jwks_uri");
ClientJwtConfiguration keyConfig = ClientJwtConfiguration.parse(UaaUrlUtils.normalizeUri(jwksUri), null);
if (keyConfig != null && keyConfig.getCleanString() != null) {
clientRegistrationService.addClientKeyConfig(clientId, keyConfig.getPrivateKeyJwtUrl(), IdentityZone.getUaaZoneId(), override);
clientRegistrationService.addClientJwtConfig(clientId, keyConfig.getJwksUri(), IdentityZone.getUaaZoneId(), override);
}
} else if (map.get("jwks") instanceof String) {
String jwks = (String) map.get("jwks");
ClientJwtConfiguration keyConfig = ClientJwtConfiguration.parse(null, jwks);
if (keyConfig != null && keyConfig.getCleanString() != null) {
clientRegistrationService.addClientKeyConfig(clientId, keyConfig.getCleanString(), IdentityZone.getUaaZoneId(), override);
clientRegistrationService.addClientJwtConfig(clientId, keyConfig.getCleanString(), IdentityZone.getUaaZoneId(), override);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public ActionResult changeClientJwt(@PathVariable String client_id, @RequestBody
switch (change.getChangeMode()){
case ADD :
if (change.getKey() != null) {
clientRegistrationService.addClientKeyConfig(client_id, change.getKey(), IdentityZoneHolder.get().getId(), false);
clientRegistrationService.addClientJwtConfig(client_id, change.getKey(), IdentityZoneHolder.get().getId(), false);
result = new ActionResult("ok", "Client jwt configuration is added");
} else {
result = new ActionResult("ok", "No key added");
Expand All @@ -569,13 +569,13 @@ public ActionResult changeClientJwt(@PathVariable String client_id, @RequestBody
case DELETE :
String deleteString = change.getKeyId() == null ? change.getKey() : change.getKeyId();
if (clientKeyConfig != null && deleteString != null) {
clientRegistrationService.deleteClientKeyConfig(client_id, deleteString, IdentityZoneHolder.get().getId());
clientRegistrationService.deleteClientJwtConfig(client_id, deleteString, IdentityZoneHolder.get().getId());
}
result = new ActionResult("ok", "Client jwt configuration is deleted");
break;

default:
clientRegistrationService.addClientKeyConfig(client_id, change.getKey(), IdentityZoneHolder.get().getId(), true);
clientRegistrationService.addClientJwtConfig(client_id, change.getKey(), IdentityZoneHolder.get().getId(), true);
result = new ActionResult("ok", "Client jwt configuration updated");
}
clientSecretChanges.incrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ public ClientDetails validate(ClientDetails prototype, boolean create, boolean c

if (prototype instanceof ClientDetailsCreation) {
ClientDetailsCreation clientDetailsCreation = (ClientDetailsCreation) prototype;
if (StringUtils.hasText(clientDetailsCreation.getPrivateKeyUrl()) || StringUtils.hasText(clientDetailsCreation.getPrivateKeySet())) {
ClientJwtConfiguration clientJwtConfiguration = ClientJwtConfiguration.parse(clientDetailsCreation.getPrivateKeyUrl(),
clientDetailsCreation.getPrivateKeySet());
if (StringUtils.hasText(clientDetailsCreation.getJsonWebKeyUri()) || StringUtils.hasText(clientDetailsCreation.getJsonWebKeySet())) {
ClientJwtConfiguration clientJwtConfiguration = ClientJwtConfiguration.parse(clientDetailsCreation.getJsonWebKeyUri(),
clientDetailsCreation.getJsonWebKeySet());
if (clientJwtConfiguration != null) {
clientJwtConfiguration.writeValue(client);
} else {
logger.warn("Client configuration with private_key_jwt not valid");
logger.warn("Client with client jwt configuration not valid");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,36 @@ public class ClientJwtConfiguration implements Cloneable{
private static final int MAX_KEY_SIZE = 10;

@JsonProperty("jwks_uri")
private String privateKeyJwtUrl;
private String jwksUri;

@JsonProperty("jwks")
private JsonWebKeySet<JsonWebKey> privateKeyJwt;
private JsonWebKeySet<JsonWebKey> jwkSet;

public ClientJwtConfiguration() {
}

public ClientJwtConfiguration(final String privateKeyJwtUrl, final JsonWebKeySet<JsonWebKey> webKeySet) {
this.privateKeyJwtUrl = privateKeyJwtUrl;
privateKeyJwt = webKeySet;
if (privateKeyJwt != null) {
public ClientJwtConfiguration(final String jwksUri, final JsonWebKeySet<JsonWebKey> webKeySet) {
this.jwksUri = jwksUri;
jwkSet = webKeySet;
if (jwkSet != null) {
validateJwkSet();
}
}

public String getPrivateKeyJwtUrl() {
return this.privateKeyJwtUrl;
public String getJwksUri() {
return this.jwksUri;
}

public void setPrivateKeyJwtUrl(final String privateKeyJwtUrl) {
this.privateKeyJwtUrl = privateKeyJwtUrl;
public void setJwksUri(final String jwksUri) {
this.jwksUri = jwksUri;
}

public JsonWebKeySet<JsonWebKey> getPrivateKeyJwt() {
return this.privateKeyJwt;
public JsonWebKeySet<JsonWebKey> getJwkSet() {
return this.jwkSet;
}

public void setPrivateKeyJwt(final JsonWebKeySet<JsonWebKey> privateKeyJwt) {
this.privateKeyJwt = privateKeyJwt;
public void setJwkSet(final JsonWebKeySet<JsonWebKey> jwkSet) {
this.jwkSet = jwkSet;
}

@Override
Expand All @@ -76,11 +76,11 @@ public boolean equals(Object o) {

if (o instanceof ClientJwtConfiguration) {
ClientJwtConfiguration that = (ClientJwtConfiguration) o;
if (!Objects.equals(privateKeyJwtUrl, that.privateKeyJwtUrl)) return false;
if (privateKeyJwt != null && that.privateKeyJwt != null) {
return privateKeyJwt.getKeys().equals(that.privateKeyJwt.getKeys());
if (!Objects.equals(jwksUri, that.jwksUri)) return false;
if (jwkSet != null && that.jwkSet != null) {
return jwkSet.getKeys().equals(that.jwkSet.getKeys());
} else {
return Objects.equals(privateKeyJwt, that.privateKeyJwt);
return Objects.equals(jwkSet, that.jwkSet);
}
}
return false;
Expand All @@ -90,8 +90,8 @@ public boolean equals(Object o) {
public int hashCode() {
int result = super.hashCode();

result = 31 * result + (privateKeyJwtUrl != null ? privateKeyJwtUrl.hashCode() : 0);
result = 31 * result + (privateKeyJwt != null ? privateKeyJwt.hashCode() : 0);
result = 31 * result + (jwksUri != null ? jwksUri.hashCode() : 0);
result = 31 * result + (jwkSet != null ? jwkSet.hashCode() : 0);
return result;
}

Expand All @@ -103,10 +103,10 @@ public Object clone() throws CloneNotSupportedException {
@JsonIgnore
public String getCleanString() {
try {
if (UaaUrlUtils.isUrl(this.privateKeyJwtUrl)) {
return this.privateKeyJwtUrl;
} else if (this.privateKeyJwt != null && !ObjectUtils.isEmpty(this.privateKeyJwt.getKeySetMap())) {
return JWKSet.parse(this.privateKeyJwt.getKeySetMap()).toString(true);
if (UaaUrlUtils.isUrl(this.jwksUri)) {
return this.jwksUri;
} else if (this.jwkSet != null && !ObjectUtils.isEmpty(this.jwkSet.getKeySetMap())) {
return JWKSet.parse(this.jwkSet.getKeySetMap()).toString(true);
}
} catch (IllegalStateException | JsonUtils.JsonUtilException | ParseException e) {
throw new InvalidClientDetailsException("Client jwt configuration configuration fails ", e);
Expand Down Expand Up @@ -148,7 +148,7 @@ public static ClientJwtConfiguration parse(String privateKeyUrl, String privateK
}

private boolean validateJwkSet() {
List<JsonWebKey> keyList = privateKeyJwt.getKeys();
List<JsonWebKey> keyList = jwkSet.getKeys();
if (keyList.isEmpty() || keyList.size() > MAX_KEY_SIZE) {
throw new InvalidClientDetailsException("Invalid private_key_jwt: jwk set is empty of exceeds to maximum of keys. max: + " + MAX_KEY_SIZE);
}
Expand All @@ -168,7 +168,7 @@ private boolean validateJwkSet() {
private boolean validateJwksUri() {
URI jwksUri;
try {
jwksUri = URI.create(privateKeyJwtUrl);
jwksUri = URI.create(this.jwksUri);
} catch (IllegalArgumentException e) {
throw new InvalidClientDetailsException("Invalid private_key_jwt: jwks_uri must be URI complaint", e);
}
Expand Down Expand Up @@ -244,25 +244,25 @@ public static ClientJwtConfiguration merge(ClientJwtConfiguration existingConfig
return existingConfig;
}
ClientJwtConfiguration result = null;
if (newConfig.privateKeyJwtUrl != null) {
if (newConfig.jwksUri != null) {
if (overwrite) {
result = new ClientJwtConfiguration(newConfig.privateKeyJwtUrl, null);
result = new ClientJwtConfiguration(newConfig.jwksUri, null);
} else {
result = existingConfig;
}
}
if (newConfig.privateKeyJwt != null) {
if (existingConfig.privateKeyJwt == null) {
if (newConfig.jwkSet != null) {
if (existingConfig.jwkSet == null) {
if (overwrite) {
result = new ClientJwtConfiguration(null, newConfig.privateKeyJwt);
result = new ClientJwtConfiguration(null, newConfig.jwkSet);
} else {
result = existingConfig;
}
} else {
JsonWebKeySet<JsonWebKey> existingKeySet = existingConfig.privateKeyJwt;
JsonWebKeySet<JsonWebKey> existingKeySet = existingConfig.jwkSet;
List<JsonWebKey> existingKeys = new ArrayList<>(existingKeySet.getKeys());
List<JsonWebKey> newKeys = new ArrayList<>();
newConfig.getPrivateKeyJwt().getKeys().forEach(key -> {
newConfig.getJwkSet().getKeys().forEach(key -> {
if (existingKeys.contains(key)) {
if (overwrite) {
existingKeys.remove(key);
Expand All @@ -288,24 +288,24 @@ public static ClientJwtConfiguration delete(ClientJwtConfiguration existingConfi
return existingConfig;
}
ClientJwtConfiguration result = null;
if (existingConfig.privateKeyJwt != null && tobeDeleted.privateKeyJwtUrl != null) {
JsonWebKeySet<JsonWebKey> existingKeySet = existingConfig.privateKeyJwt;
List<JsonWebKey> keys = existingKeySet.getKeys().stream().filter(k -> !tobeDeleted.privateKeyJwtUrl.equals(k.getKid())).collect(Collectors.toList());
if (existingConfig.jwkSet != null && tobeDeleted.jwksUri != null) {
JsonWebKeySet<JsonWebKey> existingKeySet = existingConfig.jwkSet;
List<JsonWebKey> keys = existingKeySet.getKeys().stream().filter(k -> !tobeDeleted.jwksUri.equals(k.getKid())).collect(Collectors.toList());
if (keys.isEmpty()) {
result = null;
} else {
result = new ClientJwtConfiguration(null, new JsonWebKeySet<>(keys));
}
} else if (existingConfig.privateKeyJwt != null && tobeDeleted.privateKeyJwt != null) {
List<JsonWebKey> existingKeys = new ArrayList<>(existingConfig.getPrivateKeyJwt().getKeys());
existingKeys.removeAll(tobeDeleted.privateKeyJwt.getKeys());
} else if (existingConfig.jwkSet != null && tobeDeleted.jwkSet != null) {
List<JsonWebKey> existingKeys = new ArrayList<>(existingConfig.getJwkSet().getKeys());
existingKeys.removeAll(tobeDeleted.jwkSet.getKeys());
if (existingKeys.isEmpty()) {
result = null;
} else {
result = new ClientJwtConfiguration(null, new JsonWebKeySet<>(existingKeys));
}
} else if (existingConfig.privateKeyJwtUrl != null && tobeDeleted.privateKeyJwtUrl != null) {
if ("*".equals(tobeDeleted.privateKeyJwtUrl) || existingConfig.privateKeyJwtUrl.equals(tobeDeleted.privateKeyJwtUrl)) {
} else if (existingConfig.jwksUri != null && tobeDeleted.jwksUri != null) {
if ("*".equals(tobeDeleted.jwksUri) || existingConfig.jwksUri.equals(tobeDeleted.jwksUri)) {
result = null;
} else {
result = existingConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ interface MultitenantClientSecretService {

void deleteClientSecret(String clientId, String zoneId) throws NoSuchClientException;

void addClientKeyConfig(String clientId, String keyConfig, String zoneId, boolean overwrite) throws NoSuchClientException;
void addClientJwtConfig(String clientId, String keyConfig, String zoneId, boolean overwrite) throws NoSuchClientException;

void deleteClientKeyConfig(String clientId, String keyConfig, String zoneId) throws NoSuchClientException;
void deleteClientJwtConfig(String clientId, String keyConfig, String zoneId) throws NoSuchClientException;
}

public abstract class MultitenantClientServices implements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void deleteClientSecret(String clientId, String zoneId) throws NoSuchClie
}

@Override
public void addClientKeyConfig(String clientId, String keyConfig, String zoneId, boolean overwrite) throws NoSuchClientException {
public void addClientJwtConfig(String clientId, String keyConfig, String zoneId, boolean overwrite) throws NoSuchClientException {
ClientJwtConfiguration clientJwtConfiguration = ClientJwtConfiguration.parse(keyConfig);
if (clientJwtConfiguration != null) {
BaseClientDetails clientDetails = (BaseClientDetails) loadClientByClientId(clientId, zoneId);
Expand All @@ -293,7 +293,7 @@ public void addClientKeyConfig(String clientId, String keyConfig, String zoneId,
}

@Override
public void deleteClientKeyConfig(String clientId, String keyConfig, String zoneId) throws NoSuchClientException {
public void deleteClientJwtConfig(String clientId, String keyConfig, String zoneId) throws NoSuchClientException {
ClientJwtConfiguration clientJwtConfiguration;
if(UaaUrlUtils.isUrl(keyConfig)) {
clientJwtConfiguration = ClientJwtConfiguration.parse(keyConfig);
Expand Down
Loading

0 comments on commit 97c06aa

Please sign in to comment.