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);
}
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);
}
}
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;
}
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);
}
}
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));
}
}
Aggregations