From df0c7bdfe13428cfab8857e7870de6cdedc514f4 Mon Sep 17 00:00:00 2001 From: sahandilshan Date: Thu, 30 Nov 2023 06:51:51 +0530 Subject: [PATCH] Fix formatting issues --- .../saml/SAML2InboundAuthConfigHandler.java | 69 +++++++++++++++++-- .../IdentitySAMLSSOServiceComponent.java | 24 ------- ...IdentitySAMLSSOServiceComponentHolder.java | 12 ++++ .../SAML2InboundAuthConfigHandlerTest.java | 20 +++++- 4 files changed, 95 insertions(+), 30 deletions(-) diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/SAML2InboundAuthConfigHandler.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/SAML2InboundAuthConfigHandler.java index c9f1ed1e..dc0a6abb 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/SAML2InboundAuthConfigHandler.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/SAML2InboundAuthConfigHandler.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.identity.sso.saml; import org.apache.commons.lang.StringUtils; @@ -21,26 +39,50 @@ import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.Optional; import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.SAML2; import static org.wso2.carbon.identity.application.mgt.inbound.InboundFunctions.getInboundAuthKey; +/** + * SAML2 inbound authentication configuration handler. + */ public class SAML2InboundAuthConfigHandler implements ApplicationInboundAuthConfigHandler { private static final String ATTRIBUTE_CONSUMING_SERVICE_INDEX = "attrConsumServiceIndex"; + /** + * Checks whether this handler can handle the inbound authentication request. + * + * @param inboundProtocolsDTO Inbound protocols DTO. + * @return True if InboundProtocolDTO contains SAML inbound auth configs. + */ @Override public boolean canHandle(InboundProtocolsDTO inboundProtocolsDTO) { return inboundProtocolsDTO.getInboundProtocolConfigurationMap().containsKey(SAML2); } + /** + * Checks whether this handler can handle the inbound authentication request. + * + * @param protocolName Name of the protocol. + * @return True if the protocolName is "samlsso". + */ @Override public boolean canHandle(String protocolName) { return StringUtils.containsIgnoreCase(ApplicationConstants.StandardInboundProtocols.SAML2, protocolName); } + /** + * Creates the inbound authentication request config from InboundProtocolConfigurationDTO. + * + * @param serviceProvider Service provider. + * @param inboundProtocolsDTO Inbound protocols DTO. + * @return InboundAuthenticationRequestConfig. + * @throws IdentityApplicationManagementException If an error occurs while creating the config. + */ @Override public InboundAuthenticationRequestConfig handleConfigCreation(ServiceProvider serviceProvider, InboundProtocolsDTO inboundProtocolsDTO) @@ -56,6 +98,14 @@ public InboundAuthenticationRequestConfig handleConfigCreation(ServiceProvider s } } + /** + * Updates the inbound authentication request config from InboundProtocolConfigurationDTO. + * + * @param serviceProvider Service provider. + * @param inboundProtocolConfigurationDTO Inbound protocol configuration DTO. + * @return InboundAuthenticationRequestConfig. + * @throws IdentityApplicationManagementException If an error occurs while updating the config. + */ @Override public InboundAuthenticationRequestConfig handleConfigUpdate( ServiceProvider serviceProvider, InboundProtocolConfigurationDTO inboundProtocolConfigurationDTO) @@ -71,6 +121,12 @@ public InboundAuthenticationRequestConfig handleConfigUpdate( } } + /** + * Deletes the inbound authentication request config. + * + * @param issuer Issuer of the SAMl2 application. + * @throws IdentityApplicationManagementException If an error occurs while deleting the config. + */ @Override public void handleConfigDeletion(String issuer) throws IdentityApplicationManagementException { @@ -82,6 +138,12 @@ public void handleConfigDeletion(String issuer) throws IdentityApplicationManage } } + /** + * Retrieves the inbound authentication request config. + * @param issuer Issuer of the SAMl2 application. + * @return InboundProtocolConfigurationDTO. + * @throws IdentityApplicationManagementException If an error occurs while retrieving the config. + */ @Override public InboundProtocolConfigurationDTO handleConfigRetrieval(String issuer) throws IdentityApplicationManagementException { @@ -135,7 +197,6 @@ private static SAMLSSOServiceProviderDTO getSamlSsoServiceProviderDTO(SAML2Proto } } - private static SAMLSSOServiceProviderDTO createSAMLSpWithMetadataFile(String encodedMetaFileContent) throws IdentitySAML2SSOException { @@ -175,12 +236,12 @@ InboundAuthenticationRequestConfig updateSAMLInbound(ServiceProvider application throws IdentitySAML2SSOException { // First we identify whether this is a insert or update. - String currentIssuer = getInboundAuthKey(application, FrameworkConstants.StandardInboundProtocols.SAML2); + Optional optionalInboundAuthKey = getInboundAuthKey(application, SAML2); InboundAuthenticationRequestConfig updatedInbound; - if (currentIssuer != null) { + if (optionalInboundAuthKey.isPresent()) { // This is an update. SAMLSSOServiceProviderDTO samlssoServiceProviderDTO = updateSamlSSoServiceProviderDTO( - saml2ProtocolConfigDTO, currentIssuer); + saml2ProtocolConfigDTO, optionalInboundAuthKey.get()); // Set certificate if available. if (samlssoServiceProviderDTO.getCertificateContent() != null) { diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponent.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponent.java index f6c3c0dc..dfa80996 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponent.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponent.java @@ -444,30 +444,6 @@ protected void unsetExtensionProcessor(SAMLExtensionProcessor extensionProcessor SAMLSSOUtil.removeExtensionProcessors(extensionProcessor); } -// /** -// * Add dependency to the ApplicationManagementService. -// */ -// @Reference( -// name = "identity.application.management.service", -// service = ApplicationManagementService.class, -// cardinality = ReferenceCardinality.MANDATORY, -// policy = ReferencePolicy.DYNAMIC, -// unbind = "unsetApplicationManagementService" -// ) -// protected void setApplicationManagementService(ApplicationManagementService applicationManagementService) { -// -// log.debug("ApplicationManagementService is available"); -// IdentitySAMLSSOServiceComponentHolder.getInstance().setApplicationManagementService( -// applicationManagementService); -// } -// -// protected void unsetApplicationManagementService(ApplicationManagementService applicationManagementService) { -// -// log.debug("Unset the ApplicationManagementService"); -// IdentitySAMLSSOServiceComponentHolder.getInstance().setApplicationManagementService(null); -// } - - @Reference( name = "saml.sso.service.provider.manager", service = org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager.class, diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java index cd059c25..8f7e0c9b 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java @@ -65,6 +65,7 @@ public SAMLSSOServiceProviderManager getSAMLSSOServiceProviderManager() { /** * Get SAMLSSOConfigService. + * * @return SAMLSSOConfigService. */ public SAMLSSOConfigServiceImpl getSamlSSOConfigService() { @@ -74,6 +75,7 @@ public SAMLSSOConfigServiceImpl getSamlSSOConfigService() { /** * Set SAMLSSOConfigService. + * * @param samlSSOConfigService SAMLSSOConfigService. */ public void setSamlSSOConfigService(SAMLSSOConfigServiceImpl samlSSOConfigService) { @@ -81,11 +83,21 @@ public void setSamlSSOConfigService(SAMLSSOConfigServiceImpl samlSSOConfigServic this.samlSSOConfigService = samlSSOConfigService; } + /** + * Get SAML2InboundAuthConfigHandler. + * + * @return SAML2InboundAuthConfigHandler. + */ public SAML2InboundAuthConfigHandler getSaml2InboundAuthConfigHandler() { return saml2InboundAuthConfigHandler; } + /** + * Set SAML2InboundAuthConfigHandler. + * + * @param saml2InboundAuthConfigHandler SAML2InboundAuthConfigHandler. + */ public void setSaml2InboundAuthConfigHandler(SAML2InboundAuthConfigHandler saml2InboundAuthConfigHandler) { this.saml2InboundAuthConfigHandler = saml2InboundAuthConfigHandler; diff --git a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/SAML2InboundAuthConfigHandlerTest.java b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/SAML2InboundAuthConfigHandlerTest.java index 5c7bf4b2..e616866f 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/SAML2InboundAuthConfigHandlerTest.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/SAML2InboundAuthConfigHandlerTest.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.identity.sso.saml; import org.apache.axis2.context.ConfigurationContext; @@ -17,7 +35,6 @@ import org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig; import org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig; import org.wso2.carbon.identity.application.common.model.ServiceProvider; -import org.wso2.carbon.identity.application.mgt.ApplicationManagementServiceImpl; import org.wso2.carbon.identity.application.mgt.inbound.dto.InboundProtocolsDTO; import org.wso2.carbon.identity.core.internal.IdentityCoreServiceComponent; import org.wso2.carbon.identity.sso.saml.dto.SAML2ProtocolConfigDTO; @@ -104,7 +121,6 @@ public void testCreateInboundSAML2Protocol() throws Exception { public void testUpdateSAML2Protocol() throws Exception { mockPrivilegeCarbonContext(); -// mockApplicationManagementService(); mockSAMLSSOServiceComponentHolder(); mockServiceProvider(true);