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

Introduce JDBC based persistence for SAML #6241

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Osara-B
Copy link
Contributor

@Osara-B Osara-B commented Dec 20, 2024

Proposed changes in this pull request

Introduce JDBC based persistence for SAML. Related to,

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
6.0% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 79.61783% with 96 lines in your changes missing coverage. Please review.

Project coverage is 45.87%. Comparing base (44b8576) to head (69291af).
Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
...ty/core/dao/JDBCSAMLSSOServiceProviderDAOImpl.java 86.47% 29 Missing and 14 partials ⚠️
.../identity/core/model/SAMLSSOServiceProviderDO.java 61.53% 3 Missing and 32 partials ⚠️
...ore/dao/RegistrySAMLSSOServiceProviderDAOImpl.java 48.14% 7 Missing and 7 partials ⚠️
...y/core/persistence/IdentityPersistenceManager.java 0.00% 3 Missing ⚠️
.../SAMLServiceProviderPersistenceManagerFactory.java 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6241      +/-   ##
============================================
+ Coverage     45.66%   45.87%   +0.20%     
- Complexity    14080    14183     +103     
============================================
  Files          1632     1636       +4     
  Lines        100764   101283     +519     
  Branches      17705    17781      +76     
============================================
+ Hits          46016    46462     +446     
- Misses        48036    48058      +22     
- Partials       6712     6763      +51     
Flag Coverage Δ
unit 28.69% <79.61%> (+0.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@darshanasbg darshanasbg changed the title Introduce SAMLSSOPersistenceManagerFactory and JDBC based persistence for SAML Introduce JDBC based persistence for SAML Dec 21, 2024
@@ -0,0 +1,193 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix licenses


package org.wso2.carbon.identity.core.dao;

public class SAMLSSOServiceProviderConstants {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a class comment


}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

return this.value;
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line

package org.wso2.carbon.identity.core.model;

/**
* This class represents a tuple of key and value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we improve a class comment a bit, indicating how this class related to the SAML

return StringUtils.isNotBlank(ISSUER_QUALIFIER) ?
issuer + IdentityRegistryResources.QUALIFIER_ID + ISSUER_QUALIFIER : issuer;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line

@@ -0,0 +1,49 @@
package org.wso2.carbon.identity.core.constant;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add licenses

public static final String UPDATED_ISSUER_QUALIFIER = "updatedIssuerQualifier";
public static final boolean UPDATED_DO_SINGLE_LOGOUT = false;
public static final String[] UPDATED_REQUESTED_RECIPIENTS = {"updatedRecipient1", "updatedRecipient2"};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

@@ -0,0 +1,65 @@
package org.wso2.carbon.identity.core.util;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add licenses.

--SAML--
CREATE INDEX IDX_SAML2_SP_ISSUER ON IDN_SAML2_SERVICE_PROVIDER (ISSUER, TENANT_ID);
CREATE INDEX IDX_SAML2_SP_TENANT_ID ON IDN_SAML2_SERVICE_PROVIDER (TENANT_ID);
CREATE INDEX IDX_SAML2_SP_PROPERTIES ON IDN_SAML2_SP_PROPERTIES (SP_ID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line

CREATE INDEX IDX_SAML2_SP_TENANT_ID ON IDN_SAML2_SERVICE_PROVIDER (TENANT_ID);
/
CREATE INDEX IDX_SAML2_SP_PROPERTIES ON IDN_SAML2_SP_PROPERTIES (SP_ID);
/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line

-- SAML --
CREATE INDEX IDX_SAML2_SP_ISSUER ON IDN_SAML2_SERVICE_PROVIDER (ISSUER, TENANT_ID);
CREATE INDEX IDX_SAML2_SP_TENANT_ID ON IDN_SAML2_SERVICE_PROVIDER (TENANT_ID);
CREATE INDEX IDX_SAML2_SP_PROPERTIES ON IDN_SAML2_SP_PROPERTIES (SP_ID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line

@@ -1700,4 +1752,4 @@ GO
-- Trigger AUTHORIZED_API delete by API_ID on API_RESOURCE deletion by ID --
CREATE TRIGGER API_RESOURCE_DELETE_TRIGGER ON API_RESOURCE INSTEAD OF DELETE AS BEGIN DELETE FROM AUTHORIZED_API WHERE API_ID IN (SELECT ID FROM DELETED) DELETE FROM API_RESOURCE WHERE ID IN (SELECT ID FROM deleted) END;

GO
GO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

-- SAML --
CREATE INDEX IDX_SAML2_SP_ISSUER ON IDN_SAML2_SERVICE_PROVIDER (ISSUER, TENANT_ID);
CREATE INDEX IDX_SAML2_SP_TENANT_ID ON IDN_SAML2_SERVICE_PROVIDER (TENANT_ID);
CREATE INDEX IDX_SAML2_SP_PROPERTIES ON IDN_SAML2_SP_PROPERTIES (SP_ID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

--SAML--
CREATE INDEX IDX_SAML2_SP_ISSUER ON IDN_SAML2_SERVICE_PROVIDER (ISSUER, TENANT_ID);
CREATE INDEX IDX_SAML2_SP_TENANT_ID ON IDN_SAML2_SERVICE_PROVIDER (TENANT_ID);
CREATE INDEX IDX_SAML2_SP_PROPERTIES ON IDN_SAML2_SP_PROPERTIES (SP_ID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

CREATE INDEX IDX_SAML2_SP_TENANT_ID ON IDN_SAML2_SERVICE_PROVIDER (TENANT_ID);
/
CREATE INDEX IDX_SAML2_SP_PROPERTIES ON IDN_SAML2_SP_PROPERTIES (SP_ID);
/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line

CREATE INDEX IDX_SAML2_SP_TENANT_ID ON IDN_SAML2_SERVICE_PROVIDER (TENANT_ID);
/
CREATE INDEX IDX_SAML2_SP_PROPERTIES ON IDN_SAML2_SP_PROPERTIES (SP_ID);
/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

-- SAML --
CREATE INDEX IDX_SAML2_SP_ISSUER ON IDN_SAML2_SERVICE_PROVIDER (ISSUER, TENANT_ID);
CREATE INDEX IDX_SAML2_SP_TENANT_ID ON IDN_SAML2_SERVICE_PROVIDER (TENANT_ID);
CREATE INDEX IDX_SAML2_SP_PROPERTIES ON IDN_SAML2_SP_PROPERTIES (SP_ID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.SP_ID;

import static java.time.ZoneOffset.UTC;
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

import java.util.Date;
import java.util.TimeZone;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove new line.

return certificateId != null ? certificateId : -1;
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

Comment on lines -257 to +268
throws IdentityException {
/**

Registry registry = getRegistry(tenantId);
* Add the service provider information to the registry.

* @param serviceProviderDO Service provider information object.

* @return True if addition successful.

* @throws IdentityException Error while persisting to the registry.

*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the method comment.

Comment on lines +271 to +272
registry = getRegistry(tenantId);
// Registry registry = getRegistry(tenantId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registry = getRegistry(tenantId); part should be removed.
Registry registry = getRegistry(tenantId); part should be uncommented.

@@ -78,6 +81,8 @@ public class SAMLSSOServiceProviderDO implements Serializable {
private boolean doFrontChannelLogout;
private String frontChannelLogoutBinding;

private static final String BACKCHANNEL_LOGOUT_BINDING = "BackChannel";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to move out this constant to a constants class.

/**
* Implementation of the SAMLSSOServiceProviderDAO interface for JDBC-based persistence.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the new line.

}

private void setServiceProviderParameters(NamedPreparedStatement statement,
SAMLSSOServiceProviderDO serviceProviderDO, int tenantId) throws SQLException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a new line here

Comment on lines +590 to +594
* @param serviceProviderDO
* @param tenant
* @return
* @throws SQLException
* @throws CertificateRetrievingException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add descriptions for parameters and return values

private X509Certificate getApplicationCertificate(SAMLSSOServiceProviderDO serviceProviderDO, Tenant tenant)
throws CertificateRetrievingException, DataAccessException {

// Check whether there is a certificate stored against the service provider (in the database)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check whether there is a certificate stored against the service provider (in the database)
// Check whether there is a certificate stored against the service provider (in the database).

Comment on lines +615 to +621
/**
* Returns the certificate reference ID for the given issuer (Service Provider) if there is one.
*
* @param issuer
* @return
* @throws SQLException
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add description for parameters and return statements


}

// IDN_SAML2_SERVICE_PROVIDER table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// IDN_SAML2_SERVICE_PROVIDER table
// IDN_SAML2_SERVICE_PROVIDER table.

@@ -0,0 +1,49 @@
package org.wso2.carbon.identity.core.constant;

public class TestConstants {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the class comment.


import static org.mockito.Mockito.spy;

public class TestUtils {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the class comment here.

throw new RuntimeException("No data source initiated for database: " + DB_NAME);
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the missing new line here.

Comment on lines +2057 to +2064
CREATE OR REPLACE TRIGGER IDN_SAML2_SERVICE_PROVIDER_TRIG
BEFORE INSERT
ON IDN_SAML2_SERVICE_PROVIDER
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT IDN_SAML2_SERVICE_PROVIDER_SEQ.nextval INTO :NEW.ID FROM dual;
END
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the indentation to align with other queries.

Comment on lines +2077 to +2084
CREATE OR REPLACE TRIGGER IDN_SAML2_SP_PROPERTIES_TRIG
BEFORE INSERT
ON IDN_SAML2_SP_PROPERTIES
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT IDN_SAML2_SP_PROPERTIES_SEQ.nextval INTO :NEW.ID FROM dual;
END
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the indentation to align with other queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants