Skip to content

Commit

Permalink
Add support for managing custom federated authenticators.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Nov 6, 2024
1 parent 377dc85 commit e282f69
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 164 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.DefinedByType;

/**
* Verification authenticator configuration.
* The user defined federated authenticator configuration model.
*/
public class UserDefinedFederatedAuthenticatorConfig extends FederatedAuthenticatorConfig {

Expand All @@ -43,7 +43,7 @@ public UserDefinedFederatedAuthenticatorConfig(AuthenticationType type) {
}

/**
* Get the endpoint config of the Local authenticator config.
* Get the endpoint config of the User defined federated authenticator config.
*
* @return DefinedByType
*/
Expand All @@ -53,9 +53,9 @@ public EndpointConfig getEndpointConfig() {
}

/**
* Set the defined by type of the Local authenticator config.
* Set the defined by type of the User defined federated authenticator config.
*
* @param endpointConfig The endpoint config of the local authenticator config.
* @param endpointConfig The endpoint config of the User defined federated authenticator config.
*/
public void setEndpointConfig(EndpointConfig endpointConfig) {

Expand Down
48 changes: 0 additions & 48 deletions components/application-mgt/spotbugs-exclude.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.wso2.carbon.identity.core.util.IdentityDatabaseUtil;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.secret.mgt.core.SecretsProcessor;
import org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException;
import org.wso2.carbon.idp.mgt.IdentityProviderManagementClientException;
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
Expand Down Expand Up @@ -126,7 +125,7 @@
public class IdPManagementDAO {

private static final Log log = LogFactory.getLog(IdPManagementDAO.class);
private final IdPSecretsProcessor idpSecretsProcessorService = new IdPSecretsProcessor();;
private final IdPSecretsProcessor idpSecretsProcessorService = new IdPSecretsProcessor();

private static final String OPENID_IDP_ENTITY_ID = "IdPEntityId";
private static final String ENABLE_SMS_OTP_IF_RECOVERY_NOTIFICATION_ENABLED
Expand Down Expand Up @@ -3985,13 +3984,15 @@ public String addIdPWithResourceId(IdentityProvider identityProvider, int tenant
throw new IdentityProviderManagementException("An error occurred while processing content stream.", e);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
endpointConfigurationManager.deleteEndpointConfigurations(identityProvider.getDefaultAuthenticatorConfig(),
tenantId);
if (identityProvider.getFederatedAuthenticatorConfigs().length == 1) {
endpointConfigurationManager.deleteEndpointConfigurations(
identityProvider.getFederatedAuthenticatorConfigs()[0], tenantId);
}
throw new IdentityProviderManagementException("Error occurred while adding Identity Provider for tenant "
+ tenantId, e);
} catch (IdentityProviderManagementException e) {
if (ERROR_CODE_ASSOCIATED_ACTION_MGT.getCode().equals(e.getErrorCode())) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);;
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
}
throw e;
}
Expand Down Expand Up @@ -4315,13 +4316,17 @@ public void updateIdPWithResourceId(String resourceId, IdentityProvider
throw new IdentityProviderManagementException("An error occurred while processing content stream.", e);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
endpointConfigurationManager.updateEndpointConfigurations(currentIdentityProvider
.getDefaultAuthenticatorConfig(), newIdentityProvider.getDefaultAuthenticatorConfig(), tenantId);
//
if (currentIdentityProvider.getFederatedAuthenticatorConfigs().length == 1) {
endpointConfigurationManager.updateEndpointConfigurations(currentIdentityProvider
.getFederatedAuthenticatorConfigs()[0], newIdentityProvider.getFederatedAuthenticatorConfigs()[0],
tenantId);
}
throw new IdentityProviderManagementException("Error occurred while updating Identity Provider " +
"information for tenant " + tenantId, e);
} catch (IdentityProviderManagementException e) {
if (ERROR_CODE_ASSOCIATED_ACTION_MGT.getCode().equals(e.getErrorCode())) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);;
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
}
throw e;
} catch (ConnectorException e) {
Expand Down Expand Up @@ -4394,19 +4399,20 @@ public void deleteIdP(String idPName, int tenantId, String tenantDomain)
String msg = "Trying to delete non-existent Identity Provider: %s in tenantDomain: %s";
throw new IdentityProviderManagementException(String.format(msg, idPName, tenantDomain));
}
endpointConfigurationManager.deleteEndpointConfigurations(identityProvider.getDefaultAuthenticatorConfig(),
tenantId);
if (identityProvider.getFederatedAuthenticatorConfigs().length == 1) {
endpointConfigurationManager.deleteEndpointConfigurations(
identityProvider.getFederatedAuthenticatorConfigs()[0], tenantId);
}
deleteIdP(dbConnection, tenantId, idPName, null);
IdentityDatabaseUtil.commitTransaction(dbConnection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
endpointConfigurationManager.addEndpointConfigurations(identityProvider.getDefaultAuthenticatorConfig(),
tenantId);
rollBackEndpointConfigurationDeletion(identityProvider, tenantId);
throw new IdentityProviderManagementException("Error occurred while deleting Identity Provider of tenant "
+ tenantDomain, e);
} catch (IdentityProviderManagementException e) {
if (ERROR_CODE_ASSOCIATED_ACTION_MGT.getCode().equals(e.getErrorCode())) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);;
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
}
throw e;
} finally {
Expand Down Expand Up @@ -4454,21 +4460,22 @@ public void deleteIdPByResourceId(String resourceId, int tenantId, String tenant
throw new IdentityProviderManagementException(String.format(msg, resourceId, tenantDomain));
}
idPName = identityProvider.getIdentityProviderName();
endpointConfigurationManager.deleteEndpointConfigurations(identityProvider.getDefaultAuthenticatorConfig(),
tenantId);
if (identityProvider.getFederatedAuthenticatorConfigs().length == 1) {
endpointConfigurationManager.deleteEndpointConfigurations(
identityProvider.getFederatedAuthenticatorConfigs()[0], tenantId);
}
deleteIdP(dbConnection, tenantId, null, resourceId);
// Delete IdP related secrets from the IDN_SECRET table.
idpSecretsProcessorService.deleteAssociatedSecrets(identityProvider);
IdentityDatabaseUtil.commitTransaction(dbConnection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
endpointConfigurationManager.addEndpointConfigurations(identityProvider.getDefaultAuthenticatorConfig(),
tenantId);
rollBackEndpointConfigurationDeletion(identityProvider, tenantId);
throw new IdentityProviderManagementException("Error occurred while deleting Identity Provider of tenant "
+ tenantDomain, e);
} catch (IdentityProviderManagementException e) {
if (ERROR_CODE_ASSOCIATED_ACTION_MGT.getCode().equals(e.getErrorCode())) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);;
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
}
throw e;
} catch (SecretManagementException e) {
Expand Down Expand Up @@ -4502,21 +4509,22 @@ public void forceDeleteIdP(String idPName,
log.debug(String.format("Deleting SP Provisioning Associations for IDP:%s of tenantDomain:%s",
idPName, tenantDomain));
}
endpointConfigurationManager.deleteEndpointConfigurations(identityProvider.getDefaultAuthenticatorConfig(),
tenantId);
if (identityProvider.getFederatedAuthenticatorConfigs().length == 1) {
endpointConfigurationManager.deleteEndpointConfigurations(
identityProvider.getFederatedAuthenticatorConfigs()[0], tenantId);
}
deleteIdpSpProvisioningAssociations(dbConnection, tenantId, idPName);
deleteIdP(dbConnection, tenantId, idPName, null);
IdentityDatabaseUtil.commitTransaction(dbConnection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
endpointConfigurationManager.addEndpointConfigurations(identityProvider.getDefaultAuthenticatorConfig(),
tenantId);
rollBackEndpointConfigurationDeletion(identityProvider, tenantId);
throw new IdentityProviderManagementException(
String.format("Error occurred while deleting Identity Provider:%s of tenant:%s ",
idPName, tenantDomain), e);
} catch (IdentityProviderManagementException e) {
if (ERROR_CODE_ASSOCIATED_ACTION_MGT.getCode().equals(e.getErrorCode())) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);;
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
}
throw e;
} finally {
Expand Down Expand Up @@ -4549,20 +4557,21 @@ public void forceDeleteIdPByResourceId(String resourceId, int tenantId, String t
identityProvider.getIdentityProviderName(), tenantDomain));
}
deleteIdpSpProvisioningAssociations(dbConnection, tenantId, identityProvider.getIdentityProviderName());
endpointConfigurationManager.deleteEndpointConfigurations(identityProvider.getDefaultAuthenticatorConfig(),
tenantId);
if (identityProvider.getFederatedAuthenticatorConfigs().length == 1) {
endpointConfigurationManager.deleteEndpointConfigurations(
identityProvider.getFederatedAuthenticatorConfigs()[0], tenantId);
}
deleteIdP(dbConnection, tenantId, null, resourceId);
IdentityDatabaseUtil.commitTransaction(dbConnection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
endpointConfigurationManager.addEndpointConfigurations(identityProvider.getDefaultAuthenticatorConfig(),
tenantId);
rollBackEndpointConfigurationDeletion(identityProvider, tenantId);
throw new IdentityProviderManagementException(
String.format("Error occurred while deleting Identity Provider with resource ID:%s of tenant:%s ",
resourceId, tenantDomain), e);
} catch (IdentityProviderManagementException e) {
if (ERROR_CODE_ASSOCIATED_ACTION_MGT.getCode().equals(e.getErrorCode())) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);;
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
}
throw e;
} finally {
Expand Down Expand Up @@ -6104,4 +6113,13 @@ private void performConfigCorrectionForPasswordRecoveryConfigs(Connection dbConn
}
updateIdentityProviderProperties(dbConnection, idpId, idpProperties, tenantId);
}

