Skip to content

Commit

Permalink
Add definedBy property to databases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Oct 10, 2024
1 parent 64eea15 commit 9856e5d
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 12 deletions.
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 @@ -289,7 +289,8 @@ public class ApplicationMgtDBQueries {
"B.DISPLAY_NAME FROM IDP A JOIN IDP_AUTHENTICATOR B ON A.ID = B.IDP_ID WHERE B.ID =? AND ((A.TENANT_ID =?" +
" AND B.TENANT_ID =?) OR (A.TENANT_ID=? AND A.NAME LIKE 'SHARED_%' AND B.TENANT_ID=?))";
public static final String STORE_LOCAL_AUTHENTICATOR = "INSERT INTO IDP_AUTHENTICATOR (TENANT_ID, IDP_ID, NAME," +
"IS_ENABLED, DISPLAY_NAME) VALUES (?, (SELECT ID FROM IDP WHERE IDP.NAME=? AND IDP.TENANT_ID =?), ?, ?, ?)";
"IS_ENABLED, DISPLAY_NAME, DEFINED_BY) " +
"VALUES (?, (SELECT ID FROM IDP WHERE IDP.NAME=? AND IDP.TENANT_ID =?), ?, ?, ?, ?)";

public static final String GET_SP_METADATA_BY_SP_ID = "SELECT ID, NAME, VALUE, DISPLAY_NAME FROM SP_METADATA " +
"WHERE SP_ID = ?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
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.AuthenticatorPropertyConstants.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 @@ -1565,7 +1566,8 @@ private void updateLocalAndOutboundAuthenticationConfiguration(int applicationId
authenticatorId = addAuthenticator(connection, tenantID,
ApplicationConstants.LOCAL_IDP_NAME,
lclAuthenticator.getName(),
lclAuthenticator.getDisplayName());
lclAuthenticator.getDisplayName(),
lclAuthenticator.getDefinedByType().toString());
}
if (authenticatorId > 0) {
// ID, TENANT_ID, AUTHENTICATOR_ID
Expand Down Expand Up @@ -3088,6 +3090,8 @@ private LocalAndOutboundAuthenticationConfig getLocalAndOutboundAuthenticationCo
.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)));
stepLocalAuth.get(step).add(localAuthenticator);
} else {
Map<String, List<FederatedAuthenticatorConfig>> stepFedIdps = stepFedIdPAuthenticators
Expand All @@ -3106,6 +3110,8 @@ private LocalAndOutboundAuthenticationConfig getLocalAndOutboundAuthenticationCo
.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)));
idpAuths.add(fedAuthenticator);
}

