Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new DefinedBy property to authenticator config. #5938

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import org.apache.axiom.om.OMElement;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.AuthenticationType;
import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType;

import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -46,6 +50,7 @@
public class FederatedAuthenticatorConfig implements Serializable {

private static final long serialVersionUID = -2361107623257323257L;
private static final Logger LOG = LoggerFactory.getLogger(LocalAuthenticatorConfig.class);

Check warning on line 53 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#L53

Added line #L53 was not covered by tests

@XmlElement(name = "Name")
protected String name;
Expand All @@ -63,6 +68,12 @@
@XmlElement(name = "Tags")
protected String[] tags;

@XmlElement(name = "DefinedBy")
protected DefinedByType definedByType;

@XmlElement(name = "AuthenticationType")
protected AuthenticationType authenticationType;

public static FederatedAuthenticatorConfig build(OMElement federatedAuthenticatorConfigOM) {

if (federatedAuthenticatorConfigOM == null) {
Expand Down Expand Up @@ -101,9 +112,17 @@
Property[] propertiesArr = propertiesArrList.toArray(new Property[propertiesArrList.size()]);
federatedAuthenticatorConfig.setProperties(propertiesArr);
}
} else if ("DefinedBy".equals(elementName)) {
federatedAuthenticatorConfig.setDefinedByType(
DefinedByType.valueOf(element.getText()));

Check warning on line 117 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#L116-L117

Added lines #L116 - L117 were not covered by tests
}
}

if (federatedAuthenticatorConfig.getDefinedByType() == null) {
federatedAuthenticatorConfig.setDefinedByType(DefinedByType.SYSTEM);

Check warning on line 122 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#L122

Added line #L122 was not covered by tests
}
federatedAuthenticatorConfig.setAuthenticationType(AuthenticationType.IDENTIFICATION);

Check warning on line 124 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#L124

Added line #L124 was not covered by tests

return federatedAuthenticatorConfig;
}

Expand Down Expand Up @@ -230,4 +249,44 @@

tags = tagList;
}

/**
* Get the defined by type of the federated authenticator config.
*
* @return DefinedByType
*/
public DefinedByType getDefinedByType() {

return definedByType;

Check warning on line 260 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#L260

Added line #L260 was not covered by tests
}

/**
* Set the defined by type of the federated authenticator config.
*
* @param type The defined by type of the authenticator config.
*/
public void setDefinedByType(DefinedByType type) {

definedByType = type;
}

Check warning on line 271 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#L270-L271

Added lines #L270 - L271 were not covered by tests

/**
* Get the authentication type of the federated authenticator config.
*
* @return AuthenticationType
*/
public AuthenticationType getAuthenticationType() {

return authenticationType;

Check warning on line 280 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#L280

Added line #L280 was not covered by tests
}

/**
* Set the authentication type of the federated authenticator config.
*
* @param type The authentication type.
*/
public void setAuthenticationType(AuthenticationType type) {

authenticationType = type;
}

Check warning on line 291 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#L290-L291

Added lines #L290 - L291 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import org.apache.axiom.om.OMElement;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.AuthenticationType;
import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType;
import org.wso2.carbon.identity.base.IdentityConstants;

import java.io.Serializable;
Expand All @@ -37,6 +41,8 @@
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import static org.wso2.carbon.identity.base.IdentityConstants.TAG_2FA;

