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 6ab1997
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());

Check warning on line 120 in components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/FederatedAuthenticatorConfig.java

View check run for this annotation

Codecov / codecov/patch

components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/FederatedAuthenticatorConfig.java#L119-L120

Added lines #L119 - L120 were not covered by tests
}

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());

Check warning on line 127 in components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/LocalAuthenticatorConfig.java

View check run for this annotation

Codecov / codecov/patch

components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/LocalAuthenticatorConfig.java#L126-L127

Added lines #L126 - L127 were not covered by tests
}

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(ApplicationConstants.IDP_AUTHENTICATOR_DEFINED_BY_TYPE)));

Check warning on line 3102 in components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java

View check run for this annotation

Codecov / codecov/patch

components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java#L3101-L3102

Added lines #L3101 - L3102 were not covered by tests
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(ApplicationConstants.IDP_AUTHENTICATOR_DEFINED_BY_TYPE)));
idpAuths.add(fedAuthenticator);
}

Expand Down Expand Up @@ -5029,6 +5031,9 @@ private Map<String, String> 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);
}
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();

Check warning on line 4207 in components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java

View check run for this annotation

Codecov / codecov/patch

components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java#L4207

Added line #L4207 was not covered by tests
}
}

Check warning on line 4209 in components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java

View check run for this annotation

Codecov / codecov/patch

components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java#L4209

Added line #L4209 was not covered by tests

throw new FrameworkException("No authenticator instance is found for " + authenticatorName);

Check warning on line 4211 in components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java

View check run for this annotation

Codecov / codecov/patch

components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java#L4211

Added line #L4211 was not covered by tests
}
}
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(

Check warning on line 3458 in components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java

View check run for this annotation

Codecov / codecov/patch

components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java#L3458

Added line #L3458 was not covered by tests
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(

Check warning on line 3625 in components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java

View check run for this annotation

Codecov / codecov/patch

components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java#L3625

Added line #L3625 was not covered by tests
defaultAuthenticatorDefinedByType));
federatedIdp.setDefaultAuthenticatorConfig(defaultAuthenticator);
}

Expand Down

0 comments on commit 6ab1997

Please sign in to comment.