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 a9cba87 commit c69b748
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ private void addNewClients() {

if (map.get("jwks_uri") instanceof String) {
String jwksUri = (String) map.get("jwks_uri");
PrivateKeyJwtConfiguration keyConfig = PrivateKeyJwtConfiguration.parse(UaaUrlUtils.normalizeUri(jwksUri), null);
ClientJwtConfiguration keyConfig = ClientJwtConfiguration.parse(UaaUrlUtils.normalizeUri(jwksUri), null);
if (keyConfig != null && keyConfig.getCleanString() != null) {
clientRegistrationService.addClientKeyConfig(clientId, keyConfig.getPrivateKeyJwtUrl(), IdentityZone.getUaaZoneId(), override);
}
} else if (map.get("jwks") instanceof String) {
String jwks = (String) map.get("jwks");
PrivateKeyJwtConfiguration keyConfig = PrivateKeyJwtConfiguration.parse(null, jwks);
ClientJwtConfiguration keyConfig = ClientJwtConfiguration.parse(null, jwks);
if (keyConfig != null && keyConfig.getCleanString() != null) {
clientRegistrationService.addClientKeyConfig(clientId, keyConfig.getCleanString(), IdentityZone.getUaaZoneId(), override);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public ActionResult changeClientJwt(@PathVariable String client_id, @RequestBody
throw new InvalidClientDetailsException(e.getMessage());
}

PrivateKeyJwtConfiguration clientKeyConfig = PrivateKeyJwtConfiguration.readValue(clientDetails);
ClientJwtConfiguration clientKeyConfig = ClientJwtConfiguration.readValue(clientDetails);

ActionResult result;
switch (change.getChangeMode()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ 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())) {
PrivateKeyJwtConfiguration privateKeyJwtConfiguration = PrivateKeyJwtConfiguration.parse(clientDetailsCreation.getPrivateKeyUrl(),
ClientJwtConfiguration clientJwtConfiguration = ClientJwtConfiguration.parse(clientDetailsCreation.getPrivateKeyUrl(),
clientDetailsCreation.getPrivateKeySet());
if (privateKeyJwtConfiguration != null) {
privateKeyJwtConfiguration.writeValue(client);
if (clientJwtConfiguration != null) {
clientJwtConfiguration.writeValue(client);
} else {
logger.warn("Client configuration with private_key_jwt not valid");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PrivateKeyJwtConfiguration implements Cloneable{
public class ClientJwtConfiguration implements Cloneable{

@JsonIgnore
private static final int MAX_KEY_SIZE = 10;
Expand All @@ -42,10 +42,10 @@ public class PrivateKeyJwtConfiguration implements Cloneable{
@JsonProperty("jwks")
private JsonWebKeySet<JsonWebKey> privateKeyJwt;

public PrivateKeyJwtConfiguration() {
public ClientJwtConfiguration() {
}

public PrivateKeyJwtConfiguration(final String privateKeyJwtUrl, final JsonWebKeySet<JsonWebKey> webKeySet) {
public ClientJwtConfiguration(final String privateKeyJwtUrl, final JsonWebKeySet<JsonWebKey> webKeySet) {
this.privateKeyJwtUrl = privateKeyJwtUrl;
privateKeyJwt = webKeySet;
if (privateKeyJwt != null) {
Expand Down Expand Up @@ -74,8 +74,8 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

if (o instanceof PrivateKeyJwtConfiguration) {
PrivateKeyJwtConfiguration that = (PrivateKeyJwtConfiguration) 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());
Expand Down Expand Up @@ -115,7 +115,7 @@ public String getCleanString() {
}

@JsonIgnore
public static PrivateKeyJwtConfiguration parse(String privateKeyConfig) {
public static ClientJwtConfiguration parse(String privateKeyConfig) {
if (UaaUrlUtils.isUrl(privateKeyConfig)) {
return parse(privateKeyConfig, null);
} else {
Expand All @@ -124,11 +124,11 @@ public static PrivateKeyJwtConfiguration parse(String privateKeyConfig) {
}

@JsonIgnore
public static PrivateKeyJwtConfiguration parse(String privateKeyUrl, String privateKeyJwt) {
PrivateKeyJwtConfiguration privateKeyJwtConfiguration = null;
public static ClientJwtConfiguration parse(String privateKeyUrl, String privateKeyJwt) {
ClientJwtConfiguration clientJwtConfiguration = null;
if (privateKeyUrl != null) {
privateKeyJwtConfiguration = new PrivateKeyJwtConfiguration(privateKeyUrl, null);
privateKeyJwtConfiguration.validateJwksUri();
clientJwtConfiguration = new ClientJwtConfiguration(privateKeyUrl, null);
clientJwtConfiguration.validateJwksUri();
} else if (privateKeyJwt != null && privateKeyJwt.contains("{") && privateKeyJwt.contains("}")) {
HashMap<String, Object> jsonMap = JsonUtils.readValue(privateKeyJwt, HashMap.class);
String cleanJwtString;
Expand All @@ -138,13 +138,13 @@ public static PrivateKeyJwtConfiguration parse(String privateKeyUrl, String priv
} else {
cleanJwtString = JWK.parse(jsonMap).toPublicJWK().toString();
}
privateKeyJwtConfiguration = new PrivateKeyJwtConfiguration(null, JsonWebKeyHelper.deserialize(cleanJwtString));
privateKeyJwtConfiguration.validateJwkSet();
clientJwtConfiguration = new ClientJwtConfiguration(null, JsonWebKeyHelper.deserialize(cleanJwtString));
clientJwtConfiguration.validateJwkSet();
} catch (ParseException e) {
throw new InvalidClientDetailsException("Client jwt configuration cannot be parsed", e);
}
}
return privateKeyJwtConfiguration;
return clientJwtConfiguration;
}

private boolean validateJwkSet() {
Expand Down Expand Up @@ -192,13 +192,13 @@ private boolean validateJwksUri() {
* @return
*/
@JsonIgnore
public static PrivateKeyJwtConfiguration readValue(ClientDetails clientDetails) {
public static ClientJwtConfiguration readValue(ClientDetails clientDetails) {
if (clientDetails == null ||
clientDetails.getAdditionalInformation() == null ||
!(clientDetails.getAdditionalInformation().get(PRIVATE_KEY_CONFIG) instanceof String)) {
return null;
}
return JsonUtils.readValue((String) clientDetails.getAdditionalInformation().get(PRIVATE_KEY_CONFIG), PrivateKeyJwtConfiguration.class);
return JsonUtils.readValue((String) clientDetails.getAdditionalInformation().get(PRIVATE_KEY_CONFIG), ClientJwtConfiguration.class);
}

/**
Expand Down Expand Up @@ -236,25 +236,25 @@ public static void resetConfiguration(ClientDetails clientDetails) {
}

@JsonIgnore
public static PrivateKeyJwtConfiguration merge(PrivateKeyJwtConfiguration existingConfig, PrivateKeyJwtConfiguration newConfig, boolean overwrite) {
public static ClientJwtConfiguration merge(ClientJwtConfiguration existingConfig, ClientJwtConfiguration newConfig, boolean overwrite) {
if (existingConfig == null) {
return newConfig;
}
if (newConfig == null) {
return existingConfig;
}
PrivateKeyJwtConfiguration result = null;
ClientJwtConfiguration result = null;
if (newConfig.privateKeyJwtUrl != null) {
if (overwrite) {
result = new PrivateKeyJwtConfiguration(newConfig.privateKeyJwtUrl, null);
result = new ClientJwtConfiguration(newConfig.privateKeyJwtUrl, null);
} else {
result = existingConfig;
}
}
if (newConfig.privateKeyJwt != null) {
if (existingConfig.privateKeyJwt == null) {
if (overwrite) {
result = new PrivateKeyJwtConfiguration(null, newConfig.privateKeyJwt);
result = new ClientJwtConfiguration(null, newConfig.privateKeyJwt);
} else {
result = existingConfig;
}
Expand All @@ -273,36 +273,36 @@ public static PrivateKeyJwtConfiguration merge(PrivateKeyJwtConfiguration existi
}
});
existingKeys.addAll(newKeys);
result = new PrivateKeyJwtConfiguration(null, new JsonWebKeySet<>(existingKeys));
result = new ClientJwtConfiguration(null, new JsonWebKeySet<>(existingKeys));
}
}
return result;
}

@JsonIgnore
public static PrivateKeyJwtConfiguration delete(PrivateKeyJwtConfiguration existingConfig, PrivateKeyJwtConfiguration tobeDeleted) {
public static ClientJwtConfiguration delete(ClientJwtConfiguration existingConfig, ClientJwtConfiguration tobeDeleted) {
if (existingConfig == null) {
return null;
}
if (tobeDeleted == null) {
return existingConfig;
}
PrivateKeyJwtConfiguration result = null;
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 (keys.isEmpty()) {
result = null;
} else {
result = new PrivateKeyJwtConfiguration(null, new JsonWebKeySet<>(keys));
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());
if (existingKeys.isEmpty()) {
result = null;
} else {
result = new PrivateKeyJwtConfiguration(null, new JsonWebKeySet<>(existingKeys));
result = new ClientJwtConfiguration(null, new JsonWebKeySet<>(existingKeys));
}
} else if (existingConfig.privateKeyJwtUrl != null && tobeDeleted.privateKeyJwtUrl != null) {
if ("*".equals(tobeDeleted.privateKeyJwtUrl) || existingConfig.privateKeyJwtUrl.equals(tobeDeleted.privateKeyJwtUrl)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.cloudfoundry.identity.uaa.audit.event.SystemDeletable;
import org.cloudfoundry.identity.uaa.authentication.UaaPrincipal;
import org.cloudfoundry.identity.uaa.client.PrivateKeyJwtConfiguration;
import org.cloudfoundry.identity.uaa.client.ClientJwtConfiguration;
import org.cloudfoundry.identity.uaa.oauth.client.ClientConstants;
import org.cloudfoundry.identity.uaa.resources.ResourceMonitor;
import org.cloudfoundry.identity.uaa.security.ContextSensitiveOAuth2SecurityExpressionMethods;
Expand Down Expand Up @@ -280,11 +280,11 @@ public void deleteClientSecret(String clientId, String zoneId) throws NoSuchClie

@Override
public void addClientKeyConfig(String clientId, String keyConfig, String zoneId, boolean overwrite) throws NoSuchClientException {
PrivateKeyJwtConfiguration privateKeyJwtConfiguration = PrivateKeyJwtConfiguration.parse(keyConfig);
if (privateKeyJwtConfiguration != null) {
ClientJwtConfiguration clientJwtConfiguration = ClientJwtConfiguration.parse(keyConfig);
if (clientJwtConfiguration != null) {
BaseClientDetails clientDetails = (BaseClientDetails) loadClientByClientId(clientId, zoneId);
PrivateKeyJwtConfiguration existingConfig = PrivateKeyJwtConfiguration.readValue(clientDetails);
PrivateKeyJwtConfiguration result = PrivateKeyJwtConfiguration.merge(existingConfig, privateKeyJwtConfiguration, overwrite);
ClientJwtConfiguration existingConfig = ClientJwtConfiguration.readValue(clientDetails);
ClientJwtConfiguration result = ClientJwtConfiguration.merge(existingConfig, clientJwtConfiguration, overwrite);
if (result != null) {
result.writeValue(clientDetails);
}
Expand All @@ -294,19 +294,19 @@ public void addClientKeyConfig(String clientId, String keyConfig, String zoneId,

@Override
public void deleteClientKeyConfig(String clientId, String keyConfig, String zoneId) throws NoSuchClientException {
PrivateKeyJwtConfiguration privateKeyJwtConfiguration;
ClientJwtConfiguration clientJwtConfiguration;
if(UaaUrlUtils.isUrl(keyConfig)) {
privateKeyJwtConfiguration = PrivateKeyJwtConfiguration.parse(keyConfig);
clientJwtConfiguration = ClientJwtConfiguration.parse(keyConfig);
} else {
privateKeyJwtConfiguration = new PrivateKeyJwtConfiguration(keyConfig, null);
clientJwtConfiguration = new ClientJwtConfiguration(keyConfig, null);
}
if (privateKeyJwtConfiguration != null) {
if (clientJwtConfiguration != null) {
BaseClientDetails clientDetails = (BaseClientDetails) loadClientByClientId(clientId, zoneId);
PrivateKeyJwtConfiguration result = PrivateKeyJwtConfiguration.delete(PrivateKeyJwtConfiguration.readValue(clientDetails), privateKeyJwtConfiguration);
ClientJwtConfiguration result = ClientJwtConfiguration.delete(ClientJwtConfiguration.readValue(clientDetails), clientJwtConfiguration);
if (result != null) {
result.writeValue(clientDetails);
} else {
PrivateKeyJwtConfiguration.resetConfiguration(clientDetails);
ClientJwtConfiguration.resetConfiguration(clientDetails);
}
updateClientDetails(clientDetails, zoneId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ void testCreateClientWithPrivateKeyUri() {
ArgumentCaptor<BaseClientDetails> clientCaptor = ArgumentCaptor.forClass(BaseClientDetails.class);
verify(clientDetailsService).create(clientCaptor.capture(), anyString());
BaseClientDetails created = clientCaptor.getValue();
assertEquals(PrivateKeyJwtConfiguration.readValue(created), PrivateKeyJwtConfiguration.parse(jwksUri));
assertEquals(ClientJwtConfiguration.readValue(created), ClientJwtConfiguration.parse(jwksUri));
}

@Test
Expand All @@ -1097,7 +1097,7 @@ void testCreateClientWithPrivateKeyUriInvalid() {
ArgumentCaptor<BaseClientDetails> clientCaptor = ArgumentCaptor.forClass(BaseClientDetails.class);
verify(clientDetailsService).create(clientCaptor.capture(), anyString());
BaseClientDetails created = clientCaptor.getValue();
assertNull(PrivateKeyJwtConfiguration.readValue(created));
assertNull(ClientJwtConfiguration.readValue(created));
}

@Test
Expand Down Expand Up @@ -1148,7 +1148,7 @@ void testChangeDeletePrivateKeyJwtConfigUri() {
assertEquals("Client jwt configuration updated", result.getMessage());
verify(clientRegistrationService, times(1)).addClientKeyConfig(detail.getClientId(), jwksUri, IdentityZoneHolder.get().getId(), true);

PrivateKeyJwtConfiguration.parse(jwksUri).writeValue(detail);
ClientJwtConfiguration.parse(jwksUri).writeValue(detail);
change.setChangeMode(ClientJwtChangeRequest.ChangeMode.DELETE);
change.setKeyUrl(jwksUri);
result = endpoints.changeClientJwt(detail.getClientId(), change);
Expand Down Expand Up @@ -1176,10 +1176,10 @@ void testCreateClientWithPrivateKeySet() {
ArgumentCaptor<BaseClientDetails> clientCaptor = ArgumentCaptor.forClass(BaseClientDetails.class);
verify(clientDetailsService).create(clientCaptor.capture(), anyString());
BaseClientDetails created = clientCaptor.getValue();
assertEquals(PrivateKeyJwtConfiguration.readValue(created), PrivateKeyJwtConfiguration.parse(jsonJwk));
assertEquals(PrivateKeyJwtConfiguration.readValue(created), PrivateKeyJwtConfiguration.parse(jsonJwk2));
assertEquals(PrivateKeyJwtConfiguration.readValue(created), PrivateKeyJwtConfiguration.parse(jsonJwkSet));
assertNotEquals(PrivateKeyJwtConfiguration.readValue(created), PrivateKeyJwtConfiguration.parse(jsonJwk3));
assertEquals(ClientJwtConfiguration.readValue(created), ClientJwtConfiguration.parse(jsonJwk));
assertEquals(ClientJwtConfiguration.readValue(created), ClientJwtConfiguration.parse(jsonJwk2));
assertEquals(ClientJwtConfiguration.readValue(created), ClientJwtConfiguration.parse(jsonJwkSet));
assertNotEquals(ClientJwtConfiguration.readValue(created), ClientJwtConfiguration.parse(jsonJwk3));
}

private ClientDetailsCreation createClientDetailsCreation(BaseClientDetails baseClientDetails) {
Expand Down
Loading

0 comments on commit c69b748

Please sign in to comment.