/**
* Local authenticator configuration of an application.
*/
Expand All @@ -46,6 +52,7 @@
public class LocalAuthenticatorConfig implements Serializable {

private static final long serialVersionUID = 3363298518257599291L;
private static final Logger LOG = LoggerFactory.getLogger(LocalAuthenticatorConfig.class);

Check warning on line 55 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#L55

Added line #L55 was not covered by tests

@XmlElement(name = "Name")
protected String name;
Expand All @@ -63,6 +70,12 @@
@XmlElement(name = "Tags")
protected String[] tags;

@XmlElement(name = "DefinedBy")
protected DefinedByType definedByType;

@XmlElement(name = "AuthenticationType")
protected AuthenticationType authenticationType;

/*
* <LocalAuthenticatorConfig> <Name></Name> <DisplayName></DisplayName> <IsEnabled></IsEnabled>
* <Properties></Properties> </LocalAuthenticatorConfig>
Expand Down Expand Up @@ -111,8 +124,31 @@
Property[] propertiesArr = propertiesArrList.toArray(new Property[0]);
localAuthenticatorConfig.setProperties(propertiesArr);
}
} else if ("DefinedBy".equals(member.getLocalName())) {
localAuthenticatorConfig.setDefinedByType(DefinedByType.valueOf(member.getText()));

Check warning on line 128 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#L128

Added line #L128 was not covered by tests
} else if ("AuthenticationType".equals(member.getLocalName())) {
localAuthenticatorConfig.setAuthenticationType(
AuthenticationType.valueOf(member.getText()));

Check warning on line 131 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#L130-L131

Added lines #L130 - L131 were not covered by tests
}
}

Check warning on line 133 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#L133

Added line #L133 was not covered by tests

if (localAuthenticatorConfig.getDefinedByType() == null) {
localAuthenticatorConfig.setDefinedByType(DefinedByType.SYSTEM);
LOG.debug("The defined by type is not set for the {}. Hence setting default SYSTEM value.",
localAuthenticatorConfig.getName());

Check warning on line 138 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#L136-L138

Added lines #L136 - L138 were not covered by tests
}
if (localAuthenticatorConfig.getAuthenticationType() == null && localAuthenticatorConfig.getTags() != null) {
if (localAuthenticatorConfig.getTags() != null &&
Arrays.stream(localAuthenticatorConfig.getTags()).anyMatch(s -> s.equalsIgnoreCase(TAG_2FA))) {
localAuthenticatorConfig.setAuthenticationType(

Check warning on line 143 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#L143

Added line #L143 was not covered by tests
AuthenticationType.VERIFICATION_ONLY);
} else {
localAuthenticatorConfig.setAuthenticationType(AuthenticationType.IDENTIFICATION);

Check warning on line 146 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#L146

Added line #L146 was not covered by tests
}
LOG.debug("The defined by type is not set for the: {}. Hence setting value based on the factor for the: {}",
localAuthenticatorConfig.getName(), localAuthenticatorConfig.getAuthenticationType().toString());

Check warning on line 149 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#L148-L149

Added lines #L148 - L149 were not covered by tests
}

return localAuthenticatorConfig;
}

Expand Down Expand Up @@ -224,4 +260,44 @@

tags = tagList;
}

/**
* Get the defined by type of the Local authenticator config.
*
* @return DefinedByType
*/
public DefinedByType getDefinedByType() {

return definedByType;

Check warning on line 271 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#L271

Added line #L271 was not covered by tests
}

/**
* Set the defined by type of the Local authenticator config.
*
* @param type The defined by type of the authenticator config.
*/
public void setDefinedByType(DefinedByType type) {

definedByType = type;
}

Check warning on line 282 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#L281-L282

Added lines #L281 - L282 were not covered by tests

/**
* Get the authentication type of the Local authenticator config .
*
* @return AuthenticationType
*/
public AuthenticationType getAuthenticationType() {

return authenticationType;

Check warning on line 291 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#L291

Added line #L291 was not covered by tests
}

/**
* Set the authentication type of the Local authenticator config.
*
* @param type The authentication type.
*/
public void setAuthenticationType(AuthenticationType type) {

authenticationType = type;
}

Check warning on line 302 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#L301-L302

Added lines #L301 - L302 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import org.apache.axiom.om.OMElement;
import org.apache.commons.collections.CollectionUtils;
import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.AuthenticationType;
import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -74,6 +76,10 @@
}
}
}

requestPathAuthenticatorConfig.setAuthenticationType(AuthenticationType.REQUEST_PATH);
requestPathAuthenticatorConfig.setDefinedByType(DefinedByType.SYSTEM);

Check warning on line 81 in components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/RequestPathAuthenticatorConfig.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/RequestPathAuthenticatorConfig.java#L80-L81

Added lines #L80 - L81 were not covered by tests

return requestPathAuthenticatorConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ 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 IDP_AUTHENTICATOR_AUTHENTICATION_TYPE = "authenticationType";
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 @@ -77,6 +77,8 @@
import org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO;
import org.wso2.carbon.identity.application.mgt.internal.ApplicationManagementServiceComponent;
import org.wso2.carbon.identity.application.mgt.internal.ApplicationManagementServiceComponentHolder;
import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.AuthenticationType;
import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType;
import org.wso2.carbon.identity.base.IdentityException;
import org.wso2.carbon.identity.base.IdentityRuntimeException;
import org.wso2.carbon.identity.core.CertificateRetrievingException;
Expand Down Expand Up @@ -1566,6 +1568,13 @@
ApplicationConstants.LOCAL_IDP_NAME,
lclAuthenticator.getName(),
lclAuthenticator.getDisplayName());
} else {
Thisara-Welmilla marked this conversation as resolved.
Show resolved Hide resolved
/* On demand migration for already saved local authenticators to save definedBy and
authenticationType properties to the database.
Remove this else block, once on-demand migration is done.*/
log.debug("Authenticator already exists. Updating the authenticator.The defined "
+ "by type is set to: " + lclAuthenticator.getDefinedByType().toString());

Check warning on line 1576 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#L1575-L1576

Added lines #L1575 - L1576 were not covered by tests
//TODO: Update database with defined by properties for local authenticators.
}
if (authenticatorId > 0) {
// ID, TENANT_ID, AUTHENTICATOR_ID
Expand Down Expand Up @@ -3088,6 +3097,10 @@
.get(ApplicationConstants.IDP_AUTHENTICATOR_NAME));
localAuthenticator.setDisplayName(authenticatorInfo
.get(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME));
localAuthenticator.setDefinedByType(DefinedByType.valueOf(
authenticatorInfo.get(ApplicationConstants.IDP_AUTHENTICATOR_DEFINED_BY_TYPE)));
localAuthenticator.setAuthenticationType(AuthenticationType.valueOf(
authenticatorInfo.get(ApplicationConstants.IDP_AUTHENTICATOR_AUTHENTICATION_TYPE)));

Check warning on line 3103 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#L3100-L3103

Added lines #L3100 - L3103 were not covered by tests
stepLocalAuth.get(step).add(localAuthenticator);
} else {
Map<String, List<FederatedAuthenticatorConfig>> stepFedIdps = stepFedIdPAuthenticators
Expand All @@ -3106,6 +3119,9 @@
.get(ApplicationConstants.IDP_AUTHENTICATOR_NAME));
fedAuthenticator.setDisplayName(authenticatorInfo
.get(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME));
fedAuthenticator.setDefinedByType(DefinedByType.valueOf(
authenticatorInfo.get(ApplicationConstants.IDP_AUTHENTICATOR_DEFINED_BY_TYPE)));
fedAuthenticator.setAuthenticationType(AuthenticationType.IDENTIFICATION);
idpAuths.add(fedAuthenticator);
}

Expand Down Expand Up @@ -5017,6 +5033,11 @@
returnData
.put(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME, rs.getString(3));
}
// TODO: Read from database and set the DefinedBy and authenticationType properties to the authenticator.
returnData.put(ApplicationConstants.IDP_AUTHENTICATOR_DEFINED_BY_TYPE,
DefinedByType.SYSTEM.toString());
returnData.put(ApplicationConstants.IDP_AUTHENTICATOR_AUTHENTICATION_TYPE,
AuthenticationType.IDENTIFICATION.toString());
} finally {
IdentityApplicationManagementUtil.closeStatement(prepStmt);
}
Expand All @@ -5038,7 +5059,7 @@
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 +5071,8 @@
prepStmt.setString(4, authenticatorName);
prepStmt.setString(5, "1");
prepStmt.setString(6, authenticatorDispalyName);
//TODO: prepStmt.setString(7, DefinedByType.SYSTEM.toString());
//TODO: prepStmt.setString(8, AuthenticationType.<TYPE>.toString());
prepStmt.execute();
rs = prepStmt.getGeneratedKeys();
if (rs.next()) {
Expand Down
Loading
Loading