Search in sources :

Example 6 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method getCertificateContent.

/**
 * Retrieves the certificate content from the database using the certificate reference id property of a
 * service provider.
 *
 * @param serviceProviderProperties
 * @param connection
 * @return
 * @throws CertificateRetrievingException
 */
private String getCertificateContent(List<ServiceProviderProperty> serviceProviderProperties, Connection connection) throws CertificateRetrievingException {
    String certificateReferenceId = null;
    for (ServiceProviderProperty property : serviceProviderProperties) {
        if ("CERTIFICATE".equals(property.getName())) {
            certificateReferenceId = property.getValue();
        }
    }
    if (certificateReferenceId != null) {
        PreparedStatement statementForFetchingCertificate = null;
        ResultSet results = null;
        try {
            statementForFetchingCertificate = connection.prepareStatement(GET_CERTIFICATE_BY_ID);
            statementForFetchingCertificate.setInt(1, Integer.parseInt(certificateReferenceId));
            results = statementForFetchingCertificate.executeQuery();
            String certificateContent = null;
            while (results.next()) {
                certificateContent = getBlobValue(results.getBinaryStream("CERTIFICATE_IN_PEM"));
            }
            if (certificateContent != null) {
                return certificateContent;
            }
        } catch (SQLException | IOException e) {
            String errorMessage = "An error occurred while retrieving the certificate for the " + "application.";
            log.error(errorMessage);
            throw new CertificateRetrievingException(errorMessage, e);
        } finally {
            IdentityApplicationManagementUtil.closeResultSet(results);
            IdentityApplicationManagementUtil.closeStatement(statementForFetchingCertificate);
        }
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) IOException(java.io.IOException) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty) CertificateRetrievingException(org.wso2.carbon.identity.core.CertificateRetrievingException)

Example 7 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project carbon-identity-framework by wso2.

the class DefaultLogoutRequestHandler method getRegisteredLogoutReturnUrl.

private String getRegisteredLogoutReturnUrl(String relyingParty, String requestType, String tenantDomain) throws IdentityApplicationManagementException {
    if (FrameworkConstants.OIDC.equals(requestType)) {
        requestType = FrameworkConstants.OAUTH2;
    }
    String configuredReturnUrl = ".*";
    ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
    ServiceProvider serviceProvider = appMgtService.getServiceProviderByClientId(relyingParty, requestType, tenantDomain);
    if (serviceProvider != null && serviceProvider.getSpProperties() != null) {
        for (ServiceProviderProperty spProperty : serviceProvider.getSpProperties()) {
            if (LOGOUT_RETURN_URL_SP_PROPERTY.equals(spProperty.getName())) {
                configuredReturnUrl = spProperty.getValue();
                if (log.isDebugEnabled()) {
                    log.debug("Logout caller path validation is configured for service provider of " + relyingParty);
                }
                break;
            }
        }
    }
    return configuredReturnUrl;
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)

Example 8 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2AuthzEndpointTest method provideHandleOAuthAuthorizationRequest1Data.

@DataProvider(name = "provideHandleOAuthAuthorizationRequest1Data")
public Object[][] provideHandleOAuthAuthorizationRequest1Data() {
    ServiceProvider sp1 = new ServiceProvider();
    ServiceProvider sp2 = new ServiceProvider();
    ServiceProvider sp3 = new ServiceProvider();
    ServiceProviderProperty property1 = new ServiceProviderProperty();
    property1.setName(SP_DISPLAY_NAME);
    property1.setValue("myApplication");
    ServiceProviderProperty property2 = new ServiceProviderProperty();
    property2.setName(SP_NAME);
    property2.setValue(APP_NAME);
    ServiceProviderProperty[] properties1 = new ServiceProviderProperty[] { property1, property2 };
    sp1.setSpProperties(properties1);
    ServiceProviderProperty[] properties2 = new ServiceProviderProperty[] { property2 };
    sp2.setSpProperties(properties2);
    return new Object[][] { { true, sp1, "myApplication" }, { true, sp2, null }, { true, sp3, null }, { false, sp1, null } };
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) RequestObject(org.wso2.carbon.identity.openidconnect.model.RequestObject) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty) DataProvider(org.testng.annotations.DataProvider)