private void rollBackEndpointConfigurationDeletion(IdentityProvider identityProvider, int tenantId) throws
IdentityProviderManagementException {

if (identityProvider.getFederatedAuthenticatorConfigs().length == 1) {
endpointConfigurationManager.addEndpointConfigurations(
identityProvider.getFederatedAuthenticatorConfigs()[0], tenantId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static IdpMgtServiceComponentHolder getInstance() {
private ClaimMetadataManagementService claimMetadataManagementService;
private SecretManager secretManager;
private SecretResolveManager secretResolveManager;
private ActionManagementService actionManagementService;

private List<MetadataConverter> metadataConverters = new ArrayList<>();

Expand Down Expand Up @@ -190,11 +191,21 @@ public void setClaimMetadataManagementService(ClaimMetadataManagementService cla
this.claimMetadataManagementService = claimMetadataManagementService;
}

/**
* Get the Action Management Service.
*
* @return ActionManagementService instance.
*/
public ActionManagementService getActionManagementService() {

return actionManagementService;
}

/**
* Set the Action Management Service.
*
* @param actionManagementService ActionManagementService instance.
*/
public void setActionManagementService(ActionManagementService actionManagementService) {

this.actionManagementService = actionManagementService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class AuthenticatorEndpointConfigurationManager {

private final String ACTION_ID_PROPERTY = "actionId";
private static final String ACTION_ID_PROPERTY = "actionId";

/**
* Create a new action for given endpoint configurations of the user defined authenticator.
Expand Down Expand Up @@ -163,7 +163,7 @@ public FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(Authentic
}

return new UserDefinedFederatedAuthenticatorConfig(
AuthenticatorPropertyConstants.AuthenticationType.Identification);
AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION);
}

private Action buildActionToCreate(String authenticatorName, EndpointConfig endpointConfig) {
Expand Down Expand Up @@ -191,6 +191,6 @@ private String getActionIdFromProperty(Property[] properties) throws IdentityPro
return property.getValue();
}
}
throw new IdentityProviderManagementServerException(String.format("No action id found from the property."));
throw new IdentityProviderManagementServerException("No action id found from the property.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ public enum ErrorMessage {
ERROR_CODE_VALIDATING_OUTBOUND_PROVISIONING_ROLES("IDP-65008", "Error while validating " +
"the outbound provisioning roles"),
ERROR_CODE_RETRIEVING_IDP_GROUPS("IDP-65009", "Error while retrieving IDP groups"),
ERROR_CODE_ASSOCIATED_ACTION_MGT("IDP-65010", "Error occurred with associated action management."),;
ERROR_CODE_ASSOCIATED_ACTION_MGT("IDP-65010", "Error occurred with managing associated action."),;

private final String code;
private final String message;
Expand Down
Loading

0 comments on commit e282f69

Please sign in to comment.