mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(cognito): persist app client AuthSessionValidity (#4481)
* fix(cognito): persist app client AuthSessionValidity * test(cognito): cover session validity through the SDK * fix(cognito): align session validity validation with AWS errors
This commit is contained in:
1 parent
16a6c24e15
commit
c0cb49facc
7 files changed
+367
-2
No files matched your search
@@ -270,7 +270,8 @@ public class CognitoJsonHandler {
|
||||
: null,
|
||||
request.has("EnableTokenRevocation")
|
||||
? request.path("EnableTokenRevocation").asBoolean()
|
||||
: null
|
||||
: null,
|
||||
authSessionValidity(request)
|
||||
);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("UserPoolClient", clientToNode(client));
|
||||
@@ -334,7 +335,8 @@ public class CognitoJsonHandler {
|
||||
? objectMapper.convertValue(request.path("RefreshTokenRotation"),
|
||||
new TypeReference<Map<String, Object>>() {})
|
||||
: null,
|
||||
request.has("EnableTokenRevocation") ? request.path("EnableTokenRevocation").asBoolean() : null
|
||||
request.has("EnableTokenRevocation") ? request.path("EnableTokenRevocation").asBoolean() : null,
|
||||
authSessionValidity(request)
|
||||
);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("UserPoolClient", clientToNode(client));
|
||||
@@ -1140,6 +1142,7 @@ public class CognitoJsonHandler {
|
||||
node.put("ClientId", c.getClientId());
|
||||
node.put("UserPoolId", c.getUserPoolId());
|
||||
node.put("ClientName", c.getClientName());
|
||||
node.put("AuthSessionValidity", c.getAuthSessionValidity());
|
||||
if (c.getClientSecret() != null) {
|
||||
node.put("ClientSecret", c.getClientSecret());
|
||||
}
|
||||
@@ -1190,6 +1193,17 @@ public class CognitoJsonHandler {
|
||||
return node;
|
||||
}
|
||||
|
||||
private static Integer authSessionValidity(JsonNode request) {
|
||||
JsonNode value = request.get("AuthSessionValidity");
|
||||
if (value == null || value.isNull()) {
|
||||
return null;
|
||||
}
|
||||
if (!value.isIntegralNumber() || !value.canConvertToInt()) {
|
||||
throw new AwsException("SerializationException", "Expected integer or null", 400);
|
||||
}
|
||||
return value.intValue();
|
||||
}
|
||||
|
||||
private ObjectNode resourceServerToNode(ResourceServer server) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("UserPoolId", server.getUserPoolId());
|
||||
|
||||
@@ -760,7 +760,26 @@ public class CognitoService implements ResourceProvider {
|
||||
List<String> supportedIdentityProviders, Map<String, String> tokenValidityUnits,
|
||||
List<String> writeAttributes, Map<String, Object> refreshTokenRotation,
|
||||
Boolean enableTokenRevocation) {
|
||||
return createUserPoolClient(userPoolId, clientName, generateSecret, allowedOAuthFlowsUserPoolClient,
|
||||
allowedOAuthFlows, allowedOAuthScopes, analyticsConfiguration, callbackURLs,
|
||||
defaultRedirectURI, explicitAuthFlows, accessTokenValidity, idTokenValidity,
|
||||
logoutURLs, preventUserExistenceErrors, readAttributes, refreshTokenValidity,
|
||||
supportedIdentityProviders, tokenValidityUnits, writeAttributes, refreshTokenRotation,
|
||||
enableTokenRevocation, null);
|
||||
}
|
||||
|
||||
public UserPoolClient createUserPoolClient(String userPoolId, String clientName,
|
||||
boolean generateSecret, boolean allowedOAuthFlowsUserPoolClient,
|
||||
List<String> allowedOAuthFlows, List<String> allowedOAuthScopes,
|
||||
Map<String, Object> analyticsConfiguration, List<String> callbackURLs,
|
||||
String defaultRedirectURI, List<String> explicitAuthFlows, Integer accessTokenValidity,
|
||||
Integer idTokenValidity, List<String> logoutURLs, String preventUserExistenceErrors,
|
||||
List<String> readAttributes, Integer refreshTokenValidity,
|
||||
List<String> supportedIdentityProviders, Map<String, String> tokenValidityUnits,
|
||||
List<String> writeAttributes, Map<String, Object> refreshTokenRotation,
|
||||
Boolean enableTokenRevocation, Integer authSessionValidity) {
|
||||
|
||||
validateAuthSessionValidity(authSessionValidity);
|
||||
UserPool userPool = describeUserPool(userPoolId);
|
||||
String clientId = clientIdFor(userPool, clientName);
|
||||
List<String> normalizedAllowedOAuthFlows = normalizeStringList(allowedOAuthFlows);
|
||||
@@ -802,6 +821,9 @@ public class CognitoService implements ResourceProvider {
|
||||
client.setExplicitAuthFlows(normalizedExplicitAuthFlows);
|
||||
client.setAccessTokenValidity(accessTokenValidity);
|
||||
client.setIdTokenValidity(idTokenValidity);
|
||||
if (authSessionValidity != null) {
|
||||
client.setAuthSessionValidity(authSessionValidity);
|
||||
}
|
||||
client.setLogoutURLs(normalizedLogoutUrls);
|
||||
client.setPreventUserExistenceErrors(preventUserExistenceErrors);
|
||||
client.setReadAttributes(normalizedReadAttributes);
|
||||
@@ -938,6 +960,26 @@ public class CognitoService implements ResourceProvider {
|
||||
List<String> writeAttributes,
|
||||
Map<String, Object> refreshTokenRotation,
|
||||
Boolean enableTokenRevocation) {
|
||||
return updateUserPoolClient(userPoolId, clientId, clientName, allowedOAuthFlowsUserPoolClient,
|
||||
allowedOAuthFlows, allowedOAuthScopes, analyticsConfiguration, callbackURLs,
|
||||
defaultRedirectURI, explicitAuthFlows, accessTokenValidity, idTokenValidity,
|
||||
logoutURLs, preventUserExistenceErrors, readAttributes, refreshTokenValidity,
|
||||
supportedIdentityProviders, tokenValidityUnits, writeAttributes, refreshTokenRotation,
|
||||
enableTokenRevocation, null);
|
||||
}
|
||||
|
||||
public UserPoolClient updateUserPoolClient(String userPoolId, String clientId, String clientName,
|
||||
Boolean allowedOAuthFlowsUserPoolClient,
|
||||
List<String> allowedOAuthFlows, List<String> allowedOAuthScopes,
|
||||
Map<String, Object> analyticsConfiguration, List<String> callbackURLs,
|
||||
String defaultRedirectURI, List<String> explicitAuthFlows,
|
||||
Integer accessTokenValidity, Integer idTokenValidity,
|
||||
List<String> logoutURLs, String preventUserExistenceErrors,
|
||||
List<String> readAttributes, Integer refreshTokenValidity,
|
||||
List<String> supportedIdentityProviders, Map<String, String> tokenValidityUnits,
|
||||
List<String> writeAttributes, Map<String, Object> refreshTokenRotation,
|
||||
Boolean enableTokenRevocation, Integer authSessionValidity) {
|
||||
validateAuthSessionValidity(authSessionValidity);
|
||||
UserPoolClient client = describeUserPoolClient(userPoolId, clientId);
|
||||
boolean effectiveAllowedOAuthFlowsUserPoolClient = allowedOAuthFlowsUserPoolClient != null
|
||||
? allowedOAuthFlowsUserPoolClient
|
||||
@@ -1038,6 +1080,9 @@ public class CognitoService implements ResourceProvider {
|
||||
if (enableTokenRevocation != null) {
|
||||
client.setEnableTokenRevocation(enableTokenRevocation);
|
||||
}
|
||||
if (authSessionValidity != null) {
|
||||
client.setAuthSessionValidity(authSessionValidity);
|
||||
}
|
||||
|
||||
client.setLastModifiedDate(System.currentTimeMillis() / 1000L);
|
||||
clientStore.put(clientId, client);
|
||||
@@ -1045,6 +1090,17 @@ public class CognitoService implements ResourceProvider {
|
||||
return client;
|
||||
}
|
||||
|
||||
private static void validateAuthSessionValidity(Integer authSessionValidity) {
|
||||
if (authSessionValidity != null && (authSessionValidity < 3 || authSessionValidity > 15)) {
|
||||
String constraint = authSessionValidity < 3
|
||||
? "Member must have value greater than or equal to 3"
|
||||
: "Member must have value less than or equal to 15";
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"1 validation error detected: Value '" + authSessionValidity
|
||||
+ "' at 'authSessionValidity' failed to satisfy constraint: " + constraint, 400);
|
||||
}
|
||||
}
|
||||
|
||||
public List<UserPoolClientSecret> listUserPoolClientSecrets(String userPoolId, String clientId) {
|
||||
UserPoolClient client = clientStore.get(clientId)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "User pool client not found", 400));
|
||||
|
||||
@@ -25,6 +25,7 @@ public class UserPoolClient {
|
||||
private List<String> explicitAuthFlows = new ArrayList<>();
|
||||
private Integer accessTokenValidity;
|
||||
private Integer idTokenValidity;
|
||||
private int authSessionValidity = 3;
|
||||
private List<String> logoutURLs = new ArrayList<>();
|
||||
private String preventUserExistenceErrors;
|
||||
private List<String> readAttributes = new ArrayList<>();
|
||||
@@ -99,6 +100,9 @@ public class UserPoolClient {
|
||||
public Integer getIdTokenValidity() { return idTokenValidity; }
|
||||
public void setIdTokenValidity(Integer idTokenValidity) { this.idTokenValidity = idTokenValidity; }
|
||||
|
||||
public int getAuthSessionValidity() { return authSessionValidity; }
|
||||
public void setAuthSessionValidity(int authSessionValidity) { this.authSessionValidity = authSessionValidity; }
|
||||
|
||||
public List<String> getLogoutURLs() { return logoutURLs; }
|
||||
public void setLogoutURLs(List<String> logoutURLs) { this.logoutURLs = logoutURLs; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user