diff --git a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/FederatedAuthenticatorConfig.java b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/FederatedAuthenticatorConfig.java index fa22596f1e8a..7822d9404c38 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/FederatedAuthenticatorConfig.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/FederatedAuthenticatorConfig.java @@ -116,6 +116,7 @@ public static FederatedAuthenticatorConfig build(OMElement federatedAuthenticato // TODO: Remove warn log, once feature is ready. if (federatedAuthenticatorConfig.getDefinedByType() == null) { + federatedAuthenticatorConfig.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM); LOG.warn("The defined by type is not set for the : " + federatedAuthenticatorConfig.getName()); } diff --git a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/LocalAuthenticatorConfig.java b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/LocalAuthenticatorConfig.java index 58f528d1ec26..fa5dbde68778 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/LocalAuthenticatorConfig.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/LocalAuthenticatorConfig.java @@ -123,6 +123,7 @@ public static LocalAuthenticatorConfig build(OMElement localAuthenticatorConfigO } if (localAuthenticatorConfig.getDefinedByType() == null) { + localAuthenticatorConfig.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM); LOG.warn("The defined by type is not set for the : " + localAuthenticatorConfig.getName()); } diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationConstants.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationConstants.java index 2bca40c45d54..786ce81d1ef9 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationConstants.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationConstants.java @@ -50,6 +50,7 @@ private ApplicationConstants() { public static final String IDP_NAME = "idpName"; public static final String IDP_AUTHENTICATOR_NAME = "authenticatorName"; public static final String IDP_AUTHENTICATOR_DISPLAY_NAME = "authenticatorDisplayName"; + public static final String IDP_AUTHENTICATOR_DEFINED_BY_TYPE = "definedByType"; public static final String APPLICATION_DOMAIN = "Application"; // Regex for validating application name. public static final String APP_NAME_VALIDATING_REGEX = "^[a-zA-Z0-9 ._-]*$"; diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java index 48192a9b974a..f6f807a95011 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java @@ -3098,7 +3098,8 @@ private LocalAndOutboundAuthenticationConfig getLocalAndOutboundAuthenticationCo .get(ApplicationConstants.IDP_AUTHENTICATOR_NAME)); localAuthenticator.setDisplayName(authenticatorInfo .get(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME)); - localAuthenticator.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM); + localAuthenticator.setDefinedByType(IdentityConstants.DefinedByType.valueOf( + authenticatorInfo.get(ApplicationConstants.IDP_AUTHENTICATOR_DEFINED_BY_TYPE))); stepLocalAuth.get(step).add(localAuthenticator); } else { Map> stepFedIdps = stepFedIdPAuthenticators @@ -3117,7 +3118,8 @@ private LocalAndOutboundAuthenticationConfig getLocalAndOutboundAuthenticationCo .get(ApplicationConstants.IDP_AUTHENTICATOR_NAME)); fedAuthenticator.setDisplayName(authenticatorInfo .get(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME)); - fedAuthenticator.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM); + fedAuthenticator.setDefinedByType(IdentityConstants.DefinedByType.valueOf( + authenticatorInfo.get(ApplicationConstants.IDP_AUTHENTICATOR_DEFINED_BY_TYPE))); idpAuths.add(fedAuthenticator); } @@ -5029,6 +5031,9 @@ private Map getAuthenticatorInfo(Connection conn, int tenantId, returnData .put(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME, rs.getString(3)); } + // TODO: Read from database and set the DefinedBy property to the authenticator. + returnData.put(ApplicationConstants.IDP_AUTHENTICATOR_DEFINED_BY_TYPE, + IdentityConstants.DefinedByType.SYSTEM.toString()); } finally { IdentityApplicationManagementUtil.closeStatement(prepStmt); } diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java index 054821bc69bd..f6775e77740d 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java @@ -115,6 +115,7 @@ import org.wso2.carbon.identity.application.common.model.Property; import org.wso2.carbon.identity.application.common.model.ServiceProvider; import org.wso2.carbon.identity.application.mgt.ApplicationConstants; +import org.wso2.carbon.identity.base.IdentityConstants; import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.base.IdentityRuntimeException; import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils; @@ -4190,4 +4191,23 @@ public static boolean isURLRelative(String uriString) throws URISyntaxException return !new URI(uriString).isAbsolute(); } + + /** + * This method return defined by type for the given authenticator name. + * + * @param authenticatorName Name of the authenticator. + * @return The defined by type. + * @throws FrameworkException If no authenticator found for the given authenticator name. + */ + public static IdentityConstants.DefinedByType getAuthenticatorDefinedByType(String authenticatorName) + throws FrameworkException { + + for (ApplicationAuthenticator authenticator: FrameworkServiceComponent.getAuthenticators()) { + if (authenticator.getName().equals(authenticatorName)) { + return authenticator.getDefinedByType(); + } + } + + throw new FrameworkException("No authenticator instance is found for " + authenticatorName); + } } diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java index 15c492891b08..11a70218ccf5 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java @@ -3419,6 +3419,8 @@ public IdentityProvider getIdPByAuthenticatorPropertyValue(Connection dbConnecti String roleClaimUri = rs.getString("ROLE_CLAIM_URI"); String defaultAuthenticatorName = rs.getString("DEFAULT_AUTHENTICATOR_NAME"); + // TODO: Read from database and set the DefinedBy property to the authenticator. + String defaultAuthenticatorDefinedByType = IdentityConstants.DefinedByType.SYSTEM.toString(); String defaultProvisioningConnectorConfigName = rs.getString("DEFAULT_PRO_CONNECTOR_NAME"); federatedIdp.setIdentityProviderDescription(rs.getString("DESCRIPTION")); @@ -3453,8 +3455,8 @@ public IdentityProvider getIdPByAuthenticatorPropertyValue(Connection dbConnecti if (defaultAuthenticatorName != null) { FederatedAuthenticatorConfig defaultAuthenticator = new FederatedAuthenticatorConfig(); defaultAuthenticator.setName(defaultAuthenticatorName); - // TODO: Check the authenticator type and set the DefinedBy property accordingly. - defaultAuthenticator.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM); + defaultAuthenticator.setDefinedByType(IdentityConstants.DefinedByType.valueOf( + defaultAuthenticatorDefinedByType)); federatedIdp.setDefaultAuthenticatorConfig(defaultAuthenticator); } @@ -3584,6 +3586,8 @@ public IdentityProvider getIdPByAuthenticatorPropertyValue(Connection dbConnecti String roleClaimUri = rs.getString("ROLE_CLAIM_URI"); String defaultAuthenticatorName = rs.getString("DEFAULT_AUTHENTICATOR_NAME"); + // TODO: Read from database and set the DefinedBy property to the authenticator. + String defaultAuthenticatorDefinedByType = IdentityConstants.DefinedByType.SYSTEM.toString(); String defaultProvisioningConnectorConfigName = rs.getString("DEFAULT_PRO_CONNECTOR_NAME"); federatedIdp.setIdentityProviderDescription(rs.getString("DESCRIPTION")); @@ -3618,8 +3622,8 @@ public IdentityProvider getIdPByAuthenticatorPropertyValue(Connection dbConnecti if (defaultAuthenticatorName != null) { FederatedAuthenticatorConfig defaultAuthenticator = new FederatedAuthenticatorConfig(); defaultAuthenticator.setName(defaultAuthenticatorName); - // TODO: Check the authenticator type and set the DefinedBy property accordingly. - defaultAuthenticator.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM); + defaultAuthenticator.setDefinedByType(IdentityConstants.DefinedByType.valueOf( + defaultAuthenticatorDefinedByType)); federatedIdp.setDefaultAuthenticatorConfig(defaultAuthenticator); }