Expand Down Expand Up @@ -5016,6 +5022,7 @@ 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));
returnData.put(ApplicationConstants.IDP_AUTHENTICATOR_DEFINED_BY_TYPE, rs.getString(4));
}
} finally {
IdentityApplicationManagementUtil.closeStatement(prepStmt);
Expand All @@ -5032,13 +5039,12 @@ private Map<String, String> getAuthenticatorInfo(Connection conn, int tenantId,
* @return
* @throws SQLException
*/
private int addAuthenticator(Connection conn, int tenantId, String idpName,
String authenticatorName, String authenticatorDispalyName) throws SQLException {
private int addAuthenticator(Connection conn, int tenantId, String idpName, String authenticatorName,
String authenticatorDispalyName, String definedByType) throws SQLException {

int authenticatorId = -1;
PreparedStatement prepStmt = null;
ResultSet rs = null;
// TENANT_ID, IDP_ID, NAME,IS_ENABLED, DISPLAY_NAME
String sqlStmt = ApplicationMgtDBQueries.STORE_LOCAL_AUTHENTICATOR;
try {
String dbProductName = conn.getMetaData().getDatabaseProductName();
Expand All @@ -5050,6 +5056,7 @@ private int addAuthenticator(Connection conn, int tenantId, String idpName,
prepStmt.setString(4, authenticatorName);
prepStmt.setString(5, "1");
prepStmt.setString(6, authenticatorDispalyName);
prepStmt.setString(7, definedByType);
prepStmt.execute();
rs = prepStmt.getGeneratedKeys();
if (rs.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,12 @@ public class ApplicationMgtDBQueries {
public static final String LOAD_IDP_AUTHENTICATOR_ID = "SELECT A.ID FROM IDP_AUTHENTICATOR A JOIN IDP B ON A" +
".IDP_ID= B.ID WHERE A.NAME =? AND B.NAME=? AND ((A.TENANT_ID =? AND B.TENANT_ID =?) OR (B.TENANT_ID=? " +
"AND B.NAME LIKE 'SHARED_%'))";
public static final String LOAD_IDP_AND_AUTHENTICATOR_NAMES = "SELECT A.NAME, B.NAME, " +
"B.DISPLAY_NAME FROM IDP A JOIN IDP_AUTHENTICATOR B ON A.ID = B.IDP_ID WHERE B.ID =? AND ((A.TENANT_ID =?" +
public static final String LOAD_IDP_AND_AUTHENTICATOR_NAMES = "SELECT A.NAME, B.NAME, B.DISPLAY_NAME," +
" B.DEFINED_BY FROM IDP A JOIN IDP_AUTHENTICATOR B ON A.ID = B.IDP_ID WHERE B.ID =? AND ((A.TENANT_ID =?" +
" AND B.TENANT_ID =?) OR (A.TENANT_ID=? AND A.NAME LIKE 'SHARED_%' AND B.TENANT_ID=?))";
public static final String STORE_LOCAL_AUTHENTICATOR = "INSERT INTO IDP_AUTHENTICATOR (TENANT_ID, IDP_ID, NAME," +
"IS_ENABLED, DISPLAY_NAME) VALUES (?, (SELECT ID FROM IDP WHERE IDP.NAME=? AND IDP.TENANT_ID =?), ?, ?, ?)";
"IS_ENABLED, DISPLAY_NAME, DEFINED_BY) VALUES " +
"(?, (SELECT ID FROM IDP WHERE IDP.NAME=? AND IDP.TENANT_ID =?), ?, ?, ?, ?)";

public static final String GET_SP_METADATA_BY_SP_ID = "SELECT ID, NAME, VALUE, DISPLAY_NAME FROM SP_METADATA " +
"WHERE SP_ID = ?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.wso2.carbon.identity.application.common.model.RoleMapping;
import org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants;
import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil;
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.DefinedByType;
import org.wso2.carbon.identity.base.IdentityConstants;
import org.wso2.carbon.identity.core.ConnectorConfig;
import org.wso2.carbon.identity.core.ConnectorException;
Expand Down Expand Up @@ -1148,6 +1149,7 @@ private FederatedAuthenticatorConfig[] getFederatedAuthenticatorConfigs(
}

authnConfig.setDisplayName(rs.getString("DISPLAY_NAME"));
authnConfig.setDefinedByType(DefinedByType.valueOf(rs.getString("DEFINED_BY")));

if (defaultAuthName != null && authnConfig.getName().equals(defaultAuthName)) {
federatedIdp.getDefaultAuthenticatorConfig().setDisplayName(authnConfig.getDisplayName());
Expand Down Expand Up @@ -1424,6 +1426,7 @@ public void addFederatedAuthenticatorConfig(FederatedAuthenticatorConfig authnCo
}
prepStmt1.setString(4, authnConfig.getName());
prepStmt1.setString(5, authnConfig.getDisplayName());
prepStmt1.setString(6, authnConfig.getDefinedByType().toString());
prepStmt1.execute();

int authnId = getAuthenticatorIdentifier(dbConnection, idpId, authnConfig.getName());
Expand Down Expand Up @@ -2330,6 +2333,7 @@ private FederatedAuthenticatorConfig buildSAMLProperties(IdentityProvider identi
if (samlFederatedAuthConfig == null) {
samlFederatedAuthConfig = new FederatedAuthenticatorConfig();
samlFederatedAuthConfig.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.NAME);
samlFederatedAuthConfig.setDefinedByType(DefinedByType.SYSTEM);
}

List<Property> propertiesList = new ArrayList<>();
Expand Down Expand Up @@ -2713,6 +2717,7 @@ private void fillResidentIdpProperties(IdentityProvider identityProvider, String
if (openIdFedAuthn == null) {
openIdFedAuthn = new FederatedAuthenticatorConfig();
openIdFedAuthn.setName(IdentityApplicationConstants.Authenticator.OpenID.NAME);
openIdFedAuthn.setDefinedByType(DefinedByType.SYSTEM);
}
propertiesList = new ArrayList<>(Arrays.asList(openIdFedAuthn.getProperties()));
if (IdentityApplicationManagementUtil.getProperty(openIdFedAuthn.getProperties(),
Expand All @@ -2735,6 +2740,7 @@ private void fillResidentIdpProperties(IdentityProvider identityProvider, String
if (oauth1FedAuthn == null) {
oauth1FedAuthn = new FederatedAuthenticatorConfig();
oauth1FedAuthn.setName(IdentityApplicationConstants.OAuth10A.NAME);
oauth1FedAuthn.setDefinedByType(DefinedByType.SYSTEM);
}
propertiesList = new ArrayList<>(Arrays.asList(oauth1FedAuthn.getProperties()));
if (IdentityApplicationManagementUtil.getProperty(oauth1FedAuthn.getProperties(),
Expand Down Expand Up @@ -2770,6 +2776,7 @@ private void fillResidentIdpProperties(IdentityProvider identityProvider, String
if (oidcFedAuthn == null) {
oidcFedAuthn = new FederatedAuthenticatorConfig();
oidcFedAuthn.setName(IdentityApplicationConstants.Authenticator.OIDC.NAME);
oidcFedAuthn.setDefinedByType(DefinedByType.SYSTEM);
}
propertiesList = new ArrayList<>();

Expand Down Expand Up @@ -2841,6 +2848,7 @@ private void fillResidentIdpProperties(IdentityProvider identityProvider, String
if (passiveSTSFedAuthn == null) {
passiveSTSFedAuthn = new FederatedAuthenticatorConfig();
passiveSTSFedAuthn.setName(IdentityApplicationConstants.Authenticator.PassiveSTS.NAME);
passiveSTSFedAuthn.setDefinedByType(DefinedByType.SYSTEM);
}

propertiesList = new ArrayList<>();
Expand Down Expand Up @@ -2880,6 +2888,7 @@ private void fillResidentIdpProperties(IdentityProvider identityProvider, String
if (stsFedAuthn == null) {
stsFedAuthn = new FederatedAuthenticatorConfig();
stsFedAuthn.setName(IdentityApplicationConstants.Authenticator.WSTrust.NAME);
stsFedAuthn.setDefinedByType(DefinedByType.SYSTEM);
}
propertiesList = new ArrayList<>(Arrays.asList(stsFedAuthn.getProperties()));
if (IdentityApplicationManagementUtil.getProperty(stsFedAuthn.getProperties(),
Expand All @@ -2894,6 +2903,7 @@ private void fillResidentIdpProperties(IdentityProvider identityProvider, String

FederatedAuthenticatorConfig sessionTimeoutConfig = new FederatedAuthenticatorConfig();
sessionTimeoutConfig.setName(IdentityApplicationConstants.NAME);
sessionTimeoutConfig.setDefinedByType(DefinedByType.SYSTEM);

propertiesList = new ArrayList<>(Arrays.asList(sessionTimeoutConfig.getProperties()));

Expand Down Expand Up @@ -3409,6 +3419,7 @@ public IdentityProvider getIdPByAuthenticatorPropertyValue(Connection dbConnecti
String roleClaimUri = rs.getString("ROLE_CLAIM_URI");

String defaultAuthenticatorName = rs.getString("DEFAULT_AUTHENTICATOR_NAME");
String defaultAuthenticatorDefinedByType = rs.getString("DEFINED_BY");
String defaultProvisioningConnectorConfigName = rs.getString("DEFAULT_PRO_CONNECTOR_NAME");
federatedIdp.setIdentityProviderDescription(rs.getString("DESCRIPTION"));

Expand Down Expand Up @@ -3443,6 +3454,8 @@ public IdentityProvider getIdPByAuthenticatorPropertyValue(Connection dbConnecti
if (defaultAuthenticatorName != null) {
FederatedAuthenticatorConfig defaultAuthenticator = new FederatedAuthenticatorConfig();
defaultAuthenticator.setName(defaultAuthenticatorName);
defaultAuthenticator.setDefinedByType(DefinedByType.valueOf(
defaultAuthenticatorDefinedByType));
federatedIdp.setDefaultAuthenticatorConfig(defaultAuthenticator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static class SQLQueries {
public static final String GET_IDP_ID_BY_NAME_SQL = "SELECT ID "
+ "FROM IDP WHERE TENANT_ID=? AND NAME=?";

public static final String GET_ALL_IDP_AUTH_SQL = "SELECT ID, NAME, IS_ENABLED, DISPLAY_NAME FROM " +
public static final String GET_ALL_IDP_AUTH_SQL = "SELECT ID, NAME, IS_ENABLED, DISPLAY_NAME, DEFINED_BY FROM " +
"IDP_AUTHENTICATOR WHERE IDP_ID = ?";

public static final String GET_IDP_AUTH_SQL = "SELECT ID FROM IDP_AUTHENTICATOR WHERE IDP_ID = ? AND NAME = ?";
Expand Down Expand Up @@ -357,7 +357,7 @@ public static class SQLQueries {
public static final String TRUSTED_TOKEN_ISSUER_FILTER_SQL = "IDP_METADATA.\"VALUE\" = 'true' AND ";

public static final String ADD_IDP_AUTH_SQL = "INSERT INTO IDP_AUTHENTICATOR " +
"(IDP_ID, TENANT_ID, IS_ENABLED, NAME, DISPLAY_NAME) VALUES (?,?,?,?,?)";
"(IDP_ID, TENANT_ID, IS_ENABLED, NAME, DISPLAY_NAME, DEFINED_BY) VALUES (?,?,?,?,?,?)";

public static final String DELETE_IDP_AUTH_SQL = "DELETE FROM IDP_AUTHENTICATOR WHERE IDP_ID=? AND NAME=?";

Expand Down Expand Up @@ -448,7 +448,8 @@ public static class SQLQueries {
"idp.ROLE_CLAIM_URI, idp.DEFAULT_AUTHENTICATOR_NAME, idp.DEFAULT_PRO_CONNECTOR_NAME, " +
"idp.DESCRIPTION, " +
"idp.IS_FEDERATION_HUB, idp.IS_LOCAL_CLAIM_DIALECT, idp.PROVISIONING_ROLE, idp.IS_ENABLED, " +
"idp.DISPLAY_NAME " +
"idp.DISPLAY_NAME, " +
"idp_auth.DEFINED_BY " +
"FROM IDP idp INNER JOIN IDP_AUTHENTICATOR idp_auth ON idp.ID = idp_auth.IDP_ID INNER JOIN " +
"IDP_AUTHENTICATOR_PROPERTY idp_auth_pro ON idp_auth.ID = idp_auth_pro.AUTHENTICATOR_ID " +
"WHERE idp_auth_pro.PROPERTY_KEY =? AND idp_auth_pro.PROPERTY_VALUE = ? AND idp_auth_pro.TENANT_ID =?";
Expand All @@ -460,7 +461,8 @@ public static class SQLQueries {
"idp.ROLE_CLAIM_URI, idp.DEFAULT_AUTHENTICATOR_NAME, idp.DEFAULT_PRO_CONNECTOR_NAME, " +
"idp.DESCRIPTION, " +
"idp.IS_FEDERATION_HUB, idp.IS_LOCAL_CLAIM_DIALECT, idp.PROVISIONING_ROLE, idp.IS_ENABLED, " +
"idp.DISPLAY_NAME " +
"idp.DISPLAY_NAME, " +
"idp_auth.DEFINED_BY " +
"FROM IDP idp INNER JOIN IDP_AUTHENTICATOR idp_auth ON idp.ID = idp_auth.IDP_ID INNER JOIN " +
"IDP_AUTHENTICATOR_PROPERTY idp_auth_pro ON idp_auth.ID = idp_auth_pro.AUTHENTICATOR_ID " +
"WHERE idp_auth_pro.PROPERTY_KEY =? AND idp_auth_pro.PROPERTY_VALUE = ? AND idp_auth_pro.TENANT_ID " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ CREATE TABLE IDP_AUTHENTICATOR (
NAME VARCHAR(255) NOT NULL,
IS_ENABLED CHAR (1) DEFAULT '1',
DISPLAY_NAME VARCHAR(255),
DEFINED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
UNIQUE (TENANT_ID, IDP_ID, NAME),
FOREIGN KEY (IDP_ID) REFERENCES IDP(ID) ON DELETE CASCADE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ CREATE TABLE IF NOT EXISTS IDP_AUTHENTICATOR (
NAME VARCHAR(255) NOT NULL,
IS_ENABLED CHAR (1) DEFAULT '1',
DISPLAY_NAME VARCHAR(255),
DEFINED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
UNIQUE (TENANT_ID, IDP_ID, NAME),
FOREIGN KEY (IDP_ID) REFERENCES IDP(ID) ON DELETE CASCADE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ CREATE TABLE IDP_AUTHENTICATOR (
NAME VARCHAR(255) NOT NULL,
IS_ENABLED CHAR (1) DEFAULT '1',
DISPLAY_NAME VARCHAR(255),
DEFINED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
UNIQUE (TENANT_ID, IDP_ID, NAME),
FOREIGN KEY (IDP_ID) REFERENCES IDP(ID) ON DELETE CASCADE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ CREATE TABLE IF NOT EXISTS IDP_AUTHENTICATOR (
NAME VARCHAR(255) NOT NULL,
IS_ENABLED CHAR(1) DEFAULT '1',
DISPLAY_NAME VARCHAR(255),
DEFINED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
UNIQUE (TENANT_ID, IDP_ID, NAME),
FOREIGN KEY (IDP_ID) REFERENCES IDP (ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ CREATE TABLE IF NOT EXISTS IDP_AUTHENTICATOR (
NAME VARCHAR(255) NOT NULL,
IS_ENABLED CHAR (1) DEFAULT '1',
DISPLAY_NAME VARCHAR(255),
DEFINED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
UNIQUE (TENANT_ID, IDP_ID, NAME),
FOREIGN KEY (IDP_ID) REFERENCES IDP(ID) ON DELETE CASCADE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ CREATE TABLE IDP_AUTHENTICATOR (
NAME VARCHAR(255) NOT NULL,
IS_ENABLED CHAR (1) DEFAULT '1',
DISPLAY_NAME VARCHAR(255),
DEFINED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
UNIQUE (TENANT_ID, IDP_ID, NAME),
FOREIGN KEY (IDP_ID) REFERENCES IDP(ID) ON DELETE CASCADE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ CREATE TABLE IDP_AUTHENTICATOR (
NAME VARCHAR(255) NOT NULL,
IS_ENABLED CHAR (1) DEFAULT '1',
DISPLAY_NAME VARCHAR(255),
DEFINED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
UNIQUE (TENANT_ID, IDP_ID, NAME),
FOREIGN KEY (IDP_ID) REFERENCES IDP(ID) ON DELETE CASCADE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ CREATE TABLE IDP_AUTHENTICATOR (
NAME VARCHAR(255) NOT NULL,
IS_ENABLED CHAR (1) DEFAULT '1',
DISPLAY_NAME VARCHAR(255),
DEFINED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
UNIQUE (TENANT_ID, IDP_ID, NAME),
FOREIGN KEY (IDP_ID) REFERENCES IDP(ID) ON DELETE CASCADE);
Expand Down

0 comments on commit 9856e5d

Please sign in to comment.