Skip to content

Commit

Permalink
Add VERSION, CREATED_AT, UPDATED_AT columns for IDN_SAML2_SERVICE_PRO…
Browse files Browse the repository at this point in the history
…VIDER table
  • Loading branch information
Osara-B committed Dec 19, 2024
1 parent b2e7bdf commit 1d8ffdd
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 1,621 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;


import static org.wso2.carbon.identity.core.util.JdbcUtils.isH2DB;

import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML_SCHEMA_VERSION;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.ID;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.TENANT_ID;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.ISSUER;
Expand Down Expand Up @@ -73,12 +79,18 @@
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.IDP_ENTITY_ID_ALIAS;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.ISSUER_QUALIFIER;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.VERSION;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.CREATED_AT;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.UPDATED_AT;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.PROPERTY_NAME;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.PROPERTY_VALUE;
import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.SP_ID;

import static java.time.ZoneOffset.UTC;

public class JDBCSAMLSSOServiceProviderDAOImpl implements SAMLSSOServiceProviderDAO {

private static final Calendar CALENDAR = Calendar.getInstance(TimeZone.getTimeZone(UTC));
private static final Log log = LogFactory.getLog(JDBCSAMLSSOServiceProviderDAOImpl.class);
private int tenantId;
private static final String CERTIFICATE_PROPERTY_NAME = "CERTIFICATE";
Expand Down Expand Up @@ -379,7 +391,7 @@ private void addProperties(int serviceProviderId, SAMLSSOServiceProviderDO servi
serviceProviderDO.addMultiValuedProperties(properties);
}

private void setServiceProviderParameters(NamedPreparedStatement statement,
private void setUpdateServiceProviderParameters(NamedPreparedStatement statement,
SAMLSSOServiceProviderDO serviceProviderDO) throws SQLException {

statement.setInt(TENANT_ID, tenantId);
Expand Down Expand Up @@ -412,6 +424,45 @@ private void setServiceProviderParameters(NamedPreparedStatement statement,
statement.setString(ISSUER_QUALIFIER, serviceProviderDO.getIssuerQualifier());
statement.setString(SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES,
serviceProviderDO.getSupportedAssertionQueryRequestTypes());
statement.setTimeStamp(UPDATED_AT, new Timestamp(new Date().getTime()), CALENDAR);
}

private void setServiceProviderParameters(NamedPreparedStatement statement,
SAMLSSOServiceProviderDO serviceProviderDO) throws SQLException {
Timestamp currentTime = new Timestamp(new Date().getTime());
statement.setInt(TENANT_ID, tenantId);
statement.setString(ISSUER, serviceProviderDO.getIssuer());
statement.setString(DEFAULT_ASSERTION_CONSUMER_URL, serviceProviderDO.getDefaultAssertionConsumerUrl());
statement.setString(NAME_ID_FORMAT, serviceProviderDO.getNameIDFormat());
statement.setString(CERT_ALIAS, serviceProviderDO.getCertAlias());
statement.setBoolean(REQ_SIG_VALIDATION, serviceProviderDO.isDoValidateSignatureInRequests());
statement.setBoolean(SIGN_RESPONSE, serviceProviderDO.isDoSignResponse());
statement.setBoolean(SIGN_ASSERTIONS, serviceProviderDO.isDoSignAssertions());
statement.setString(SIGNING_ALGO, serviceProviderDO.getSigningAlgorithmUri());
statement.setString(DIGEST_ALGO, serviceProviderDO.getDigestAlgorithmUri());
statement.setBoolean(ENCRYPT_ASSERTION, serviceProviderDO.isDoEnableEncryptedAssertion());
statement.setString(ASSERTION_ENCRYPTION_ALGO, serviceProviderDO.getAssertionEncryptionAlgorithmUri());
statement.setString(KEY_ENCRYPTION_ALGO, serviceProviderDO.getKeyEncryptionAlgorithmUri());
statement.setBoolean(ATTR_PROFILE_ENABLED, serviceProviderDO.isEnableAttributesByDefault());
statement.setString(ATTR_SERVICE_INDEX, serviceProviderDO.getAttributeConsumingServiceIndex());
statement.setBoolean(SLO_PROFILE_ENABLED, serviceProviderDO.isDoSingleLogout());
statement.setString(SLO_METHOD, serviceProviderDO.getSingleLogoutMethod());
statement.setString(SLO_RESPONSE_URL, serviceProviderDO.getSloResponseURL());
statement.setString(SLO_REQUEST_URL, serviceProviderDO.getSloRequestURL());
statement.setBoolean(IDP_INIT_SSO_ENABLED, serviceProviderDO.isIdPInitSSOEnabled());
statement.setBoolean(IDP_INIT_SLO_ENABLED, serviceProviderDO.isIdPInitSLOEnabled());
statement.setBoolean(QUERY_REQUEST_PROFILE_ENABLED, serviceProviderDO.isAssertionQueryRequestProfileEnabled());
statement.setBoolean(ECP_ENABLED, serviceProviderDO.isSamlECP());
statement.setBoolean(ARTIFACT_BINDING_ENABLED, serviceProviderDO.isEnableSAML2ArtifactBinding());
statement.setBoolean(ARTIFACT_RESOLVE_REQ_SIG_VALIDATION,
serviceProviderDO.isDoValidateSignatureInArtifactResolve());
statement.setString(IDP_ENTITY_ID_ALIAS, serviceProviderDO.getIdpEntityIDAlias());
statement.setString(ISSUER_QUALIFIER, serviceProviderDO.getIssuerQualifier());
statement.setString(SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES,
serviceProviderDO.getSupportedAssertionQueryRequestTypes());
statement.setString(VERSION, SAML_SCHEMA_VERSION);
statement.setTimeStamp(CREATED_AT, currentTime, CALENDAR);
statement.setTimeStamp(UPDATED_AT, currentTime, CALENDAR);
}

private int processGetServiceProviderId(String issuer) throws DataAccessException {
Expand Down Expand Up @@ -462,7 +513,7 @@ private void processUpdateServiceProvider(SAMLSSOServiceProviderDO serviceProvid
namedJdbcTemplate.executeUpdate(SAMLSSOServiceProviderConstants.SQLQueries.UPDATE_SAML2_SSO_CONFIG,
namedPreparedStatement -> {
namedPreparedStatement.setInt(ID, serviceProviderId);
setServiceProviderParameters(namedPreparedStatement, serviceProviderDO);
setUpdateServiceProviderParameters(namedPreparedStatement, serviceProviderDO);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class SAMLSSOServiceProviderConstants {

public static final String SAML_STORAGE_CONFIG = "DataStorageType.SAML";
public static final String SAML_SCHEMA_VERSION = "1.0.0";

public enum MultiValuedPropertyKey {
ASSERTION_CONSUMER_URLS("ASSERTION_CONSUMER_URLS"),
Expand Down Expand Up @@ -80,6 +81,9 @@ private SAML2TableColumns() {
public static final String ISSUER_QUALIFIER = "ISSUER_QUALIFIER";
public static final String SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES = "SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES";
public static final String TENANT_ID = "TENANT_ID";
public static final String VERSION = "VERSION";
public static final String CREATED_AT = "CREATED_AT";
public static final String UPDATED_AT = "UPDATED_AT";

// IDN_SAML2_SP_PROPERTIES table
public static final String PROPERTY_NAME = "PROPERTY_NAME";
Expand All @@ -102,15 +106,15 @@ private SQLQueries() {
"SLO_PROFILE_ENABLED, SLO_METHOD, SLO_RESPONSE_URL, SLO_REQUEST_URL, IDP_INIT_SSO_ENABLED, " +
"IDP_INIT_SLO_ENABLED, QUERY_REQUEST_PROFILE_ENABLED, ECP_ENABLED, ARTIFACT_BINDING_ENABLED, " +
"ARTIFACT_RESOLVE_REQ_SIG_VALIDATION, IDP_ENTITY_ID_ALIAS, ISSUER_QUALIFIER, " +
"SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES, TENANT_ID) " +
"SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES, TENANT_ID, VERSION, CREATED_AT, UPDATED_AT) " +
"VALUES (:ISSUER;, :DEFAULT_ASSERTION_CONSUMER_URL;, :NAME_ID_FORMAT;, :CERT_ALIAS;, " +
":REQ_SIG_VALIDATION;, :SIGN_RESPONSE;, :SIGN_ASSERTIONS;, :SIGNING_ALGO;, :DIGEST_ALGO;, " +
":ENCRYPT_ASSERTION;, :ASSERTION_ENCRYPTION_ALGO;, :KEY_ENCRYPTION_ALGO;, " +
":ATTR_PROFILE_ENABLED;, :ATTR_SERVICE_INDEX;, :SLO_PROFILE_ENABLED;, :SLO_METHOD;, " +
":SLO_RESPONSE_URL;, :SLO_REQUEST_URL;, :IDP_INIT_SSO_ENABLED;, :IDP_INIT_SLO_ENABLED;, " +
":QUERY_REQUEST_PROFILE_ENABLED;, :ECP_ENABLED;, :ARTIFACT_BINDING_ENABLED;, " +
":ARTIFACT_RESOLVE_REQ_SIG_VALIDATION;, :IDP_ENTITY_ID_ALIAS;, :ISSUER_QUALIFIER;, " +
":SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES;, :TENANT_ID;)";
":SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES;, :TENANT_ID;, :VERSION;, :CREATED_AT;, :UPDATED_AT;)";

public static final String UPDATE_SAML2_SSO_CONFIG =
"UPDATE IDN_SAML2_SERVICE_PROVIDER " +
Expand All @@ -129,7 +133,8 @@ private SQLQueries() {
"ECP_ENABLED = :ECP_ENABLED;, ARTIFACT_BINDING_ENABLED = :ARTIFACT_BINDING_ENABLED;, " +
"ARTIFACT_RESOLVE_REQ_SIG_VALIDATION = :ARTIFACT_RESOLVE_REQ_SIG_VALIDATION;, " +
"IDP_ENTITY_ID_ALIAS = :IDP_ENTITY_ID_ALIAS;, ISSUER_QUALIFIER = :ISSUER_QUALIFIER;, " +
"SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES = :SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES; " +
"SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES = :SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES;, " +
"UPDATED_AT = :UPDATED_AT;" +
"WHERE ID = :ID; AND TENANT_ID = :TENANT_ID;";

public static final String DELETE_SAML2_SSO_CONFIG_BY_ISSUER =
Expand Down Expand Up @@ -159,6 +164,9 @@ private SQLQueries() {
"FROM IDN_SAML2_SERVICE_PROVIDER " +
"WHERE TENANT_ID = :TENANT_ID;";

public static final String GET_SAML2_SSO_CONFIG_LAST_UPDATED_TIME =
"SELECT UPDATED_AT FROM KEY_STORE WHERE NAME = :NAME; AND TENANT_ID = :TENANT_ID;";

public static final String GET_SAML_SP_ID_BY_ISSUER =
"SELECT ID " +
"FROM IDN_SAML2_SERVICE_PROVIDER " +
Expand Down
Loading

0 comments on commit 1d8ffdd

Please sign in to comment.