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 16, 2024
1 parent 8ddc6a3 commit c4243a8
Show file tree
Hide file tree
Showing 36 changed files with 147 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.wso2.carbon.identity.application.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig;
Expand All @@ -31,6 +33,7 @@
public class ApplicationAuthenticatorService {

private static volatile ApplicationAuthenticatorService instance;
private static final Log LOG = LogFactory.getLog(ApplicationAuthenticatorService.class);

private List<LocalAuthenticatorConfig> localAuthenticators = new ArrayList<>();
private List<FederatedAuthenticatorConfig> federatedAuthenticators = new ArrayList<>();
Expand Down Expand Up @@ -88,6 +91,9 @@ public RequestPathAuthenticatorConfig getRequestPathAuthenticatorByName(String n

public void addLocalAuthenticator(LocalAuthenticatorConfig authenticator) {
if (authenticator != null) {
if (authenticator.getDefinedByType() == null) {
LOG.warn("The defined by type is not set for the : " + authenticator.getName());
}
localAuthenticators.add(authenticator);
}
}
Expand All @@ -100,6 +106,9 @@ public void removeLocalAuthenticator(LocalAuthenticatorConfig authenticator) {

public void addFederatedAuthenticator(FederatedAuthenticatorConfig authenticator) {
if (authenticator != null) {
if (authenticator.getDefinedByType() == null) {
LOG.warn("The defined by type is not set for the : " + authenticator.getName());
}
federatedAuthenticators.add(authenticator);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.axiom.om.OMElement;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.wso2.carbon.identity.base.IdentityConstants;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class FederatedAuthenticatorConfig implements Serializable {
@XmlElement(name = "Tags")
protected String[] tags;

protected IdentityConstants.DefinedByType definedByType;

public static FederatedAuthenticatorConfig build(OMElement federatedAuthenticatorConfigOM) {

if (federatedAuthenticatorConfigOM == null) {
Expand Down Expand Up @@ -101,6 +104,8 @@ public static FederatedAuthenticatorConfig build(OMElement federatedAuthenticato
Property[] propertiesArr = propertiesArrList.toArray(new Property[propertiesArrList.size()]);
federatedAuthenticatorConfig.setProperties(propertiesArr);
}
} else if ("DefinedBy".equals(elementName)) {
federatedAuthenticatorConfig.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM);
}
}

Expand Down Expand Up @@ -230,4 +235,24 @@ public void setTags(String[] tagList) {

tags = tagList;
}

/**
* Get the tag list of the Local authenticator.
*
* @return String[]
*/
public IdentityConstants.DefinedByType getDefinedByType() {

return definedByType;
}

/**
* Set the tag list for Local authenticator config.
*
* @param type authenticator.
*/
public void setDefinedByType(IdentityConstants.DefinedByType type) {

definedByType = type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
public class IdentityProvider implements Serializable {

private static final long serialVersionUID = 2199048941051702943L;
private static final Log LOG = LogFactory.getLog(IdentityProvider.class);

private static final Log log = LogFactory.getLog(IdentityProvider.class);
private static final String FILE_ELEMENT_IDENTITY_PROVIDER_NAME = "IdentityProviderName";
Expand Down Expand Up @@ -419,6 +420,11 @@ public void setFederatedAuthenticatorConfigs(
if (federatedAuthenticatorConfigs == null) {
return;
}
for (FederatedAuthenticatorConfig config: federatedAuthenticatorConfigs) {
if (config.getDefinedByType() == null) {
LOG.warn("The defined by type is not set for the : " + config.getName());
}
}
Set<FederatedAuthenticatorConfig> propertySet =
new HashSet<FederatedAuthenticatorConfig>(Arrays.asList(federatedAuthenticatorConfigs));
this.federatedAuthenticatorConfigs = propertySet.toArray(new FederatedAuthenticatorConfig[propertySet.size()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class LocalAuthenticatorConfig implements Serializable {
@XmlElement(name = "Tags")
protected String[] tags;

protected IdentityConstants.DefinedByType definedByType;

/*
* <LocalAuthenticatorConfig> <Name></Name> <DisplayName></DisplayName> <IsEnabled></IsEnabled>
* <Properties></Properties> </LocalAuthenticatorConfig>
Expand Down Expand Up @@ -111,6 +113,8 @@ public static LocalAuthenticatorConfig build(OMElement localAuthenticatorConfigO
Property[] propertiesArr = propertiesArrList.toArray(new Property[0]);
localAuthenticatorConfig.setProperties(propertiesArr);
}
} else if ("DefinedBy".equals(member.getLocalName())) {
localAuthenticatorConfig.setDefinedByType(IdentityConstants.DefinedByType.valueOf(member.getText()));
}
}
return localAuthenticatorConfig;
Expand Down Expand Up @@ -224,4 +228,24 @@ public void setTags(String[] tagList) {

tags = tagList;
}

/**
* Get the tag list of the Local authenticator.
*
* @return String[]
*/
public IdentityConstants.DefinedByType getDefinedByType() {

return definedByType;
}

/**
* Set the tag list for Local authenticator config.
*
* @param type authenticator.
*/
public void setDefinedByType(IdentityConstants.DefinedByType type) {

definedByType = type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,15 @@ private void updateLocalAndOutboundAuthenticationConfiguration(int applicationId
ApplicationConstants.LOCAL_IDP_NAME,
lclAuthenticator.getName(),
lclAuthenticator.getDisplayName());
} else {
if (lclAuthenticator.getDefinedByType() == null) {
log.warn("Authenticator already exists. Updating the authenticator, but the " +
"defined by type is not set.");
} else {
log.debug("Authenticator already exists. Updating the authenticator.The defined "
+ "by type is set to: " + lclAuthenticator.getDefinedByType().toString());
//TODO: Update database with defined by properties for local authenticators.
}
}
if (authenticatorId > 0) {
// ID, TENANT_ID, AUTHENTICATOR_ID
Expand Down Expand Up @@ -5038,7 +5047,7 @@ private int addAuthenticator(Connection conn, int tenantId, String idpName,
int authenticatorId = -1;
PreparedStatement prepStmt = null;
ResultSet rs = null;
// TENANT_ID, IDP_ID, NAME,IS_ENABLED, DISPLAY_NAME
// TENANT_ID, IDP_ID, NAME,IS_ENABLED, DISPLAY_NAME, DEFINED_BY
String sqlStmt = ApplicationMgtDBQueries.STORE_LOCAL_AUTHENTICATOR;
try {
String dbProductName = conn.getMetaData().getDatabaseProductName();
Expand All @@ -5050,6 +5059,7 @@ private int addAuthenticator(Connection conn, int tenantId, String idpName,
prepStmt.setString(4, authenticatorName);
prepStmt.setString(5, "1");
prepStmt.setString(6, authenticatorDispalyName);
//TODO: prepStmt.setString(7, IdentityConstants.DefinedByType.SYSTEM.toString());
prepStmt.execute();
rs = prepStmt.getGeneratedKeys();
if (rs.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.wso2.carbon.identity.application.authentication.framework.exception.LogoutFailedException;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatorData;
import org.wso2.carbon.identity.application.common.model.Property;
import org.wso2.carbon.identity.base.IdentityConstants;

import java.io.Serializable;
import java.util.List;
Expand Down Expand Up @@ -171,4 +172,13 @@ default String getI18nKey() {
return StringUtils.EMPTY;
}

/**
* Get the authenticator type. Default value will be SYSTEM.
*
* @return Authenticator Type.
*/
default IdentityConstants.DefinedByType getDefinedByType() {

return IdentityConstants.DefinedByType.SYSTEM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import org.wso2.carbon.identity.application.common.model.Property;
import org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.base.IdentityConstants;
import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService;
import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager;
import org.wso2.carbon.identity.core.handler.HandlerComparator;
Expand Down Expand Up @@ -506,6 +507,7 @@ protected void setAuthenticator(ApplicationAuthenticator authenticator) {
localAuthenticatorConfig.setProperties(configProperties);
localAuthenticatorConfig.setDisplayName(authenticator.getFriendlyName());
localAuthenticatorConfig.setTags(getTags(authenticator));
localAuthenticatorConfig.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM);
AuthenticatorConfig fileBasedConfig = getAuthenticatorConfig(authenticator.getName());
localAuthenticatorConfig.setEnabled(fileBasedConfig.isEnabled());
ApplicationAuthenticatorService.getInstance().addLocalAuthenticator(localAuthenticatorConfig);
Expand All @@ -515,6 +517,7 @@ protected void setAuthenticator(ApplicationAuthenticator authenticator) {
federatedAuthenticatorConfig.setProperties(configProperties);
federatedAuthenticatorConfig.setDisplayName(authenticator.getFriendlyName());
federatedAuthenticatorConfig.setTags(getTags(authenticator));
federatedAuthenticatorConfig.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM);
ApplicationAuthenticatorService.getInstance().addFederatedAuthenticator(federatedAuthenticatorConfig);
} else if (authenticator instanceof RequestPathApplicationAuthenticator) {
RequestPathAuthenticatorConfig reqPathAuthenticatorConfig = new RequestPathAuthenticatorConfig();
Expand All @@ -524,6 +527,7 @@ protected void setAuthenticator(ApplicationAuthenticator authenticator) {
reqPathAuthenticatorConfig.setTags(getTags(authenticator));
AuthenticatorConfig fileBasedConfig = getAuthenticatorConfig(authenticator.getName());
reqPathAuthenticatorConfig.setEnabled(fileBasedConfig.isEnabled());
reqPathAuthenticatorConfig.setDefinedByType(IdentityConstants.DefinedByType.SYSTEM);
ApplicationAuthenticatorService.getInstance().addRequestPathAuthenticator(reqPathAuthenticatorConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<LocalAuthenticatorConfig>
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<DefinedBy>SYSTEM</DefinedBy>
<IsEnabled>true</IsEnabled>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
Expand Down Expand Up @@ -85,6 +86,7 @@
<Name>BasicFailingMockAuthenticator</Name>
<DisplayName>basicauthfialing</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down Expand Up @@ -85,6 +86,7 @@
<Name>MockFallbackAuthenticator</Name>
<DisplayName>basicauthfallback</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Name>BasicMockAuthenticator</Name>
<DisplayName>basicauth</DisplayName>
<IsEnabled>true</IsEnabled>
<DefinedBy>SYSTEM</DefinedBy>
</LocalAuthenticatorConfig>
</LocalAuthenticatorConfigs>
<SubjectStep>true</SubjectStep>
Expand Down
Loading

0 comments on commit c4243a8

Please sign in to comment.