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 protocol config handler #412

Merged
merged 20 commits into from
Feb 16, 2024
Merged
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 @@ -237,6 +237,17 @@
<xs:element minOccurs="0" name="tenantZero" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="AuditLogDataType">
<xs:sequence>
<xs:element name="entry" type="ax2380:MapEntry" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MapEntry">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
<xs:element name="value" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="SAMLSSOServiceProviderDTO">
<!-- <xs:complexContent>-->
<!-- <xs:extension base="ax2381:InboundConfigurationProtocol">-->
Expand All @@ -246,6 +257,7 @@
<xs:element minOccurs="0" name="assertionEncryptionAlgorithmURI" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="assertionQueryRequestProfileEnabled" type="xs:boolean"/>
<xs:element minOccurs="0" name="attributeConsumingServiceIndex" nillable="true" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="auditLogData" nillable="true" type="ax2380:AuditLogDataType"/>
<xs:element minOccurs="0" name="certAlias" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="certificateContent" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="defaultAssertionConsumerUrl" nillable="true" type="xs:string"/>
Expand Down
8 changes: 8 additions & 0 deletions components/org.wso2.carbon.identity.sso.saml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.axis2.wso2</groupId>
<artifactId>axis2</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

<!-- for Java 17 Compatibility -->
<dependency>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ public boolean updateRPServiceProvider(SAMLSSOServiceProviderDTO serviceProvider
* @throws IdentityException
*/
public SAMLSSOServiceProviderDTO createServiceProvider(SAMLSSOServiceProviderDTO spDto) throws IdentityException {


return createServiceProvider(spDto, true);
}

SAMLSSOServiceProviderDTO createServiceProvider(SAMLSSOServiceProviderDTO spDto, boolean enableAuditing) throws IdentityException {

validateSAMLSSOServiceProviderDTO(spDto);
SAMLSSOConfigAdmin configAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry());
SAMLSSOConfigAdmin configAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry(), enableAuditing);
try {
return configAdmin.addSAMLServiceProvider(spDto);
} catch (IdentityException ex) {
Expand All @@ -137,8 +142,15 @@ public SAMLSSOServiceProviderDTO createServiceProvider(SAMLSSOServiceProviderDTO
public SAMLSSOServiceProviderDTO updateServiceProvider(SAMLSSOServiceProviderDTO serviceProviderDTO, String currentIssuer)
throws IdentityException {

return updateServiceProvider(serviceProviderDTO, currentIssuer, true);
}

SAMLSSOServiceProviderDTO updateServiceProvider(SAMLSSOServiceProviderDTO serviceProviderDTO, String currentIssuer,
boolean enableAuditing)
throws IdentityException {

validateSAMLSSOServiceProviderDTO(serviceProviderDTO);
SAMLSSOConfigAdmin configAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry());
SAMLSSOConfigAdmin configAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry(), enableAuditing);
try {
return configAdmin.updateSAMLServiceProvider(serviceProviderDTO, currentIssuer);
} catch (IdentityException ex) {
Expand Down Expand Up @@ -179,8 +191,14 @@ private void validateSAMLSSOServiceProviderDTO(SAMLSSOServiceProviderDTO service

public SAMLSSOServiceProviderDTO uploadRPServiceProvider(String metadata) throws IdentitySAML2SSOException {

return uploadRPServiceProvider(metadata, true);
}

SAMLSSOServiceProviderDTO uploadRPServiceProvider(String metadata, boolean enableAuditing)
throws IdentitySAML2SSOException {

try {
SAMLSSOConfigAdmin configAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry());
SAMLSSOConfigAdmin configAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry(), enableAuditing);
if (log.isDebugEnabled()) {
log.debug("Creating SAML Service Provider with metadata: " + metadata);
}
Expand All @@ -202,8 +220,15 @@ public SAMLSSOServiceProviderDTO uploadRPServiceProvider(String metadata) throws
public SAMLSSOServiceProviderDTO updateRPServiceProviderWithMetadata(String metadata, String currentIssuer)
throws IdentitySAML2SSOException {

return updateRPServiceProviderWithMetadata(metadata, currentIssuer, true);
}

SAMLSSOServiceProviderDTO updateRPServiceProviderWithMetadata(String metadata, String currentIssuer,
boolean enableAuditing)
throws IdentitySAML2SSOException {

try {
SAMLSSOConfigAdmin configAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry());
SAMLSSOConfigAdmin configAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry(), enableAuditing);
if (log.isDebugEnabled()) {
log.debug("Updating SAML Service Provider with metadata: " + metadata);
}
Expand All @@ -222,15 +247,21 @@ public SAMLSSOServiceProviderDTO updateRPServiceProviderWithMetadata(String meta
*/
public SAMLSSOServiceProviderDTO createServiceProviderWithMetadataURL(String metadataUrl)
throws IdentitySAML2SSOException {


return createServiceProviderWithMetadataURL(metadataUrl, true);
}

SAMLSSOServiceProviderDTO createServiceProviderWithMetadataURL(String metadataUrl, boolean enableAuditing)
throws IdentitySAML2SSOException {

try {
URL url = new URL(metadataUrl);
URLConnection con = url.openConnection();
con.setConnectTimeout(getConnectionTimeoutInMillis());
con.setReadTimeout(getReadTimeoutInMillis());
try (InputStream inputStream = new BoundedInputStream(con.getInputStream(), getMaxSizeInBytes())) {
String metadata = IOUtils.toString(inputStream);
return uploadRPServiceProvider(metadata);
return uploadRPServiceProvider(metadata, enableAuditing);
}
} catch (IOException e) {
throw handleIOException(URL_NOT_FOUND, "Non-existing metadata URL for SAML service provider creation in tenantDomain: "
Expand All @@ -249,19 +280,26 @@ public SAMLSSOServiceProviderDTO createServiceProviderWithMetadataURL(String met
public SAMLSSOServiceProviderDTO updateServiceProviderWithMetadataURL(String metadataUrl, String currentIssuer)
throws IdentitySAML2SSOException {

return updateServiceProviderWithMetadataURL(metadataUrl, currentIssuer, true);
}

SAMLSSOServiceProviderDTO updateServiceProviderWithMetadataURL(String metadataUrl, String currentIssuer,
boolean enableAuditing)
throws IdentitySAML2SSOException {

try {
URL url = new URL(metadataUrl);
URLConnection connection = url.openConnection();
connection.setConnectTimeout(getConnectionTimeoutInMillis());
connection.setReadTimeout(getReadTimeoutInMillis());
try (InputStream inputStream = new BoundedInputStream(connection.getInputStream(), getMaxSizeInBytes())) {
String metadata = IOUtils.toString(inputStream);
return updateRPServiceProviderWithMetadata(metadata, currentIssuer);
return updateRPServiceProviderWithMetadata(metadata, currentIssuer, enableAuditing);
}
} catch (IOException e) {
throw handleIOException(URL_NOT_FOUND,
"Non-existing metadata URL for SAML service provider creation in tenantDomain: "
+ getTenantDomain(), e);
+ getTenantDomain(), e);
}
}

Expand Down Expand Up @@ -459,8 +497,13 @@ public String getKeyEncryptionAlgorithmURIByConfig() {
*/
public boolean removeServiceProvider(String issuer) throws IdentityException {

return removeServiceProvider(issuer, true);
}

boolean removeServiceProvider(String issuer, boolean enableAuditing) throws IdentityException {

try {
SAMLSSOConfigAdmin ssoConfigAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry());
SAMLSSOConfigAdmin ssoConfigAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry(), enableAuditing);
return ssoConfigAdmin.removeServiceProvider(issuer);
} catch (IdentityException ex) {
String msg = "Error removing SAML SP with issuer: " + issuer + " in tenantDomain: " + getTenantDomain();
Expand Down Expand Up @@ -557,9 +600,12 @@ private Registry getGovernanceRegistry() {
private IdentitySAML2SSOException handleException(String message, IdentityException ex) {

setErrorCodeIfNotDefined(ex);
if (ex instanceof IdentitySAML2SSOException) {
if (ex instanceof IdentitySAML2ClientException) {
return (IdentitySAML2ClientException) ex;
} else if (ex instanceof IdentitySAML2SSOException) {
return (IdentitySAML2SSOException) ex;
} else {
}
else {
return new IdentitySAML2SSOException(ex.getErrorCode(), message, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public static class LogConstants {

public static final String CREATE_SAML_APPLICATION = "CREATE SAML APPLICATION";
public static final String DELETE_SAML_APPLICATION = "DELETE SAML APPLICATION";
public static final String UPDATE_SAML_APPLICATION = "UPDATE SAML APPLICATION";
public static final String SAML_INBOUND_SERVICE = "saml-inbound-service";

/**
Expand Down
Loading
Loading