Skip to content

Commit

Permalink
ACS-6603 Use enum type
Browse files Browse the repository at this point in the history
  • Loading branch information
damianujma committed Feb 12, 2024
1 parent 6ecdef0 commit d1fb4df
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import static java.util.Optional.ofNullable;
import static java.util.function.Predicate.not;

import static org.alfresco.repo.security.authentication.identityservice.IdentityServiceMetadataKeys.AUDIENCE_METADATA;
import static org.alfresco.repo.security.authentication.identityservice.IdentityServiceMetadataKeys.SCOPES_SUPPORTED_METADATA;
import static org.alfresco.repo.security.authentication.identityservice.IdentityServiceMetadataKey.AUDIENCE;
import static org.alfresco.repo.security.authentication.identityservice.IdentityServiceMetadataKey.SCOPES_SUPPORTED;

import java.io.ByteArrayInputStream;
import java.io.File;
Expand Down Expand Up @@ -476,11 +476,11 @@ private Map<String, Object> createMetadata(OIDCProviderMetadata metadata)
Map<String, Object> configurationMetadata = new LinkedHashMap<>();
if(metadata.getScopes() != null)
{
configurationMetadata.put(SCOPES_SUPPORTED_METADATA, metadata.getScopes());
configurationMetadata.put(SCOPES_SUPPORTED.getValue(), metadata.getScopes());
}
if(StringUtils.isNotBlank(config.getAudience()))
{
configurationMetadata.put(AUDIENCE_METADATA, config.getAudience());
configurationMetadata.put(AUDIENCE.getValue(), config.getAudience());
}
return configurationMetadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@
*/
package org.alfresco.repo.security.authentication.identityservice;

public class IdentityServiceMetadataKeys
public enum IdentityServiceMetadataKey
{
public static final String AUDIENCE_METADATA = "audience";
public static final String SCOPES_SUPPORTED_METADATA = "scopes_supported";
}
AUDIENCE("audience"),
SCOPES_SUPPORTED("scopes_supported");

private String value;

IdentityServiceMetadataKey(String value)
{
this.value = value;
}

public String getValue()
{
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import static java.util.Objects.requireNonNull;

import static org.alfresco.repo.security.authentication.identityservice.IdentityServiceMetadataKeys.AUDIENCE_METADATA;
import static org.alfresco.repo.security.authentication.identityservice.IdentityServiceMetadataKey.AUDIENCE;

import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -256,7 +256,7 @@ private static OAuth2AccessTokenResponseClient<OAuth2PasswordGrantRequest> creat
Optional.of(clientRegistration)
.map(ClientRegistration::getProviderDetails)
.map(ProviderDetails::getConfigurationMetadata)
.map(metadata -> metadata.get(AUDIENCE_METADATA))
.map(metadata -> metadata.get(AUDIENCE.getValue()))
.filter(String.class::isInstance)
.map(String.class::cast)
.ifPresent(audienceValue -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package org.alfresco.repo.security.authentication.identityservice.admin;

import static org.alfresco.repo.security.authentication.identityservice.IdentityServiceFacade.AuthorizationGrant.authorizationCode;
import static org.alfresco.repo.security.authentication.identityservice.IdentityServiceMetadataKeys.SCOPES_SUPPORTED_METADATA;
import static org.alfresco.repo.security.authentication.identityservice.IdentityServiceMetadataKey.SCOPES_SUPPORTED;

import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -216,7 +216,7 @@ private Set<String> getScopes(ClientRegistration clientRegistration)
{
return Optional.ofNullable(clientRegistration.getProviderDetails())
.map(ProviderDetails::getConfigurationMetadata)
.map(metadata -> metadata.get(SCOPES_SUPPORTED_METADATA))
.map(metadata -> metadata.get(SCOPES_SUPPORTED.getValue()))
.filter(Scope.class::isInstance)
.map(Scope.class::cast)
.map(this::getSupportedScopes)
Expand Down

0 comments on commit d1fb4df

Please sign in to comment.