Skip to content

Commit

Permalink
Add new DefinedBy property to authenticator config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Sep 19, 2024
1 parent b40fb77 commit 10bba5c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ._-]*$";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("SYSTEM")));
stepLocalAuth.get(step).add(localAuthenticator);
} else {
Map<String, List<FederatedAuthenticatorConfig>> stepFedIdps = stepFedIdPAuthenticators
Expand All @@ -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("SYSTEM")));
idpAuths.add(fedAuthenticator);
}

Expand Down Expand Up @@ -5028,6 +5030,9 @@ private Map<String, String> getAuthenticatorInfo(Connection conn, int tenantId,
returnData.put(ApplicationConstants.IDP_AUTHENTICATOR_NAME, rs.getString(2));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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"));

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 10bba5c

Please sign in to comment.