Skip to content

Commit

Permalink
Fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sahandilshan committed Nov 30, 2023
1 parent 4f58f09 commit df0c7bd
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 {

Expand All @@ -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 {
Expand Down Expand Up @@ -135,7 +197,6 @@ private static SAMLSSOServiceProviderDTO getSamlSsoServiceProviderDTO(SAML2Proto
}
}


private static SAMLSSOServiceProviderDTO createSAMLSpWithMetadataFile(String encodedMetaFileContent)
throws IdentitySAML2SSOException {

Expand Down Expand Up @@ -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<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public SAMLSSOServiceProviderManager getSAMLSSOServiceProviderManager() {

/**
* Get SAMLSSOConfigService.
*
* @return SAMLSSOConfigService.
*/
public SAMLSSOConfigServiceImpl getSamlSSOConfigService() {
Expand All @@ -74,18 +75,29 @@ public SAMLSSOConfigServiceImpl getSamlSSOConfigService() {

/**
* Set SAMLSSOConfigService.
*
* @param samlSSOConfigService SAMLSSOConfigService.
*/
public void setSamlSSOConfigService(SAMLSSOConfigServiceImpl samlSSOConfigService) {

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -104,7 +121,6 @@ public void testCreateInboundSAML2Protocol() throws Exception {
public void testUpdateSAML2Protocol() throws Exception {

mockPrivilegeCarbonContext();
// mockApplicationManagementService();
mockSAMLSSOServiceComponentHolder();
mockServiceProvider(true);

Expand Down

0 comments on commit df0c7bd

Please sign in to comment.