Example 9 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2AuthzEndpoint method getSpDisplayName.

private String getSpDisplayName(String clientId) throws OAuthSystemException {
    if (getOAuthServerConfiguration().isShowDisplayNameInConsentPage()) {
        ServiceProvider serviceProvider = getServiceProvider(clientId);
        ServiceProviderProperty[] serviceProviderProperties = serviceProvider.getSpProperties();
        for (ServiceProviderProperty serviceProviderProperty : serviceProviderProperties) {
            if (DISPLAY_NAME.equals(serviceProviderProperty.getName())) {
                return serviceProviderProperty.getValue();
            }
        }
    }
    return StringUtils.EMPTY;
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)

Example 10 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project identity-inbound-auth-oauth by wso2-extensions.

the class DefaultOIDCClaimsCallbackHandlerTest method testHandleClaimsForOAuthAuthzReqMessageContextNullAccessToken.

@Test
public void testHandleClaimsForOAuthAuthzReqMessageContextNullAccessToken() throws Exception {
    JWTClaimsSet.Builder jwtClaimsSetBuilder = new JWTClaimsSet.Builder();
    AuthenticatedUser authenticatedUser = getDefaultAuthenticatedUserFederatedUser();
    OAuth2AuthorizeReqDTO authorizeReqDTO = new OAuth2AuthorizeReqDTO();
    authorizeReqDTO.setUser(authenticatedUser);
    authorizeReqDTO.setTenantDomain(TENANT_DOMAIN);
    OAuthAuthzReqMessageContext authzReqMessageContext = new OAuthAuthzReqMessageContext(authorizeReqDTO);
    authzReqMessageContext.setApprovedScope(APPROVED_SCOPES);
    ServiceProvider serviceProvider = new ServiceProvider();
    serviceProvider.setApplicationName(SERVICE_PROVIDER_NAME);
    ClaimMapping claimMap1 = ClaimMapping.build("http://www.wso2.org/claims/email", "email", "sample@abc.com", true);
    ClaimMapping claimMap2 = ClaimMapping.build("http://www.wso2.org/claims/username", "username", "user123", true);
    ClaimMapping[] requestedLocalClaimMap = { claimMap1, claimMap2 };
    ClaimConfig claimConfig = new ClaimConfig();
    claimConfig.setClaimMappings(requestedLocalClaimMap);
    serviceProvider.setClaimConfig(claimConfig);
    serviceProvider.setSpProperties(new ServiceProviderProperty[] {});
    OAuthServerConfiguration mockOAuthServerConfiguration = PowerMockito.mock(OAuthServerConfiguration.class);
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockOAuthServerConfiguration);
    when(mockOAuthServerConfiguration.getOpenIDConnectSkipeUserConsentConfig()).thenReturn(true);
    mockApplicationManagementService(serviceProvider);
    JWTClaimsSet jwtClaimsSet = defaultOIDCClaimsCallbackHandler.handleCustomClaims(jwtClaimsSetBuilder, authzReqMessageContext);
    assertEquals(jwtClaimsSet.getClaims().size(), 0, "Claims are not successfully set.");
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) OAuthAuthzReqMessageContext(org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) OAuth2AuthorizeReqDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) SAML2BearerGrantHandlerTest(org.wso2.carbon.identity.oauth2.token.handlers.grant.saml.SAML2BearerGrantHandlerTest) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ServiceProviderProperty (org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)24 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)8 PreparedStatement (java.sql.PreparedStatement)7 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)7 ArrayList (java.util.ArrayList)6 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)3 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)3 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)3 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)3 IOException (java.io.IOException)2 List (java.util.List)2 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)2 AuthenticationStep (org.wso2.carbon.identity.application.common.model.AuthenticationStep)2 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)2 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)2 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)2 Property (org.wso2.carbon.identity.application.common.model.Property)2 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)2