Search in sources :

Example 26 with ServiceProvider

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

the class ApplicationDAOImpl method addApplicationCertificateReferenceAsServiceProviderProperty.

/**
 * Add the given certificate ID as a property of the given service provider object.
 *
 * @param serviceProvider
 * @param newlyAddedCertificateID
 */
private void addApplicationCertificateReferenceAsServiceProviderProperty(ServiceProvider serviceProvider, int newlyAddedCertificateID) {
    ServiceProviderProperty[] serviceProviderProperties = serviceProvider.getSpProperties();
    ServiceProviderProperty[] newServiceProviderProperties;
    if (serviceProviderProperties != null) {
        newServiceProviderProperties = new ServiceProviderProperty[serviceProviderProperties.length + 1];
        for (int i = 0; i < serviceProviderProperties.length; i++) {
            newServiceProviderProperties[i] = serviceProviderProperties[i];
        }
    } else {
        newServiceProviderProperties = new ServiceProviderProperty[1];
    }
    ServiceProviderProperty propertyForCertificate = new ServiceProviderProperty();
    propertyForCertificate.setDisplayName("CERTIFICATE");
    propertyForCertificate.setName("CERTIFICATE");
    propertyForCertificate.setValue(String.valueOf(newlyAddedCertificateID));
    newServiceProviderProperties[newServiceProviderProperties.length - 1] = propertyForCertificate;
    serviceProvider.setSpProperties(newServiceProviderProperties);
}
Also used : ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)

Example 27 with ServiceProvider

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

the class ApplicationDAOImpl method persistApplicationCertificate.

/**
 * Persists the certificate content of the given service provider object,
 * and adds ID of the newly added certificate as a property of the service provider object.
 *
 * @param serviceProvider
 * @param tenantID
 * @param connection
 * @throws SQLException
 */
private void persistApplicationCertificate(ServiceProvider serviceProvider, int tenantID, Connection connection) throws SQLException, IdentityApplicationManagementException {
    // Configure the prepared statement to collect the auto generated id of the database record.
    PreparedStatement statementToAddCertificate = null;
    ResultSet results = null;
    try {
        String dbProductName = connection.getMetaData().getDatabaseProductName();
        statementToAddCertificate = connection.prepareStatement(ADD_CERTIFICATE, new String[] { DBUtils.getConvertedAutoGeneratedColumnName(dbProductName, "ID") });
        statementToAddCertificate.setString(1, serviceProvider.getApplicationName());
        setBlobValue(serviceProvider.getCertificateContent(), statementToAddCertificate, 2);
        statementToAddCertificate.setInt(3, tenantID);
        statementToAddCertificate.execute();
        results = statementToAddCertificate.getGeneratedKeys();
        int newlyAddedCertificateID = 0;
        if (results.next()) {
            newlyAddedCertificateID = results.getInt(1);
        }
        // So if the ID is not returned, get the ID by querying the database passing the certificate name.
        if (newlyAddedCertificateID == 0) {
            if (log.isDebugEnabled()) {
                log.debug("JDBC Driver did not return the application id, executing Select operation");
            }
            newlyAddedCertificateID = getCertificateIDByName(serviceProvider.getApplicationName(), tenantID, connection);
        }
        addApplicationCertificateReferenceAsServiceProviderProperty(serviceProvider, newlyAddedCertificateID);
    } catch (IOException e) {
        throw new IdentityApplicationManagementException("An error occurred while processing content stream " + "of certificate.", e);
    } finally {
        IdentityApplicationManagementUtil.closeResultSet(results);
        IdentityApplicationManagementUtil.closeStatement(statementToAddCertificate);
    }
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) IOException(java.io.IOException)

Example 28 with ServiceProvider

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

the class ApplicationDAOImpl method buildJwksProperty.

private ServiceProviderProperty buildJwksProperty(ServiceProvider sp) {
    ServiceProviderProperty jwksUri = new ServiceProviderProperty();
    jwksUri.setName(JWKS_URI_SP_PROPERTY_NAME);
    jwksUri.setDisplayName(JWKS_URI_SP_PROPERTY_NAME);
    jwksUri.setValue(StringUtils.isNotBlank(sp.getJwksUri()) ? sp.getJwksUri() : StringUtils.EMPTY);
    return jwksUri;
}
Also used : ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)

Example 29 with ServiceProvider

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

the class ApplicationDAOImpl method getApplicationByResourceId.

@Override
public ServiceProvider getApplicationByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
    try {
        int appId = getAppIdUsingResourceId(resourceId, tenantDomain);
        ServiceProvider application = getApplication(appId);
        if (application == null) {
            if (log.isDebugEnabled()) {
                log.debug("Cannot find an application for resourceId:" + resourceId + ", tenantDomain:" + tenantDomain);
            }
        }
        return application;
    } catch (IdentityApplicationManagementException ex) {
        throw new IdentityApplicationManagementServerException("Error while retrieving application with " + "resourceId: " + resourceId + " in tenantDomain: " + tenantDomain, ex);
    }
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException)

Example 30 with ServiceProvider

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

the class ApplicationDAOImpl method deleteCertificate.

/**
 * Delete the certificate of the given application if there is one.
 *
 * @param connection
 * @param appName
 * @param tenantID
 * @throws UserStoreException
 * @throws IdentityApplicationManagementException
 * @throws SQLException
 */
private void deleteCertificate(Connection connection, String appName, int tenantID) throws UserStoreException, IdentityApplicationManagementException, SQLException {
    String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    if (tenantID != MultitenantConstants.SUPER_TENANT_ID) {
        Tenant tenant = ApplicationManagementServiceComponentHolder.getInstance().getRealmService().getTenantManager().getTenant(tenantID);
        tenantDomain = tenant.getDomain();
    }
    ServiceProvider application = getApplication(appName, tenantDomain);
    String certificateReferenceID = getCertificateReferenceID(application.getSpProperties());
    if (certificateReferenceID != null) {
        deleteCertificate(connection, Integer.parseInt(certificateReferenceID));
    }
}
Also used : Tenant(org.wso2.carbon.user.api.Tenant) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider)

Aggregations

ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)222 Test (org.testng.annotations.Test)120 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)96 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)85 ArrayList (java.util.ArrayList)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)58 HashMap (java.util.HashMap)50 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)49 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)40 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)35 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)33 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)29 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)26 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)25 IdentityException (org.wso2.carbon.identity.base.IdentityException)23 Property (org.wso2.carbon.identity.application.common.model.xsd.Property)21 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)20 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig)20 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)20 Matchers.anyString (org.mockito.Matchers.anyString)19