-
Notifications
You must be signed in to change notification settings - Fork 829
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add persistence support for private_key_jwt client authentic…
…ation (#2449) * refactor: prepare for private_key_jwt in oauth_client_details BaseClientDetails from spring security oauth2 cannot be changed, therefore more to UaaClientDetails for client details load * feature: add persistence support for private_key_jwt Allow to setup jwks_uri and jwks, similar to OIDC proxy mode with tokenKeyUrl and tokenKey. The private_key_jwt metadata is stored in additional_information (could be switched to own column) The setup can be done from REST and yaml. * more tests * refactorings * add tests * Renamed * Renamed * Renamed * Add column client_jwt_config and do some refactoring for UaaClientDetails usage * Sonar findings * cleanup * Refactoring because of usage of client_jwt_config now from oauth_client_details additional_information is not used anymore * remove not needed method. Even if UaaClientDetails is used the addClientDetails method can be used and therefore it does not make sense to have 2 add methods * review * own events for jwt client configuration * review * throw exceptions * * doc: Add documentation * Add new scope clients.trust This can be used for JWT client trust configuration calls Similar to clients.secret * review * more tests * sonar findings * fix sonar issues
- Loading branch information
Showing
27 changed files
with
1,387 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
model/src/main/java/org/cloudfoundry/identity/uaa/oauth/client/ClientJwtChangeRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.cloudfoundry.identity.uaa.oauth.client; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import static org.cloudfoundry.identity.uaa.oauth.client.ClientJwtChangeRequest.ChangeMode.ADD; | ||
import static org.cloudfoundry.identity.uaa.oauth.client.ClientJwtChangeRequest.ChangeMode.DELETE; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class ClientJwtChangeRequest { | ||
|
||
public static final String JWKS_URI = "jwks_uri"; | ||
public static final String JWKS = "jwks"; | ||
|
||
public enum ChangeMode { | ||
UPDATE, | ||
ADD, | ||
DELETE | ||
} | ||
@JsonProperty("kid") | ||
private String keyId; | ||
@JsonProperty(JWKS_URI) | ||
private String jsonWebKeyUri; | ||
@JsonProperty(JWKS) | ||
private String jsonWebKeySet; | ||
@JsonProperty("client_id") | ||
private String clientId; | ||
private ChangeMode changeMode = ADD; | ||
|
||
public ClientJwtChangeRequest() { | ||
} | ||
|
||
public ClientJwtChangeRequest(String clientId, String jsonWebKeyUri, String jsonWebKeySet) { | ||
this.jsonWebKeyUri = jsonWebKeyUri; | ||
this.jsonWebKeySet = jsonWebKeySet; | ||
this.clientId = clientId; | ||
} | ||
|
||
public String getJsonWebKeyUri() { | ||
return jsonWebKeyUri; | ||
} | ||
|
||
public void setJsonWebKeyUri(String jsonWebKeyUri) { | ||
this.jsonWebKeyUri = jsonWebKeyUri; | ||
} | ||
|
||
public String getJsonWebKeySet() { | ||
return jsonWebKeySet; | ||
} | ||
|
||
public void setJsonWebKeySet(String jsonWebKeySet) { | ||
this.jsonWebKeySet = jsonWebKeySet; | ||
} | ||
|
||
public String getClientId() { | ||
return clientId; | ||
} | ||
|
||
public void setClientId(String clientId) { | ||
this.clientId = clientId; | ||
} | ||
|
||
public ChangeMode getChangeMode() { | ||
return changeMode; | ||
} | ||
|
||
public void setChangeMode(ChangeMode changeMode) { | ||
this.changeMode = changeMode; | ||
} | ||
|
||
public String getKeyId() { return keyId;} | ||
|
||
public void setKeyId(String keyId) { | ||
this.keyId = keyId; | ||
} | ||
|
||
public String getChangeValue() { | ||
// Depending on change mode, allow different values | ||
if (changeMode == DELETE && keyId != null) { | ||
return keyId; | ||
} | ||
return jsonWebKeyUri != null ? jsonWebKeyUri : jsonWebKeySet; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...l/src/test/java/org/cloudfoundry/identity/uaa/oauth/client/ClientDetailsCreationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.cloudfoundry.identity.uaa.oauth.client; | ||
|
||
import org.cloudfoundry.identity.uaa.util.JsonUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class ClientDetailsCreationTest { | ||
|
||
ClientDetailsCreation clientDetailsCreation = new ClientDetailsCreation(); | ||
|
||
@Test | ||
void testRequestSerialization() { | ||
clientDetailsCreation.setJsonWebKeyUri("https://uri.domain.net"); | ||
clientDetailsCreation.setJsonWebKeySet("{}"); | ||
String jsonRequest = JsonUtils.writeValueAsString(clientDetailsCreation); | ||
ClientDetailsCreation request = JsonUtils.readValue(jsonRequest, ClientDetailsCreation.class); | ||
assertEquals(clientDetailsCreation, request); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../src/test/java/org/cloudfoundry/identity/uaa/oauth/client/ClientJwtChangeRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.cloudfoundry.identity.uaa.oauth.client; | ||
|
||
import org.cloudfoundry.identity.uaa.util.JsonUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
class ClientJwtChangeRequestTest { | ||
|
||
@Test | ||
void testRequestSerialization() { | ||
ClientJwtChangeRequest def = new ClientJwtChangeRequest(null, null, null); | ||
def.setKeyId("key-1"); | ||
def.setChangeMode(ClientJwtChangeRequest.ChangeMode.DELETE); | ||
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); | ||
assertNotEquals(def, request); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.