|
|
@ -15,7 +15,6 @@
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.dynamic.client.registration.impl;
|
|
|
|
package org.wso2.carbon.dynamic.client.registration.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
@ -25,21 +24,13 @@ import org.json.JSONObject;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.RegistryType;
|
|
|
|
import org.wso2.carbon.context.RegistryType;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.ApplicationConstants;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.*;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.OAuthApplicationInfo;
|
|
|
|
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile;
|
|
|
|
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
|
|
|
|
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
|
|
|
|
import org.wso2.carbon.identity.application.common.model.AuthenticationStep;
|
|
|
|
import org.wso2.carbon.identity.application.common.model.*;
|
|
|
|
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.LocalAndOutboundAuthenticationConfig;
|
|
|
|
|
|
|
|
import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig;
|
|
|
|
|
|
|
|
import org.wso2.carbon.identity.application.common.model.Property;
|
|
|
|
|
|
|
|
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
|
|
|
|
|
|
|
|
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
|
|
|
|
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
|
|
|
|
import org.wso2.carbon.identity.base.IdentityException;
|
|
|
|
import org.wso2.carbon.identity.base.IdentityException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.identity.oauth.IdentityOAuthAdminException;
|
|
|
|
import org.wso2.carbon.identity.oauth.OAuthAdminService;
|
|
|
|
import org.wso2.carbon.identity.oauth.OAuthAdminService;
|
|
|
|
import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO;
|
|
|
|
import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO;
|
|
|
|
import org.wso2.carbon.identity.sso.saml.admin.SAMLSSOConfigAdmin;
|
|
|
|
import org.wso2.carbon.identity.sso.saml.admin.SAMLSSOConfigAdmin;
|
|
|
@ -155,6 +146,10 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
// Create the Service Provider
|
|
|
|
// Create the Service Provider
|
|
|
|
ServiceProvider serviceProvider = new ServiceProvider();
|
|
|
|
ServiceProvider serviceProvider = new ServiceProvider();
|
|
|
|
serviceProvider.setApplicationName(applicationName);
|
|
|
|
serviceProvider.setApplicationName(applicationName);
|
|
|
|
|
|
|
|
User user = new User();
|
|
|
|
|
|
|
|
user.setUserName(userName);
|
|
|
|
|
|
|
|
user.setTenantDomain(tenantDomain);
|
|
|
|
|
|
|
|
serviceProvider.setOwner(user);
|
|
|
|
|
|
|
|
|
|
|
|
serviceProvider.setDescription("Service Provider for application " + applicationName);
|
|
|
|
serviceProvider.setDescription("Service Provider for application " + applicationName);
|
|
|
|
|
|
|
|
|
|
|
@ -167,7 +162,7 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
|
|
|
|
|
|
|
|
ServiceProvider existingServiceProvider = appMgtService.getApplication(applicationName);
|
|
|
|
ServiceProvider existingServiceProvider = appMgtService.getApplication(applicationName);
|
|
|
|
|
|
|
|
|
|
|
|
if(existingServiceProvider == null) {
|
|
|
|
if (existingServiceProvider == null) {
|
|
|
|
appMgtService.createApplication(serviceProvider);
|
|
|
|
appMgtService.createApplication(serviceProvider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -181,16 +176,16 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
// Then Create OAuthApp
|
|
|
|
// Then Create OAuthApp
|
|
|
|
OAuthAdminService oAuthAdminService = new OAuthAdminService();
|
|
|
|
OAuthAdminService oAuthAdminService = new OAuthAdminService();
|
|
|
|
|
|
|
|
|
|
|
|
OAuthConsumerAppDTO oAuthConsumerAppDTO = new OAuthConsumerAppDTO();
|
|
|
|
OAuthConsumerAppDTO oAuthConsumerApp = new OAuthConsumerAppDTO();
|
|
|
|
oAuthConsumerAppDTO.setApplicationName(applicationName);
|
|
|
|
oAuthConsumerApp.setApplicationName(applicationName);
|
|
|
|
oAuthConsumerAppDTO.setCallbackUrl(callbackUrl);
|
|
|
|
oAuthConsumerApp.setCallbackUrl(callbackUrl);
|
|
|
|
oAuthConsumerAppDTO.setGrantTypes(grantType);
|
|
|
|
oAuthConsumerApp.setGrantTypes(grantType);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Creating OAuth App " + applicationName);
|
|
|
|
log.debug("Creating OAuth App " + applicationName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(existingServiceProvider == null) {
|
|
|
|
if (existingServiceProvider == null) {
|
|
|
|
oAuthAdminService.registerOAuthApplicationData(oAuthConsumerAppDTO);
|
|
|
|
oAuthAdminService.registerOAuthApplicationData(oAuthConsumerApp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
@ -198,8 +193,7 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OAuthConsumerAppDTO createdApp =
|
|
|
|
OAuthConsumerAppDTO createdApp =
|
|
|
|
oAuthAdminService.getOAuthApplicationDataByAppName(oAuthConsumerAppDTO
|
|
|
|
oAuthAdminService.getOAuthApplicationDataByAppName(oAuthConsumerApp.getApplicationName());
|
|
|
|
.getApplicationName());
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Retrieved Details for OAuth App " + createdApp.getApplicationName());
|
|
|
|
log.debug("Retrieved Details for OAuth App " + createdApp.getApplicationName());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -219,7 +213,7 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
Property property = new Property();
|
|
|
|
Property property = new Property();
|
|
|
|
property.setName("oauthConsumerSecret");
|
|
|
|
property.setName("oauthConsumerSecret");
|
|
|
|
property.setValue(createdApp.getOauthConsumerSecret());
|
|
|
|
property.setValue(createdApp.getOauthConsumerSecret());
|
|
|
|
Property[] properties = { property };
|
|
|
|
Property[] properties = {property};
|
|
|
|
inboundAuthenticationRequestConfig.setProperties(properties);
|
|
|
|
inboundAuthenticationRequestConfig.setProperties(properties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -289,14 +283,17 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected Registry getConfigSystemRegistry() {
|
|
|
|
protected Registry getConfigSystemRegistry() {
|
|
|
|
return (Registry)PrivilegedCarbonContext.getThreadLocalCarbonContext().
|
|
|
|
return (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
|
|
|
|
getRegistry(RegistryType.SYSTEM_CONFIGURATION);
|
|
|
|
getRegistry(RegistryType.SYSTEM_CONFIGURATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean unregisterOAuthApplication(String userId, String applicationName,
|
|
|
|
public boolean unregisterOAuthApplication(String userId, String applicationName,
|
|
|
|
String consumerKey)
|
|
|
|
String consumerKey) throws DynamicClientRegistrationException {
|
|
|
|
throws DynamicClientRegistrationException {
|
|
|
|
DynamicClientRegistrationUtil.validateUsername(userId);
|
|
|
|
|
|
|
|
DynamicClientRegistrationUtil.validateApplicationName(applicationName);
|
|
|
|
|
|
|
|
DynamicClientRegistrationUtil.validateConsumerKey(consumerKey);
|
|
|
|
|
|
|
|
|
|
|
|
boolean status = false;
|
|
|
|
boolean status = false;
|
|
|
|
String tenantDomain = MultitenantUtils.getTenantDomain(userId);
|
|
|
|
String tenantDomain = MultitenantUtils.getTenantDomain(userId);
|
|
|
|
String baseUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String baseUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
@ -306,21 +303,23 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName);
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName);
|
|
|
|
|
|
|
|
|
|
|
|
if (userId == null || userId.isEmpty()) {
|
|
|
|
OAuthAdminService oAuthAdminService;
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
OAuthConsumerAppDTO oAuthConsumerApp;
|
|
|
|
"Error occurred while unregistering Application: userId cannot " +
|
|
|
|
|
|
|
|
"be null/empty");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
OAuthAdminService oAuthAdminService = new OAuthAdminService();
|
|
|
|
oAuthAdminService = new OAuthAdminService();
|
|
|
|
OAuthConsumerAppDTO oAuthConsumerAppDTO =
|
|
|
|
oAuthConsumerApp = oAuthAdminService.getOAuthApplicationData(consumerKey);
|
|
|
|
oAuthAdminService.getOAuthApplicationData(consumerKey);
|
|
|
|
} catch (IdentityOAuthAdminException e) {
|
|
|
|
|
|
|
|
throw new DynamicClientRegistrationException("Error occurred while retrieving application data", e);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw new DynamicClientRegistrationException("Error occurred while retrieving application data", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (oAuthConsumerAppDTO == null) {
|
|
|
|
if (oAuthConsumerApp == null) {
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
"Couldn't retrieve OAuth Consumer Application associated with the " +
|
|
|
|
"No OAuth Consumer Application is associated with the given consumer key: " + consumerKey);
|
|
|
|
"given consumer key: " + consumerKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
oAuthAdminService.removeOAuthApplicationData(consumerKey);
|
|
|
|
oAuthAdminService.removeOAuthApplicationData(consumerKey);
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
|
|
|
|
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
|
|
|
@ -331,7 +330,6 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
"Service");
|
|
|
|
"Service");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName);
|
|
|
|
ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName);
|
|
|
|
|
|
|
|
|
|
|
|
if (createdServiceProvider == null) {
|
|
|
|
if (createdServiceProvider == null) {
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
"Couldn't retrieve Service Provider Application " + applicationName);
|
|
|
|
"Couldn't retrieve Service Provider Application " + applicationName);
|
|
|
@ -340,10 +338,13 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
status = true;
|
|
|
|
status = true;
|
|
|
|
} catch (IdentityApplicationManagementException e) {
|
|
|
|
} catch (IdentityApplicationManagementException e) {
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
"Error occurred while removing ServiceProvider for app " + applicationName, e);
|
|
|
|
"Error occurred while removing ServiceProvider for application '" + applicationName + "'", e);
|
|
|
|
|
|
|
|
} catch (IdentityOAuthAdminException e) {
|
|
|
|
|
|
|
|
throw new DynamicClientRegistrationException("Error occurred while removing application '" +
|
|
|
|
|
|
|
|
applicationName + "'", e);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
throw new DynamicClientRegistrationException("Error occurred while removing application '" +
|
|
|
|
"Error occurred while removing OAuthApp " + applicationName, e);
|
|
|
|
applicationName + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(baseUser);
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(baseUser);
|
|
|
@ -352,8 +353,7 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isOAuthApplicationExists(String applicationName)
|
|
|
|
public boolean isOAuthApplicationExists(String applicationName) throws DynamicClientRegistrationException {
|
|
|
|
throws DynamicClientRegistrationException {
|
|
|
|
|
|
|
|
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
|
|
|
|
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
|
|
|
|
if (appMgtService == null) {
|
|
|
|
if (appMgtService == null) {
|
|
|
|
throw new IllegalStateException(
|
|
|
|
throw new IllegalStateException(
|
|
|
@ -361,14 +361,14 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
|
|
|
"Service");
|
|
|
|
"Service");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (appMgtService.getApplication(applicationName) != null) {
|
|
|
|
if (ApplicationManagementService.getInstance().getApplication(applicationName) != null) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IdentityApplicationManagementException e) {
|
|
|
|
} catch (IdentityApplicationManagementException e) {
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
throw new DynamicClientRegistrationException(
|
|
|
|
"Error occurred while retrieving information of OAuthApp " + applicationName,
|
|
|
|
"Error occurred while retrieving information of OAuthApp " + applicationName, e);
|
|
|
|
e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|