use of org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig in project carbon-apimgt by wso2.
the class RegistrationServiceImpl method createApplication.
/**
* Create a new client application
*
* @param appRequest OAuthAppRequest object with client's payload content
* @return created Application
* @throws APIKeyMgtException if failed to create the a new application
*/
private OAuthApplicationInfo createApplication(String applicationName, OAuthAppRequest appRequest, String grantType) throws APIManagementException {
String userName;
OAuthApplicationInfo applicationInfo = appRequest.getOAuthApplicationInfo();
String appName = applicationInfo.getClientName();
String userId = (String) applicationInfo.getParameter(OAUTH_CLIENT_USERNAME);
boolean isTenantFlowStarted = false;
if (userId == null || userId.isEmpty()) {
return null;
}
userName = MultitenantUtils.getTenantAwareUsername(userId);
String tenantDomain = MultitenantUtils.getTenantDomain(userId);
try {
if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
isTenantFlowStarted = true;
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName);
}
// Creating the service provider
ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName(applicationName);
serviceProvider.setDescription("Service Provider for application " + appName);
serviceProvider.setSaasApp(applicationInfo.getIsSaasApplication());
ServiceProviderProperty[] serviceProviderProperties = new ServiceProviderProperty[4];
ServiceProviderProperty serviceProviderProperty = new ServiceProviderProperty();
serviceProviderProperty.setName(APP_DISPLAY_NAME);
serviceProviderProperty.setValue(applicationName);
serviceProviderProperties[0] = serviceProviderProperty;
ServiceProviderProperty tokenTypeProviderProperty = new ServiceProviderProperty();
tokenTypeProviderProperty.setName(APIConstants.APP_TOKEN_TYPE);
tokenTypeProviderProperty.setValue(applicationInfo.getTokenType());
serviceProviderProperties[1] = tokenTypeProviderProperty;
ServiceProviderProperty consentProperty = new ServiceProviderProperty();
consentProperty.setDisplayName(APIConstants.APP_SKIP_CONSENT_DISPLAY);
consentProperty.setName(APIConstants.APP_SKIP_CONSENT_NAME);
consentProperty.setValue(APIConstants.APP_SKIP_CONSENT_VALUE);
serviceProviderProperties[2] = consentProperty;
ServiceProviderProperty logoutConsentProperty = new ServiceProviderProperty();
logoutConsentProperty.setDisplayName(APIConstants.APP_SKIP_LOGOUT_CONSENT_DISPLAY);
logoutConsentProperty.setName(APIConstants.APP_SKIP_LOGOUT_CONSENT_NAME);
logoutConsentProperty.setValue(APIConstants.APP_SKIP_LOGOUT_CONSENT_VALUE);
serviceProviderProperties[3] = logoutConsentProperty;
serviceProvider.setSpProperties(serviceProviderProperties);
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
appMgtService.createApplication(serviceProvider, tenantDomain, userName);
// Retrieving the created service provider
ServiceProvider createdServiceProvider = appMgtService.getApplicationExcludingFileBasedSPs(applicationName, tenantDomain);
if (createdServiceProvider == null) {
throw new APIManagementException("Error occurred while creating Service Provider " + "Application" + appName);
}
// creating the OAuth app
OAuthConsumerAppDTO createdOauthApp = this.createOAuthApp(applicationName, applicationInfo, grantType, userName);
// Set the OAuthApp in InboundAuthenticationConfig
InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig();
InboundAuthenticationRequestConfig[] inboundAuthenticationRequestConfigs = new InboundAuthenticationRequestConfig[1];
InboundAuthenticationRequestConfig inboundAuthenticationRequestConfig = new InboundAuthenticationRequestConfig();
String oAuthType = APIConstants.SWAGGER_12_OAUTH2;
inboundAuthenticationRequestConfig.setInboundAuthType(oAuthType);
inboundAuthenticationRequestConfig.setInboundAuthKey(createdOauthApp.getOauthConsumerKey());
String oauthConsumerSecret = createdOauthApp.getOauthConsumerSecret();
if (oauthConsumerSecret != null && !oauthConsumerSecret.isEmpty()) {
Property property = new Property();
property.setName(ApplicationConstants.INBOUNT_AUTH_CONSUMER_SECRET);
property.setValue(oauthConsumerSecret);
Property[] properties = { property };
inboundAuthenticationRequestConfig.setProperties(properties);
}
inboundAuthenticationRequestConfigs[0] = inboundAuthenticationRequestConfig;
inboundAuthenticationConfig.setInboundAuthenticationRequestConfigs(inboundAuthenticationRequestConfigs);
createdServiceProvider.setInboundAuthenticationConfig(inboundAuthenticationConfig);
// Setting the SaasApplication attribute to created service provider
createdServiceProvider.setSaasApp(applicationInfo.getIsSaasApplication());
createdServiceProvider.setSpProperties(serviceProviderProperties);
// Updating the service provider with Inbound Authentication Configs and SaasApplication
appMgtService.updateApplication(createdServiceProvider, tenantDomain, userName);
Map<String, String> valueMap = new HashMap<String, String>();
valueMap.put(OAUTH_REDIRECT_URIS, createdOauthApp.getCallbackUrl());
valueMap.put(OAUTH_CLIENT_NAME, createdOauthApp.getApplicationName());
valueMap.put(OAUTH_CLIENT_GRANT, createdOauthApp.getGrantTypes());
return this.fromAppDTOToApplicationInfo(createdOauthApp.getOauthConsumerKey(), applicationName, createdOauthApp.getCallbackUrl(), createdOauthApp.getOauthConsumerSecret(), createdServiceProvider.isSaasApp(), userId, valueMap);
} catch (IdentityApplicationManagementException e) {
log.error("Error occurred while creating the client application " + appName, e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().endTenantFlow();
}
}
return null;
}
use of org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method deleteApplication.
/**
* Deletes the application from IDN_APPMGT_APP table. Cascade deletes with foreign key
* constraints should delete the corresponding entries from the tables
*
* @param appName
* @throws IdentityApplicationManagementException
*/
public void deleteApplication(String appName) throws IdentityApplicationManagementException {
int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
Connection connection = IdentityDatabaseUtil.getDBConnection();
if (log.isDebugEnabled()) {
log.debug("Deleting Application " + appName);
}
// Now, delete the application
try {
// Delete the application certificate if there is any.
deleteCertificate(connection, appName, tenantID);
// First, delete all the clients of the application
int applicationID = getApplicationIDByName(appName, tenantID, connection);
InboundAuthenticationConfig clients = getInboundAuthenticationConfig(applicationID, connection, tenantID);
for (InboundAuthenticationRequestConfig client : clients.getInboundAuthenticationRequestConfigs()) {
handleClientDeletion(client.getInboundAuthKey(), client.getInboundAuthType());
}
handleDeleteServiceProvider(connection, appName, tenantID);
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException | UserStoreException | IdentityApplicationManagementException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
String errorMessege = "An error occured while delete the application : " + appName;
log.error(errorMessege, e);
throw new IdentityApplicationManagementException(errorMessege, e);
} finally {
IdentityApplicationManagementUtil.closeConnection(connection);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method updateInboundAuthRequestConfiguration.
/**
* @param applicationId
* @param inBoundAuthenticationConfig
* @param connection
* @throws SQLException
*/
private void updateInboundAuthRequestConfiguration(int applicationId, InboundAuthenticationConfig inBoundAuthenticationConfig, Connection connection) throws IdentityApplicationManagementException {
int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
PreparedStatement inboundAuthReqConfigPrepStmt = null;
try {
if (inBoundAuthenticationConfig == null || inBoundAuthenticationConfig.getInboundAuthenticationRequestConfigs() == null || inBoundAuthenticationConfig.getInboundAuthenticationRequestConfigs().length == 0) {
// no in-bound authentication requests defined.
return;
}
inboundAuthReqConfigPrepStmt = connection.prepareStatement(STORE_CLIENT_INFO);
InboundAuthenticationRequestConfig[] authRequests = inBoundAuthenticationConfig.getInboundAuthenticationRequestConfigs();
for (InboundAuthenticationRequestConfig authRequest : authRequests) {
if (authRequest == null || authRequest.getInboundAuthType() == null) {
log.warn("Invalid in-bound authentication request");
// not a valid authentication request. Must have client and a type.
continue;
}
Property[] propertiesArray = authRequest.getProperties();
List<Property> propertyArrayList = new ArrayList<>();
String authKey = null;
String inboundConfigType = ApplicationConstants.STANDARD_APPLICATION;
if (standardInboundAuthTypes.contains(authRequest.getInboundAuthType())) {
authKey = authRequest.getInboundAuthKey();
propertyArrayList = filterEmptyProperties(propertiesArray);
} else {
AbstractInboundAuthenticatorConfig inboundAuthenticatorConfig = ApplicationManagementServiceComponentHolder.getInboundAuthenticatorConfig(authRequest.getInboundAuthType() + ":" + authRequest.getInboundConfigType());
if (inboundAuthenticatorConfig != null && StringUtils.isNotBlank(inboundAuthenticatorConfig.getRelyingPartyKey())) {
if (propertiesArray != null && propertiesArray.length > 0) {
for (Property prop : propertiesArray) {
if (inboundAuthenticatorConfig.getRelyingPartyKey().equals(prop.getName())) {
if (StringUtils.isNotBlank(prop.getValue())) {
authKey = prop.getValue();
}
} else {
if (StringUtils.isNotBlank(prop.getValue())) {
propertyArrayList.add(prop);
}
}
}
}
} else {
propertyArrayList = filterEmptyProperties(propertiesArray);
}
}
if (StringUtils.isBlank(authKey)) {
String applicationName = getApplicationName(applicationId, connection);
if (StringUtils.isNotBlank(applicationName)) {
authKey = applicationName;
}
}
if (StringUtils.isNotBlank(authRequest.getInboundConfigType())) {
inboundConfigType = authRequest.getInboundConfigType();
}
if (!propertyArrayList.isEmpty()) {
for (Property prop : propertyArrayList) {
inboundAuthReqConfigPrepStmt.setInt(1, tenantID);
inboundAuthReqConfigPrepStmt.setString(2, authKey);
inboundAuthReqConfigPrepStmt.setString(3, authRequest.getInboundAuthType());
inboundAuthReqConfigPrepStmt.setString(4, prop.getName());
inboundAuthReqConfigPrepStmt.setString(5, prop.getValue());
inboundAuthReqConfigPrepStmt.setInt(6, applicationId);
inboundAuthReqConfigPrepStmt.setString(7, inboundConfigType);
inboundAuthReqConfigPrepStmt.addBatch();
}
} else {
inboundAuthReqConfigPrepStmt.setInt(1, tenantID);
inboundAuthReqConfigPrepStmt.setString(2, authKey);
inboundAuthReqConfigPrepStmt.setString(3, authRequest.getInboundAuthType());
inboundAuthReqConfigPrepStmt.setString(4, null);
inboundAuthReqConfigPrepStmt.setString(5, null);
inboundAuthReqConfigPrepStmt.setInt(6, applicationId);
inboundAuthReqConfigPrepStmt.setString(7, inboundConfigType);
inboundAuthReqConfigPrepStmt.addBatch();
}
if (log.isDebugEnabled()) {
log.debug("Updating inbound authentication request configuration of the application " + applicationId + "inbound auth key: " + authRequest.getInboundAuthKey() + " inbound auth type: " + authRequest.getInboundAuthType());
}
}
inboundAuthReqConfigPrepStmt.executeBatch();
} catch (SQLException e) {
log.error("Error occurred while updating the Inbound Authentication Request Configuration.", e);
} finally {
IdentityApplicationManagementUtil.closeStatement(inboundAuthReqConfigPrepStmt);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method deleteApplication.
/**
* Deletes the Application with application ID
*
* @param applicationID
* @param connection
* @throws IdentityApplicationManagementException
*/
public void deleteApplication(int applicationID, Connection connection) throws IdentityApplicationManagementException {
int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
if (log.isDebugEnabled()) {
log.debug("Deleting Application " + applicationID);
}
// Now, delete the application
PreparedStatement deleteClientPrepStmt = null;
try {
// delete clients
InboundAuthenticationConfig clients = getInboundAuthenticationConfig(applicationID, connection, tenantID);
for (InboundAuthenticationRequestConfig client : clients.getInboundAuthenticationRequestConfigs()) {
handleClientDeletion(client.getInboundAuthKey(), client.getInboundAuthType());
}
String applicationName = getApplicationName(applicationID, connection);
// delete roles
ApplicationMgtUtil.deleteAppRole(applicationName);
deleteClientPrepStmt = connection.prepareStatement(REMOVE_APP_FROM_APPMGT_APP_WITH_ID);
deleteClientPrepStmt.setInt(1, applicationID);
deleteClientPrepStmt.setInt(2, tenantID);
deleteClientPrepStmt.execute();
if (!connection.getAutoCommit()) {
connection.commit();
}
} catch (SQLException e) {
log.error(e.getMessage(), e);
throw new IdentityApplicationManagementException("Error deleting application");
} finally {
IdentityApplicationManagementUtil.closeStatement(deleteClientPrepStmt);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig in project carbon-identity-framework by wso2.
the class CacheBackedApplicationDAO method clearAppCacheByInboundKey.
private static void clearAppCacheByInboundKey(ServiceProvider serviceProvider, String tenantDomain) {
if (serviceProvider.getInboundAuthenticationConfig() != null && serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs() != null) {
InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();
for (InboundAuthenticationRequestConfig config : configs) {
if (config.getInboundAuthKey() != null) {
ServiceProviderCacheInboundAuthKey clientKey = new ServiceProviderCacheInboundAuthKey(config.getInboundAuthKey(), config.getInboundAuthType());
appCacheByInboundAuth.clearCacheEntry(clientKey, tenantDomain);
}
}
}
}
Aggregations