Skip to content

Commit

Permalink
Update APIs to support custom authentication management.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Nov 13, 2024
1 parent 979dbc2 commit 8b39ea6
Showing 1 changed file with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ public FederatedAuthenticatorListResponse updateFederatedAuthenticators(String i
// Need to create a clone, since modifying the fields of the original object, will modify the cached
// IDP object.
IdentityProvider idpToUpdate = createIdPClone(idp);
updateFederatedAuthenticatorConfig(idpToUpdate, authenticatorRequest, false);
updateFederatedAuthenticatorConfig(idpToUpdate, authenticatorRequest);
IdentityProvider updatedIdp = IdentityProviderServiceHolder.getIdentityProviderManager()
.updateIdPByResourceId(
idpId, idpToUpdate, ContextLoader.getTenantDomainFromContext());
Expand Down Expand Up @@ -1765,8 +1765,7 @@ private MetaOutboundConnector createMetaOutboundConnector(ProvisioningConnectorC
}

private void updateFederatedAuthenticatorConfig(IdentityProvider idp, FederatedAuthenticatorRequest
federatedAuthenticatorRequest, boolean isNewFederatedAuthenticator)
throws IdentityProviderManagementClientException {
federatedAuthenticatorRequest) throws IdentityProviderManagementClientException {

if (federatedAuthenticatorRequest != null) {
List<FederatedAuthenticator> federatedAuthenticators = federatedAuthenticatorRequest.getAuthenticators();
Expand All @@ -1775,13 +1774,52 @@ private void updateFederatedAuthenticatorConfig(IdentityProvider idp, FederatedA
List<FederatedAuthenticatorConfig> fedAuthConfigs = new ArrayList<>();
for (FederatedAuthenticator authenticator : federatedAuthenticators) {
String authenticatorName = getDecodedAuthenticatorName(authenticator.getAuthenticatorId());
String definedByType;
if (isNewFederatedAuthenticator) {
definedByType = resolveDefinedByTypeToCreateFederatedAuthenticator(
authenticator.getDefinedBy().toString()).toString();
} else {
definedByType = resolveDefinedByTypeToUpdateFederatedAuthenticator(authenticatorName).toString();
String definedByType = resolveDefinedByTypeToUpdateFederatedAuthenticator(authenticatorName).toString();

if (DefinedByType.SYSTEM.toString().equals(definedByType)) {
validateAuthenticatorProperties(authenticatorName, authenticator.getProperties());
}

FederatedAuthenticatorConfigBuilderFactory.Builder builder =
new FederatedAuthenticatorConfigBuilderFactory.Builder();
builder.authenticatorName(authenticatorName);
builder.definedByType(definedByType);
builder.enabled(authenticator.getIsEnabled());
builder.displayName(getDisplayNameOfAuthenticator(authenticatorName));
builder.endpoint(authenticator.getEndpoint());
List<Property> properties = authenticator.getProperties().stream().map(propertyToInternal)
.collect(Collectors.toList());
builder.properties(properties);
FederatedAuthenticatorConfig authConfig = builder.build();

fedAuthConfigs.add(authConfig);

if (StringUtils.equals(defaultAuthenticator, authenticator.getAuthenticatorId())) {
defaultAuthConfig = authConfig;
}
}

if (StringUtils.isNotBlank(defaultAuthenticator) && defaultAuthConfig == null) {
throw handleException(Response.Status.BAD_REQUEST,
Constants.ErrorMessage.ERROR_CODE_INVALID_DEFAULT_AUTHENTICATOR, null);
}
idp.setFederatedAuthenticatorConfigs(fedAuthConfigs.toArray(new FederatedAuthenticatorConfig[0]));
idp.setDefaultAuthenticatorConfig(defaultAuthConfig);
}
}

private void createFederatedAuthenticatorConfig(IdentityProvider idp, FederatedAuthenticatorRequest
federatedAuthenticatorRequest) throws IdentityProviderManagementClientException {

if (federatedAuthenticatorRequest != null) {
List<FederatedAuthenticator> federatedAuthenticators = federatedAuthenticatorRequest.getAuthenticators();
String defaultAuthenticator = federatedAuthenticatorRequest.getDefaultAuthenticatorId();
FederatedAuthenticatorConfig defaultAuthConfig = null;
List<FederatedAuthenticatorConfig> fedAuthConfigs = new ArrayList<>();
for (FederatedAuthenticator authenticator : federatedAuthenticators) {
String authenticatorName = getDecodedAuthenticatorName(authenticator.getAuthenticatorId());
String definedByType = resolveDefinedByTypeToCreateFederatedAuthenticator(
authenticator.getDefinedBy().toString()).toString();

if (DefinedByType.SYSTEM.toString().equals(definedByType)) {
validateAuthenticatorProperties(authenticatorName, authenticator.getProperties());
Expand Down Expand Up @@ -2123,7 +2161,7 @@ private IdentityProvider createIDP(IdentityProviderPOSTRequest identityProviderP
}
idp.setFederationHub(identityProviderPOSTRequest.getIsFederationHub());

updateFederatedAuthenticatorConfig(idp, identityProviderPOSTRequest.getFederatedAuthenticators(), true);
createFederatedAuthenticatorConfig(idp, identityProviderPOSTRequest.getFederatedAuthenticators());
if (identityProviderPOSTRequest.getProvisioning() != null) {
updateOutboundConnectorConfig(idp, identityProviderPOSTRequest.getProvisioning().getOutboundConnectors());
updateJIT(idp, identityProviderPOSTRequest.getProvisioning().getJit());
Expand Down

0 comments on commit 8b39ea6

Please sign in to comment.