From 234cd47931c62d5f8b4158404561bf4d29501073 Mon Sep 17 00:00:00 2001 From: harshanl Date: Fri, 2 Oct 2015 18:00:05 +0530 Subject: [PATCH 1/7] Added identity-extensions --- .../core/config/permission/Permission.java | 10 +++ .../repository/conf/axis2/axis2.xml | 10 +-- .../repository/conf/tomcat/web.xml | 4 +- .../dynamic-client-web/pom.xml | 0 .../client/web/ConfigurationService.java | 0 .../dynamic/client/web/DynamicClientUtil.java | 0 .../client/web/FaultMessageBodyWriter.java | 0 .../dynamic/client/web/FaultResponse.java | 0 .../client/web/RegistrationResponse.java | 0 .../client/web/RegistrationService.java | 0 .../web/impl/ConfigurationServiceImpl.java | 0 .../web/impl/RegistrationServiceImpl.java | 0 .../webapp/META-INF/webapp-classloading.xml | 0 .../src/main/webapp/WEB-INF/cxf-servlet.xml | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/main/webapp/servicelist.css | 0 .../src/test/resources/log4j.properties | 0 .../src/test/resources/testng.xml | 0 .../pom.xml | 0 .../registration/ApplicationConstants.java | 0 .../DynamicClientRegistrationException.java | 0 .../DynamicClientRegistrationService.java | 0 .../registration/OAuthApplicationInfo.java | 0 .../impl/DynamicClientRegistrationImpl.java | 0 ...amicClientRegistrationBundleActivator.java | 4 + .../profile/RegistrationProfile.java | 0 .../pom.xml | 0 .../DynamicRegistrationManager.java | 0 .../client/web/app/registration/OAuthApp.java | 0 .../web/app/registration/OAuthSettings.java | 0 .../DynamicClientRegistrationDataHolder.java | 0 ...entWebAppRegistrationServiceComponent.java | 0 ...ientWebAppDeploymentLifecycleListener.java | 0 .../DynamicClientRegistrationConstants.java | 0 .../DynamicClientWebAppRegistrationUtil.java | 0 .../dynamic-client-registration/pom.xml | 28 +----- .../pom.xml | 79 +++++++++++++++++ .../extensions/OAuthExtensionsUtils.java | 63 ++++++++++++++ .../DeviceMgtOAuthCallbackHandler.java | 62 +++++++++++++ .../OAuthExtensionServiceComponent.java | 77 ++++++++++++++++ .../internal/OAuthExtensionsDataHolder.java | 45 ++++++++++ .../validators/OAuth2TokenValidator.java | 36 ++++++++ .../extensions/validators/ScopeValidator.java | 36 ++++++++ components/identity-extensions/pom.xml | 42 +++++++++ .../repository/conf/axis2/axis2.xml | 10 +-- .../repository/conf/tomcat/web.xml | 4 +- .../pom.xml | 87 +++++++++++++++++++ features/oauth-extensions/pom.xml | 41 +++++++++ pom.xml | 28 ++++-- 49 files changed, 621 insertions(+), 45 deletions(-) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/pom.xml (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/ConfigurationService.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/DynamicClientUtil.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultMessageBodyWriter.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultResponse.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/webapp/META-INF/webapp-classloading.xml (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/cxf-servlet.xml (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/main/webapp/servicelist.css (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/test/resources/log4j.properties (100%) rename components/{ => identity-extensions}/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationException.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationService.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java (89%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthApp.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthSettings.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java (100%) rename components/{ => identity-extensions}/dynamic-client-registration/pom.xml (64%) create mode 100644 components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml create mode 100644 components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/OAuthExtensionsUtils.java create mode 100644 components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/DeviceMgtOAuthCallbackHandler.java create mode 100644 components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionServiceComponent.java create mode 100644 components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionsDataHolder.java create mode 100644 components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/OAuth2TokenValidator.java create mode 100644 components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java create mode 100644 components/identity-extensions/pom.xml create mode 100644 features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml create mode 100644 features/oauth-extensions/pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/Permission.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/Permission.java index 76810771b8..ca5f79caf1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/Permission.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/Permission.java @@ -26,6 +26,16 @@ public class Permission{ private String name; private String path; + private String scope; + + public String getScope() { + return scope; + } + + @XmlElement(name = "scope", required = true) + public void setScope(String scope) { + this.scope = scope; + } public String getName() { return name; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml index a6c5a03057..0f0822fa02 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml @@ -114,19 +114,19 @@ ${jaxwsparam} - + - + - + - + - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml index 33e1518b67..d4241ef741 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml @@ -481,7 +481,7 @@ - + @@ -1003,7 +1003,7 @@ diff --git a/components/dynamic-client-registration/dynamic-client-web/pom.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/pom.xml similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/pom.xml rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/pom.xml diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/ConfigurationService.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/ConfigurationService.java similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/ConfigurationService.java rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/ConfigurationService.java diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/DynamicClientUtil.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/DynamicClientUtil.java similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/DynamicClientUtil.java rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/DynamicClientUtil.java diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultMessageBodyWriter.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultMessageBodyWriter.java similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultMessageBodyWriter.java rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultMessageBodyWriter.java diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultResponse.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultResponse.java similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultResponse.java rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultResponse.java diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/webapp/META-INF/webapp-classloading.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/META-INF/webapp-classloading.xml similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/webapp/META-INF/webapp-classloading.xml rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/META-INF/webapp-classloading.xml diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/cxf-servlet.xml similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/cxf-servlet.xml rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/cxf-servlet.xml diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/webapp/servicelist.css b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/servicelist.css similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/main/webapp/servicelist.css rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/servicelist.css diff --git a/components/dynamic-client-registration/dynamic-client-web/src/test/resources/log4j.properties b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/test/resources/log4j.properties similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/test/resources/log4j.properties rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/test/resources/log4j.properties diff --git a/components/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml similarity index 100% rename from components/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml rename to components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationException.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationException.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationException.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationException.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationService.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationService.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationService.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationService.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java similarity index 89% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java index e3ae13e4df..a5ba8ecb2b 100644 --- a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java @@ -18,6 +18,8 @@ package org.wso2.carbon.dynamic.client.registration.internal; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService; @@ -28,6 +30,8 @@ import org.wso2.carbon.dynamic.client.registration.impl.DynamicClientRegistratio */ public class DynamicClientRegistrationBundleActivator implements BundleActivator{ + private static final Log log = LogFactory.getLog(DynamicClientRegistrationBundleActivator.class); + @Override public void start(BundleContext bundleContext) throws Exception { DynamicClientRegistrationService dynamicClientRegistrationService = diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthApp.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthApp.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthApp.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthApp.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthSettings.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthSettings.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthSettings.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthSettings.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java similarity index 100% rename from components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java diff --git a/components/dynamic-client-registration/pom.xml b/components/identity-extensions/dynamic-client-registration/pom.xml similarity index 64% rename from components/dynamic-client-registration/pom.xml rename to components/identity-extensions/dynamic-client-registration/pom.xml index 95cd219a42..e568ea5e88 100644 --- a/components/dynamic-client-registration/pom.xml +++ b/components/identity-extensions/dynamic-client-registration/pom.xml @@ -21,9 +21,9 @@ org.wso2.carbon.devicemgt - carbon-devicemgt + identity-extensions 0.9.2-SNAPSHOT - ../../pom.xml + ../pom.xml 4.0.0 @@ -31,32 +31,12 @@ dynamic-client-registration 0.9.2-SNAPSHOT pom - WSO2 Carbon - Dynamic Client Registration Component + WSO2 Carbon - Dynamic client registration http://wso2.org + dynamic-client-web org.wso2.carbon.dynamic.client.registration org.wso2.carbon.dynamic.client.web.app.registration - dynamic-client-web - - - - - - org.apache.felix - maven-scr-plugin - 1.7.2 - - - generate-scr-scrdescriptor - - scr - - - - - - - diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml new file mode 100644 index 0000000000..0e663bf144 --- /dev/null +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml @@ -0,0 +1,79 @@ + + + + + + + org.wso2.carbon.devicemgt + identity-extensions + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.oauth.extensions + 0.9.2-SNAPSHOT + bundle + WSO2 Carbon - OAuth Extensions + http://wso2.org + + + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth + + + org.wso2.carbon + org.wso2.carbon.user.core + + + org.wso2.carbon + org.wso2.carbon.user.api + + + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + OAuth Extensions Bundle + org.wso2.carbon.device.mgt.oauth.extensions.internal + + !org.wso2.carbon.device.mgt.oauth.extensions.internal, + org.wso2.carbon.device.mgt.oauth.extensions.* + + * + + + + + + diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/OAuthExtensionsUtils.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/OAuthExtensionsUtils.java new file mode 100644 index 0000000000..2356a6affa --- /dev/null +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/OAuthExtensionsUtils.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.oauth.extensions; + +import org.wso2.carbon.device.mgt.oauth.extensions.internal.OAuthExtensionsDataHolder; +import org.wso2.carbon.user.api.AuthorizationManager; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.api.UserStoreManager; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * Created by harshan on 10/2/15. + */ +public class OAuthExtensionsUtils { + + public static void getRolePermissions(String role){ + RealmService realmService = OAuthExtensionsDataHolder.getInstance().getRealmService(); + try { + int tenantId = realmService.getTenantManager().getTenantId("tenant-domain"); + AuthorizationManager + authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager(); + // authorizationManager.is + } catch (UserStoreException e) { + e.printStackTrace(); + } + } + + public static void getUserPermissions(String userName){ + + } + + public static String[] getUserRoles(String userName){ + RealmService realmService = OAuthExtensionsDataHolder.getInstance().getRealmService(); + try { + int tenantId = realmService.getTenantManager().getTenantId("tenant-domain"); + UserStoreManager userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager(); + return userStoreManager.getRoleListOfUser(userName); + } catch (UserStoreException e) { + e.printStackTrace(); + } + return new String[0]; + } + + public static void getScopePermissions(String scopeKey){ + + } +} diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/DeviceMgtOAuthCallbackHandler.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/DeviceMgtOAuthCallbackHandler.java new file mode 100644 index 0000000000..b8dcd71927 --- /dev/null +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/DeviceMgtOAuthCallbackHandler.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.oauth.extensions.handlers; + +import org.wso2.carbon.identity.oauth.callback.AbstractOAuthCallbackHandler; +import org.wso2.carbon.identity.oauth.callback.OAuthCallback; +import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.UnsupportedCallbackException; +import java.io.IOException; + +/** + * Created by harshan on 10/1/15. + */ +public class DeviceMgtOAuthCallbackHandler extends AbstractOAuthCallbackHandler { + + @Override + public boolean canHandle(Callback[] callbacks) throws IdentityOAuth2Exception { + return true; + } + + @Override + public void handle(Callback[] callbacks) + throws IOException, UnsupportedCallbackException { + if (callbacks != null && callbacks.length > 0){ + OAuthCallback oauthCallback = (OAuthCallback) callbacks[0]; + if (OAuthCallback.OAuthCallbackType.ACCESS_DELEGATION_AUTHZ.equals( + oauthCallback.getCallbackType())){ + oauthCallback.setAuthorized(true); + } else if (OAuthCallback.OAuthCallbackType.ACCESS_DELEGATION_TOKEN.equals( + oauthCallback.getCallbackType())){ + oauthCallback.setAuthorized(true); + } else if (OAuthCallback.OAuthCallbackType.SCOPE_VALIDATION_AUTHZ.equals( + oauthCallback.getCallbackType())){ + oauthCallback.setValidScope(true); + } else if (OAuthCallback.OAuthCallbackType.SCOPE_VALIDATION_TOKEN.equals( + oauthCallback.getCallbackType())){ + String[] scopes = oauthCallback.getRequestedScope(); + oauthCallback.setApprovedScope(scopes); + oauthCallback.setValidScope(true); + } + } + + } +} diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionServiceComponent.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionServiceComponent.java new file mode 100644 index 0000000000..9f13ec4ef3 --- /dev/null +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionServiceComponent.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.oauth.extensions.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * @scr.component name="org.wso2.carbon.device.mgt.oauth.extensions" immediate="true" + * @scr.reference name="user.realmservice.default" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + */ +public class OAuthExtensionServiceComponent { + + private static final Log log = LogFactory.getLog(OAuthExtensionServiceComponent.class); + + @SuppressWarnings("unused") + protected void activate(ComponentContext componentContext) { + if(log.isDebugEnabled()){ + log.debug("Starting OAuthExtensionBundle"); + } + } + + @SuppressWarnings("unused") + protected void deactivate(ComponentContext componentContext) { + if(log.isDebugEnabled()){ + log.debug("Stopping OAuthExtensionBundle"); + } + } + + /** + * Sets Realm Service. + * + * @param realmService An instance of RealmService + */ + protected void setRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Setting Realm Service"); + } + OAuthExtensionsDataHolder.getInstance().setRealmService(realmService); + } + + /** + * Unsets Realm Service. + * + * @param realmService An instance of RealmService + */ + protected void unsetRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Realm Service"); + } + OAuthExtensionsDataHolder.getInstance().setRealmService(null); + } + +} diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionsDataHolder.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionsDataHolder.java new file mode 100644 index 0000000000..b0eed80a3f --- /dev/null +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionsDataHolder.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.oauth.extensions.internal; + +import org.wso2.carbon.user.core.service.RealmService; + +/** + * Created by harshan on 10/2/15. + */ +public class OAuthExtensionsDataHolder { + + private RealmService realmService; + + private static OAuthExtensionsDataHolder thisInstance = new OAuthExtensionsDataHolder(); + + private OAuthExtensionsDataHolder() {} + + public static OAuthExtensionsDataHolder getInstance() { + return thisInstance; + } + + public RealmService getRealmService() { + return realmService; + } + + public void setRealmService(RealmService realmService) { + this.realmService = realmService; + } +} diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/OAuth2TokenValidator.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/OAuth2TokenValidator.java new file mode 100644 index 0000000000..d5393a59d0 --- /dev/null +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/OAuth2TokenValidator.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.oauth.extensions.validators; + +import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; +import org.wso2.carbon.identity.oauth2.validators.DefaultOAuth2TokenValidator; +import org.wso2.carbon.identity.oauth2.validators.OAuth2TokenValidationMessageContext; + +/** + * OAuth2 Token validator implementation which supports custom token validation logic specific + * to MDM. + */ +public class OAuth2TokenValidator extends DefaultOAuth2TokenValidator { + + @Override + public boolean validateAccessToken( + OAuth2TokenValidationMessageContext validationReqDTO) throws IdentityOAuth2Exception { + return true; + } +} diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java new file mode 100644 index 0000000000..5fc0da4af1 --- /dev/null +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.oauth.extensions.validators; + +import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; +import org.wso2.carbon.identity.oauth2.model.AccessTokenDO; +import org.wso2.carbon.identity.oauth2.validators.OAuth2ScopeValidator; + +/** + * Created by harshan on 10/1/15. + */ +public class ScopeValidator extends OAuth2ScopeValidator { + + @Override + public boolean validateScope(AccessTokenDO accessTokenDO, String resource) + throws IdentityOAuth2Exception { + //Call Milan's permission logic + return true; + } +} diff --git a/components/identity-extensions/pom.xml b/components/identity-extensions/pom.xml new file mode 100644 index 0000000000..78a24d9adb --- /dev/null +++ b/components/identity-extensions/pom.xml @@ -0,0 +1,42 @@ + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 0.9.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + org.wso2.carbon.devicemgt + identity-extensions + 0.9.2-SNAPSHOT + pom + WSO2 Carbon - Dynamic Client Registration Component + http://wso2.org + + + org.wso2.carbon.device.mgt.oauth.extensions + dynamic-client-registration + + + diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml index a6c5a03057..0f0822fa02 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml @@ -114,19 +114,19 @@ ${jaxwsparam} - + - + - + - + - + diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml index 33e1518b67..d4241ef741 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml @@ -481,7 +481,7 @@ - + @@ -1003,7 +1003,7 @@ diff --git a/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml b/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml new file mode 100644 index 0000000000..b75edcb2d3 --- /dev/null +++ b/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml @@ -0,0 +1,87 @@ + + + + + + + + org.wso2.carbon.devicemgt + oauth-extensions-feature + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.oauth.extensions.feature + pom + 0.9.2-SNAPSHOT + WSO2 Carbon - Device Mgt OAuth Extensions Feature + http://wso2.org + This feature contains devicemgt related OAuth extensions + + + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.oauth.extensions + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + org.wso2.carbon.device.mgt.oauth.extensions + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.oauth.extensions:${carbon.device.mgt.version} + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + + + + + + + + + diff --git a/features/oauth-extensions/pom.xml b/features/oauth-extensions/pom.xml new file mode 100644 index 0000000000..cca949ed19 --- /dev/null +++ b/features/oauth-extensions/pom.xml @@ -0,0 +1,41 @@ + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 0.9.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + org.wso2.carbon.devicemgt + oauth-extensions-feature + 0.9.2-SNAPSHOT + pom + WSO2 Carbon Device Management - OAuth Extensions Feature + http://wso2.org + + + org.wso2.carbon.device.mgt.oauth.extensions.feature + + + diff --git a/pom.xml b/pom.xml index ce2f4a193f..835faf5c47 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,8 @@ ~ under the License. --> - 4.0.0 @@ -37,17 +38,18 @@ components/device-mgt - components/apimgt-extensions + components/apimgt-extensions components/policy-mgt components/certificate-mgt components/webapp-authenticator-framework - components/dynamic-client-registration + components/identity-extensions features/device-mgt features/apimgt-extensions - features/policy-mgt + features/policy-mgt features/webapp-authenticator-framework features/certificate-mgt features/dynamic-client-registration + features/oauth-extensions @@ -185,6 +187,17 @@ dynamic-client-web ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.oauth.extensions + ${carbon.device.mgt.version} + + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth + + + @@ -370,8 +383,8 @@ bcprov-jdk15on - - + + org.wso2.carbon @@ -1006,7 +1019,8 @@ https://github.com/wso2/carbon-device-mgt.git - scm:git:https://github.com/wso2/carbon-device-mgt.git + scm:git:https://github.com/wso2/carbon-device-mgt.git + scm:git:https://github.com/wso2/carbon-device-mgt.git HEAD From 77f5f466d654fdf9ee1ca8160d1be7363f6504d7 Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 6 Oct 2015 11:44:40 +0530 Subject: [PATCH 2/7] Added scope validator and refactored code --- .../mgt/common/permission/mgt/Permission.java | 2 +- .../mgt/PermissionManagementException.java | 3 + .../WebAppDeploymentLifecycleListener.java | 8 ++- .../DeviceManagementServiceComponent.java | 4 +- ...java => PermissionManagerServiceImpl.java} | 12 ++-- .../core/permission/mgt/PermissionUtils.java | 32 +++++++--- .../DynamicRegistrationManager.java | 4 +- .../extensions/OAuthExtensionsUtils.java | 63 ------------------- .../DeviceMgtOAuthCallbackHandler.java | 5 +- .../internal/OAuthExtensionsDataHolder.java | 2 +- .../validators/OAuth2TokenValidator.java | 37 ----------- .../extensions/validators/ScopeValidator.java | 9 ++- .../authenticator/OAuthAuthenticator.java | 3 + .../authorizer/PermissionAuthorizer.java | 5 +- 14 files changed, 62 insertions(+), 127 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/{RegistryBasedPermissionManagerServiceImpl.java => PermissionManagerServiceImpl.java} (83%) delete mode 100644 components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/OAuthExtensionsUtils.java delete mode 100644 components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/OAuth2TokenValidator.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/permission/mgt/Permission.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/permission/mgt/Permission.java index 719633825a..ad92cb27d8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/permission/mgt/Permission.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/permission/mgt/Permission.java @@ -55,7 +55,7 @@ public class Permission { return scope; } - @XmlElement(name = "scope", required = true) + @XmlElement(name = "scope", required = false) public void setScope(String scope) { this.scope = scope; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/permission/mgt/PermissionManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/permission/mgt/PermissionManagementException.java index 351efcaffb..5c0abce988 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/permission/mgt/PermissionManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/permission/mgt/PermissionManagementException.java @@ -17,6 +17,9 @@ */ package org.wso2.carbon.device.mgt.common.permission.mgt; +/** + * Custom exception class of Permission related operations. + */ public class PermissionManagementException extends Exception { private static final long serialVersionUID = -3151279311929070298L; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/lifecycle/WebAppDeploymentLifecycleListener.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/lifecycle/WebAppDeploymentLifecycleListener.java index f5a11bcdfd..557ce64859 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/lifecycle/WebAppDeploymentLifecycleListener.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/lifecycle/WebAppDeploymentLifecycleListener.java @@ -26,7 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException; import org.wso2.carbon.device.mgt.core.config.permission.PermissionConfiguration; -import org.wso2.carbon.device.mgt.core.permission.mgt.RegistryBasedPermissionManagerServiceImpl; +import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceImpl; import javax.servlet.ServletContext; import javax.xml.bind.JAXBContext; @@ -35,6 +35,10 @@ import javax.xml.bind.Unmarshaller; import java.io.File; import java.io.InputStream; +/** + * This listener class will initiate the permission addition of permissions defined in + * permission.xml of any web-app. + */ @SuppressWarnings("unused") public class WebAppDeploymentLifecycleListener implements LifecycleListener { @@ -56,7 +60,7 @@ public class WebAppDeploymentLifecycleListener implements LifecycleListener { unmarshaller.unmarshal(permissionStream); if (permissionConfiguration != null && permissionConfiguration.getPermissions() != null) { - RegistryBasedPermissionManagerServiceImpl.getInstance().addPermissions( + PermissionManagerServiceImpl.getInstance().addPermissions( permissionConfiguration.getPermissions()); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index bca5e6b345..ff5723cc22 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -45,7 +45,7 @@ import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementSe import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; -import org.wso2.carbon.device.mgt.core.permission.mgt.RegistryBasedPermissionManagerServiceImpl; +import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; @@ -191,7 +191,7 @@ public class DeviceManagementServiceComponent { /* Registering PermissionManager Service */ PermissionManagerService permissionManagerService - = RegistryBasedPermissionManagerServiceImpl.getInstance(); + = PermissionManagerServiceImpl.getInstance(); bundleContext.registerService(PermissionManagerService.class.getName(), permissionManagerService, null); /* Registering App Management service */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/RegistryBasedPermissionManagerServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceImpl.java similarity index 83% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/RegistryBasedPermissionManagerServiceImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceImpl.java index b4131be177..5ea3a09e84 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/RegistryBasedPermissionManagerServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceImpl.java @@ -29,21 +29,21 @@ import java.util.Properties; * This class will add, update custom permissions defined in permission.xml in webapps and it will * use Registry as the persistence storage. */ -public class RegistryBasedPermissionManagerServiceImpl implements PermissionManagerService { +public class PermissionManagerServiceImpl implements PermissionManagerService { public static final String URL_PROPERTY = "URL"; public static final String HTTP_METHOD_PROPERTY = "HTTP_METHOD"; - private static RegistryBasedPermissionManagerServiceImpl registryBasedPermissionManager; + private static PermissionManagerServiceImpl registryBasedPermissionManager; private static PermissionTree permissionTree; // holds the permissions at runtime. - private RegistryBasedPermissionManagerServiceImpl() { + private PermissionManagerServiceImpl() { } - public static RegistryBasedPermissionManagerServiceImpl getInstance() { + public static PermissionManagerServiceImpl getInstance() { if (registryBasedPermissionManager == null) { - synchronized (RegistryBasedPermissionManagerServiceImpl.class) { + synchronized (PermissionManagerServiceImpl.class) { if (registryBasedPermissionManager == null) { - registryBasedPermissionManager = new RegistryBasedPermissionManagerServiceImpl(); + registryBasedPermissionManager = new PermissionManagerServiceImpl(); permissionTree = new PermissionTree(); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionUtils.java index 03ba2bd90e..35733cd7ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionUtils.java @@ -31,6 +31,7 @@ import org.wso2.carbon.registry.core.Registry; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; +import java.util.StringTokenizer; /** * Utility class which holds necessary utility methods required for persisting permissions in @@ -71,12 +72,16 @@ public class PermissionUtils { throws PermissionManagementException { boolean status; try { - Resource resource = PermissionUtils.getGovernanceRegistry().newCollection(); - resource.addProperty(PERMISSION_PROPERTY_NAME, permission.getName()); - PermissionUtils.getGovernanceRegistry().beginTransaction(); - PermissionUtils.getGovernanceRegistry().put(ADMIN_PERMISSION_REGISTRY_PATH + - permission.getPath(), resource); - PermissionUtils.getGovernanceRegistry().commitTransaction(); + StringTokenizer tokenizer = new StringTokenizer(permission.getPath(), "/"); + String lastToken = "", currentToken, tempPath; + while(tokenizer.hasMoreTokens()){ + currentToken = tokenizer.nextToken(); + tempPath = lastToken + "/" + currentToken; + if(!checkResourceExists(tempPath)){ + createRegistryCollection(tempPath, currentToken.substring(0)); + } + lastToken = tempPath; + } status = true; } catch (RegistryException e) { throw new PermissionManagementException( @@ -86,10 +91,21 @@ public class PermissionUtils { return status; } - public static boolean checkPermissionExistence(Permission permission) + public static void createRegistryCollection(String path, String resourceName) + throws PermissionManagementException, + RegistryException { + Resource resource = PermissionUtils.getGovernanceRegistry().newCollection(); + resource.addProperty(PERMISSION_PROPERTY_NAME, resourceName); + PermissionUtils.getGovernanceRegistry().beginTransaction(); + PermissionUtils.getGovernanceRegistry().put(ADMIN_PERMISSION_REGISTRY_PATH + + path, resource); + PermissionUtils.getGovernanceRegistry().commitTransaction(); + } + + public static boolean checkResourceExists(String path) throws PermissionManagementException, org.wso2.carbon.registry.core.exceptions.RegistryException { - return PermissionUtils.getGovernanceRegistry().resourceExists(permission.getPath()); + return PermissionUtils.getGovernanceRegistry().resourceExists(path); } public static Document convertToDocument(File file) throws PermissionManagementException { diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java index a279387332..bef3b10ae8 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java @@ -123,8 +123,8 @@ public class DynamicRegistrationManager { //Check whether this is an already registered application if (!dynamicRegistrationManager.isRegisteredOAuthApplication(webAppName)) { //Construct the RegistrationProfile - registrationProfile = DynamicClientWebAppRegistrationUtil - .constructRegistrationProfile(servletContext, webAppName); + registrationProfile = DynamicClientWebAppRegistrationUtil. + constructRegistrationProfile(servletContext, webAppName); //Register the OAuth application oAuthApp = dynamicRegistrationManager.registerOAuthApplication( registrationProfile); diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/OAuthExtensionsUtils.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/OAuthExtensionsUtils.java deleted file mode 100644 index 2356a6affa..0000000000 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/OAuthExtensionsUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.oauth.extensions; - -import org.wso2.carbon.device.mgt.oauth.extensions.internal.OAuthExtensionsDataHolder; -import org.wso2.carbon.user.api.AuthorizationManager; -import org.wso2.carbon.user.api.UserStoreException; -import org.wso2.carbon.user.api.UserStoreManager; -import org.wso2.carbon.user.core.service.RealmService; - -/** - * Created by harshan on 10/2/15. - */ -public class OAuthExtensionsUtils { - - public static void getRolePermissions(String role){ - RealmService realmService = OAuthExtensionsDataHolder.getInstance().getRealmService(); - try { - int tenantId = realmService.getTenantManager().getTenantId("tenant-domain"); - AuthorizationManager - authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager(); - // authorizationManager.is - } catch (UserStoreException e) { - e.printStackTrace(); - } - } - - public static void getUserPermissions(String userName){ - - } - - public static String[] getUserRoles(String userName){ - RealmService realmService = OAuthExtensionsDataHolder.getInstance().getRealmService(); - try { - int tenantId = realmService.getTenantManager().getTenantId("tenant-domain"); - UserStoreManager userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager(); - return userStoreManager.getRoleListOfUser(userName); - } catch (UserStoreException e) { - e.printStackTrace(); - } - return new String[0]; - } - - public static void getScopePermissions(String scopeKey){ - - } -} diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/DeviceMgtOAuthCallbackHandler.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/DeviceMgtOAuthCallbackHandler.java index 0a785b1c5b..e621ee4a8b 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/DeviceMgtOAuthCallbackHandler.java +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/DeviceMgtOAuthCallbackHandler.java @@ -27,7 +27,8 @@ import javax.security.auth.callback.UnsupportedCallbackException; import java.io.IOException; /** - * Created by harshan on 10/1/15. + * This class represents a Custom OAuthCallback Handler implementation. This should be implemented + * if there's any necessity of custom logic to authorize OAuthCallbacks. */ public class DeviceMgtOAuthCallbackHandler extends AbstractOAuthCallbackHandler { @@ -55,7 +56,7 @@ public class DeviceMgtOAuthCallbackHandler extends AbstractOAuthCallbackHandler String[] scopes = oauthCallback.getRequestedScope(); oauthCallback.setApprovedScope(scopes); oauthCallback.setValidScope(true); - //TODO Need to write the necessary logic to validate the scope + //Add the necessary logic if we are doing the scope validation upon token issue } } diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionsDataHolder.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionsDataHolder.java index 568dea8a13..f87ac765d3 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionsDataHolder.java +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/internal/OAuthExtensionsDataHolder.java @@ -23,7 +23,7 @@ import org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService; import org.wso2.carbon.user.core.service.RealmService; /** - * Created by harshan on 10/2/15. + * This holds the OSGi service references required for oauth extensions bundle. */ public class OAuthExtensionsDataHolder { diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/OAuth2TokenValidator.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/OAuth2TokenValidator.java deleted file mode 100644 index af4e857eab..0000000000 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/OAuth2TokenValidator.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.oauth.extensions.validators; - -import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; -import org.wso2.carbon.identity.oauth2.validators.DefaultOAuth2TokenValidator; -import org.wso2.carbon.identity.oauth2.validators.OAuth2TokenValidationMessageContext; - -/** - * OAuth2 Token validator implementation which supports custom token validation logic specific - * to MDM. - */ -public class OAuth2TokenValidator extends DefaultOAuth2TokenValidator { - - @Override - public boolean validateAccessToken( - OAuth2TokenValidationMessageContext validationReqDTO) throws IdentityOAuth2Exception { - //for now there's no specific logic to handle in token validation - return true; - } -} diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java index b8be09e6b7..ed68a04a55 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java @@ -28,12 +28,14 @@ import org.wso2.carbon.device.mgt.oauth.extensions.internal.OAuthExtensionsDataH import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; import org.wso2.carbon.identity.oauth2.model.AccessTokenDO; import org.wso2.carbon.identity.oauth2.validators.OAuth2ScopeValidator; +import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; import java.util.Properties; /** - * Custom OAuth2Token Scope validation implementation. + * Custom OAuth2Token Scope validation implementation for DeviceManagement. This will validate the + * user permissions before dispatching the HTTP request to the actual endpoint. */ public class ScopeValidator extends OAuth2ScopeValidator { @@ -72,6 +74,11 @@ public class ScopeValidator extends OAuth2ScopeValidator { status = CarbonContext.getThreadLocalCarbonContext().getUserRealm(). getAuthorizationManager().isUserAuthorized(username, permission.getPath(), ScopeValidator.PermissionMethod.READ); + UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm(); + if(userRealm != null && userRealm.getAuthorizationManager() != null){ + status = userRealm.getAuthorizationManager().isUserAuthorized(username, permission.getPath(), + ScopeValidator.PermissionMethod.READ); + } } catch (PermissionManagementException e) { log.error("Error occurred while validating the resource scope for : " + resource + diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java index a3f70e972b..3fd3027592 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java @@ -30,6 +30,7 @@ import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO; import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO; +import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.webapp.authenticator.framework.AuthenticationException; import org.wso2.carbon.webapp.authenticator.framework.AuthenticationFrameworkUtil; import org.wso2.carbon.webapp.authenticator.framework.Constants; @@ -122,6 +123,8 @@ public class OAuthAuthenticator implements WebappAuthenticator { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId( IdentityUtil.getTenantIdOFUser(username)); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( + MultitenantUtils.getTenantDomain(username)); } catch (IdentityException e) { throw new AuthenticationException( "Error occurred while retrieving the tenant ID of user '" + diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/PermissionAuthorizer.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/PermissionAuthorizer.java index e58f4e0c50..ce4623b4cb 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/PermissionAuthorizer.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/PermissionAuthorizer.java @@ -25,7 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.permission.mgt.Permission; import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException; -import org.wso2.carbon.device.mgt.core.permission.mgt.RegistryBasedPermissionManagerServiceImpl; +import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceImpl; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.webapp.authenticator.framework.Constants; import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; @@ -49,7 +49,8 @@ public class PermissionAuthorizer { return WebappAuthenticator.Status.CONTINUE; } - RegistryBasedPermissionManagerServiceImpl registryBasedPermissionManager = RegistryBasedPermissionManagerServiceImpl.getInstance(); + PermissionManagerServiceImpl + registryBasedPermissionManager = PermissionManagerServiceImpl.getInstance(); Properties properties = new Properties(); properties.put("",requestUri); properties.put("",requestMethod); From f6c65dd48111306b4148e38d30919320bb1ffe80 Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 6 Oct 2015 13:15:40 +0530 Subject: [PATCH 3/7] Refactored dynamic-client registration code --- ...namicClientWebAppRegistrationManager.java} | 46 ++++++++++--------- ...icClientWebAppRegistrationDataHolder.java} | 10 ++-- ...entWebAppRegistrationServiceComponent.java | 16 +++---- ...ientWebAppDeploymentLifecycleListener.java | 4 +- ...micClientWebAppRegistrationConstants.java} | 2 +- .../DynamicClientWebAppRegistrationUtil.java | 22 ++++----- 6 files changed, 52 insertions(+), 48 deletions(-) rename components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/{DynamicRegistrationManager.java => DynamicClientWebAppRegistrationManager.java} (77%) rename components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/{DynamicClientRegistrationDataHolder.java => DynamicClientWebAppRegistrationDataHolder.java} (90%) rename components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/{DynamicClientRegistrationConstants.java => DynamicClientWebAppRegistrationConstants.java} (96%) diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicClientWebAppRegistrationManager.java similarity index 77% rename from components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicClientWebAppRegistrationManager.java index bef3b10ae8..a5f2453f11 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicClientWebAppRegistrationManager.java @@ -25,8 +25,8 @@ import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationExce 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.web.app.registration.internal.DynamicClientRegistrationDataHolder; -import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientRegistrationConstants; +import org.wso2.carbon.dynamic.client.web.app.registration.internal.DynamicClientWebAppRegistrationDataHolder; +import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationConstants; import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil; import javax.servlet.ServletContext; @@ -34,24 +34,24 @@ import javax.servlet.ServletContext; /** * This class contains the logic to handle the OAuth application creation process. */ -public class DynamicRegistrationManager { +public class DynamicClientWebAppRegistrationManager { - private static DynamicRegistrationManager dynamicRegistrationManager; + private static DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager; private static final Log log = - LogFactory.getLog(DynamicRegistrationManager.class); + LogFactory.getLog(DynamicClientWebAppRegistrationManager.class); - private DynamicRegistrationManager() { + private DynamicClientWebAppRegistrationManager() { } - public static DynamicRegistrationManager getInstance() { - if (dynamicRegistrationManager == null) { - synchronized (DynamicRegistrationManager.class) { - if (dynamicRegistrationManager == null) { - dynamicRegistrationManager = new DynamicRegistrationManager(); + public static DynamicClientWebAppRegistrationManager getInstance() { + if (dynamicClientWebAppRegistrationManager == null) { + synchronized (DynamicClientWebAppRegistrationManager.class) { + if (dynamicClientWebAppRegistrationManager == null) { + dynamicClientWebAppRegistrationManager = new DynamicClientWebAppRegistrationManager(); } } } - return dynamicRegistrationManager; + return dynamicClientWebAppRegistrationManager; } public OAuthApp registerOAuthApplication(RegistrationProfile registrationProfile) { @@ -60,7 +60,7 @@ public class DynamicRegistrationManager { } if (DynamicClientWebAppRegistrationUtil.validateRegistrationProfile(registrationProfile)) { DynamicClientRegistrationService dynamicClientRegistrationService = - DynamicClientRegistrationDataHolder.getInstance() + DynamicClientWebAppRegistrationDataHolder.getInstance() .getDynamicClientRegistrationService(); try { OAuthApplicationInfo oAuthApplicationInfo = @@ -110,9 +110,9 @@ public class DynamicRegistrationManager { public void initiateDynamicClientRegistrationProcess(StandardContext context) { ServletContext servletContext = context.getServletContext(); String requiredDynamicClientRegistration = servletContext.getInitParameter( - DynamicClientRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG); - DynamicRegistrationManager dynamicRegistrationManager = - DynamicRegistrationManager.getInstance(); + DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG); + DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager = + DynamicClientWebAppRegistrationManager.getInstance(); //Get the application name from web-context String webAppName = context.getBaseName(); RegistrationProfile registrationProfile; @@ -121,30 +121,34 @@ public class DynamicRegistrationManager { if ((requiredDynamicClientRegistration != null) && (Boolean.parseBoolean(requiredDynamicClientRegistration))) { //Check whether this is an already registered application - if (!dynamicRegistrationManager.isRegisteredOAuthApplication(webAppName)) { + if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) { //Construct the RegistrationProfile registrationProfile = DynamicClientWebAppRegistrationUtil. constructRegistrationProfile(servletContext, webAppName); //Register the OAuth application - oAuthApp = dynamicRegistrationManager.registerOAuthApplication( + oAuthApp = dynamicClientWebAppRegistrationManager.registerOAuthApplication( registrationProfile); + } else { + oAuthApp = dynamicClientWebAppRegistrationManager.getOAuthApplicationData(webAppName); } } else { //Jaggery apps OAuthSettings oAuthSettings = DynamicClientWebAppRegistrationUtil .getJaggeryAppOAuthSettings(servletContext); if (oAuthSettings.isRequireDynamicClientRegistration()) { - if (!dynamicRegistrationManager.isRegisteredOAuthApplication(webAppName)) { + if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) { registrationProfile = DynamicClientWebAppRegistrationUtil .constructRegistrationProfile(oAuthSettings, webAppName); - oAuthApp = dynamicRegistrationManager + oAuthApp = dynamicClientWebAppRegistrationManager .registerOAuthApplication(registrationProfile); + } else { + oAuthApp = dynamicClientWebAppRegistrationManager.getOAuthApplicationData(webAppName); } } } DynamicClientWebAppRegistrationUtil.addClientCredentialsToWebContext(oAuthApp, - servletContext); + servletContext); } } diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationDataHolder.java similarity index 90% rename from components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationDataHolder.java index aea9739b17..af96d2a37d 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationDataHolder.java @@ -26,20 +26,20 @@ import org.wso2.carbon.utils.ConfigurationContextService; /** * Dataholder class of DynamicClient Webapp Registration component. */ -public class DynamicClientRegistrationDataHolder { +public class DynamicClientWebAppRegistrationDataHolder { private RealmService realmService; private RegistryService registryService; private DynamicClientRegistrationService dynamicClientRegistrationService; private ConfigurationContextService configurationContextService; - private static DynamicClientRegistrationDataHolder thisInstance = - new DynamicClientRegistrationDataHolder(); + private static DynamicClientWebAppRegistrationDataHolder thisInstance = + new DynamicClientWebAppRegistrationDataHolder(); - private DynamicClientRegistrationDataHolder() { + private DynamicClientWebAppRegistrationDataHolder() { } - public static DynamicClientRegistrationDataHolder getInstance() { + public static DynamicClientWebAppRegistrationDataHolder getInstance() { return thisInstance; } diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java index 9f1eaf4984..7950a4dbb8 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java @@ -76,7 +76,7 @@ public class DynamicClientWebAppRegistrationServiceComponent { if (log.isDebugEnabled()) { log.debug("Setting Realm Service"); } - DynamicClientRegistrationDataHolder.getInstance().setRealmService(realmService); + DynamicClientWebAppRegistrationDataHolder.getInstance().setRealmService(realmService); } /** @@ -88,7 +88,7 @@ public class DynamicClientWebAppRegistrationServiceComponent { if (log.isDebugEnabled()) { log.debug("Unsetting Realm Service"); } - DynamicClientRegistrationDataHolder.getInstance().setRealmService(null); + DynamicClientWebAppRegistrationDataHolder.getInstance().setRealmService(null); } /** @@ -100,7 +100,7 @@ public class DynamicClientWebAppRegistrationServiceComponent { if (log.isDebugEnabled()) { log.debug("Setting Registry Service"); } - DynamicClientRegistrationDataHolder.getInstance().setRegistryService(registryService); + DynamicClientWebAppRegistrationDataHolder.getInstance().setRegistryService(registryService); } /** @@ -112,7 +112,7 @@ public class DynamicClientWebAppRegistrationServiceComponent { if (log.isDebugEnabled()) { log.debug("Un setting Registry Service"); } - DynamicClientRegistrationDataHolder.getInstance().setRegistryService(null); + DynamicClientWebAppRegistrationDataHolder.getInstance().setRegistryService(null); } /** @@ -124,7 +124,7 @@ public class DynamicClientWebAppRegistrationServiceComponent { if (log.isDebugEnabled()) { log.debug("Setting Dynamic Client Registration Service"); } - DynamicClientRegistrationDataHolder.getInstance().setDynamicClientRegistrationService( + DynamicClientWebAppRegistrationDataHolder.getInstance().setDynamicClientRegistrationService( dynamicClientRegistrationService); } @@ -137,7 +137,7 @@ public class DynamicClientWebAppRegistrationServiceComponent { if (log.isDebugEnabled()) { log.debug("Un setting Dynamic Client Registration Service"); } - DynamicClientRegistrationDataHolder.getInstance().setDynamicClientRegistrationService(null); + DynamicClientWebAppRegistrationDataHolder.getInstance().setDynamicClientRegistrationService(null); } /** @@ -149,7 +149,7 @@ public class DynamicClientWebAppRegistrationServiceComponent { if (log.isDebugEnabled()) { log.debug("Setting ConfigurationContextService"); } - DynamicClientRegistrationDataHolder.getInstance().setConfigurationContextService(configurationContextService); + DynamicClientWebAppRegistrationDataHolder.getInstance().setConfigurationContextService(configurationContextService); } /** @@ -161,7 +161,7 @@ public class DynamicClientWebAppRegistrationServiceComponent { if (log.isDebugEnabled()) { log.debug("Un-setting ConfigurationContextService"); } - DynamicClientRegistrationDataHolder.getInstance().setConfigurationContextService(null); + DynamicClientWebAppRegistrationDataHolder.getInstance().setConfigurationContextService(null); } } diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java index 0c3f8674fb..ce8e452a82 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java @@ -24,7 +24,7 @@ import org.apache.catalina.LifecycleListener; import org.apache.catalina.core.StandardContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.dynamic.client.web.app.registration.DynamicRegistrationManager; +import org.wso2.carbon.dynamic.client.web.app.registration.DynamicClientWebAppRegistrationManager; /** * This class initiates the dynamic client registration flow for Web applications upon on deployment @@ -40,7 +40,7 @@ public class DynamicClientWebAppDeploymentLifecycleListener implements Lifecycle public void lifecycleEvent(LifecycleEvent lifecycleEvent) { if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType())) { StandardContext context = (StandardContext) lifecycleEvent.getLifecycle(); - DynamicRegistrationManager.getInstance().initiateDynamicClientRegistrationProcess( + DynamicClientWebAppRegistrationManager.getInstance().initiateDynamicClientRegistrationProcess( context); } } diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationConstants.java similarity index 96% rename from components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java rename to components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationConstants.java index d9314c6277..778063b722 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationConstants.java @@ -21,7 +21,7 @@ package org.wso2.carbon.dynamic.client.web.app.registration.util; /** * Holds the constants to be used in Dynamic client web app registration component. */ -public class DynamicClientRegistrationConstants { +public class DynamicClientWebAppRegistrationConstants { public final static String OAUTH_APP_DATA_REGISTRY_PATH = "/OAuth"; public final static String OAUTH_APP_NAME = "appName"; diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java index 51939d80d7..1dd54c40f1 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java @@ -26,7 +26,7 @@ import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationExce import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; import org.wso2.carbon.dynamic.client.web.app.registration.OAuthApp; import org.wso2.carbon.dynamic.client.web.app.registration.OAuthSettings; -import org.wso2.carbon.dynamic.client.web.app.registration.internal.DynamicClientRegistrationDataHolder; +import org.wso2.carbon.dynamic.client.web.app.registration.internal.DynamicClientWebAppRegistrationDataHolder; import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.Resource; import org.wso2.carbon.registry.core.Registry; @@ -62,7 +62,7 @@ public class DynamicClientWebAppRegistrationUtil { public static Registry getGovernanceRegistry() throws DynamicClientRegistrationException { try { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - return DynamicClientRegistrationDataHolder.getInstance().getRegistryService() + return DynamicClientWebAppRegistrationDataHolder.getInstance().getRegistryService() .getGovernanceSystemRegistry( tenantId); } catch (RegistryException e) { @@ -76,7 +76,7 @@ public class DynamicClientWebAppRegistrationUtil { throws DynamicClientRegistrationException { Resource resource; String resourcePath = - DynamicClientRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + appName; + DynamicClientWebAppRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + appName; try { if (log.isDebugEnabled()) { log.debug("Retrieving OAuth application " + appName + " data from Registry"); @@ -88,7 +88,7 @@ public class DynamicClientWebAppRegistrationUtil { return (OAuthApp) unmarshaller.unmarshal( new StringReader(new String((byte[]) resource.getContent(), Charset .forName( - DynamicClientRegistrationConstants.CharSets.CHARSET_UTF8)))); + DynamicClientWebAppRegistrationConstants.CharSets.CHARSET_UTF8)))); } return new OAuthApp(); } catch (JAXBException e) { @@ -116,9 +116,9 @@ public class DynamicClientWebAppRegistrationUtil { Resource resource = DynamicClientWebAppRegistrationUtil.getGovernanceRegistry().newResource(); resource.setContent(writer.toString()); - resource.setMediaType(DynamicClientRegistrationConstants.ContentTypes.MEDIA_TYPE_XML); + resource.setMediaType(DynamicClientWebAppRegistrationConstants.ContentTypes.MEDIA_TYPE_XML); String resourcePath = - DynamicClientRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + + DynamicClientWebAppRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + oAuthApp.getWebAppName(); status = DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource); @@ -172,7 +172,7 @@ public class DynamicClientWebAppRegistrationUtil { public static String getUserName() { String username = ""; RealmService realmService = - DynamicClientRegistrationDataHolder.getInstance().getRealmService(); + DynamicClientWebAppRegistrationDataHolder.getInstance().getRealmService(); if (realmService != null) { username = realmService.getBootstrapRealmConfiguration().getAdminUserName(); } @@ -252,7 +252,7 @@ public class DynamicClientWebAppRegistrationUtil { while (reader.hasNext()) { String key = reader.nextName(); switch (key) { - case DynamicClientRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG: + case DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG: oAuthSettings.setRequireDynamicClientRegistration(reader.nextBoolean()); break; case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_GRANT_TYPE: @@ -289,7 +289,7 @@ public class DynamicClientWebAppRegistrationUtil { // HTTPS port String mgtConsoleTransport = CarbonUtils.getManagementTransport(); ConfigurationContextService configContextService = - DynamicClientRegistrationDataHolder.getInstance().getConfigurationContextService(); + DynamicClientWebAppRegistrationDataHolder.getInstance().getConfigurationContextService(); int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport); int httpsProxyPort = CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(), @@ -310,9 +310,9 @@ public class DynamicClientWebAppRegistrationUtil { //Check for client credentials if ((oAuthApp.getClientKey() != null && !oAuthApp.getClientKey().isEmpty()) && (oAuthApp.getClientSecret() != null && !oAuthApp.getClientSecret().isEmpty())) { - servletContext.setAttribute(DynamicClientRegistrationConstants.OAUTH_CLIENT_KEY, + servletContext.setAttribute(DynamicClientWebAppRegistrationConstants.OAUTH_CLIENT_KEY, oAuthApp.getClientKey()); - servletContext.setAttribute(DynamicClientRegistrationConstants.OAUTH_CLIENT_SECRET, + servletContext.setAttribute(DynamicClientWebAppRegistrationConstants.OAUTH_CLIENT_SECRET, oAuthApp.getClientSecret()); } else { log.warn("Client credentials not found for web app : " + oAuthApp.getWebAppName()); From 429b738dba104fbfc4df24f0140e55a01c88e405 Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 6 Oct 2015 22:41:59 +0530 Subject: [PATCH 4/7] Fixed issues in permission tree' --- .../mgt/PermissionManagerServiceImpl.java | 5 ++++- .../mgt/core/permission/mgt/PermissionTree.java | 10 ++++++---- .../mgt/core/permission/mgt/PermissionUtils.java | 7 +++++-- .../extensions/validators/ScopeValidator.java | 16 +++++++--------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceImpl.java index 5ea3a09e84..bee2ce0646 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceImpl.java @@ -60,7 +60,10 @@ public class PermissionManagerServiceImpl implements PermissionManagerService { @Override public boolean addPermission(Permission permission) throws PermissionManagementException { - permissionTree.addPermission(permission); // adding a permission to the tree + // update the permission path to absolute permission path + permission.setPath(PermissionUtils.getAbsolutePermissionPath(permission.getPath())); + // adding a permission to the tree + permissionTree.addPermission(permission); return PermissionUtils.putPermission(permission); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionTree.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionTree.java index 380aeebe1b..8294cce8a0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionTree.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionTree.java @@ -87,18 +87,19 @@ public class PermissionTree { */ public Permission getPermission(String url, String httpMethod) { StringTokenizer st = new StringTokenizer(url, ROOT); - PermissionNode tempRoot = rootNode; + PermissionNode tempRoot; + PermissionNode currentRoot = rootNode; while (st.hasMoreTokens()) { String currentToken = st.nextToken(); // returns the child node which matches with the 'currentToken' path. - tempRoot = tempRoot.getChild(currentToken); + tempRoot = currentRoot.getChild(currentToken); // if tempRoot is null, that means 'currentToken' is not matched with the child's path. // It means that it is at a point where the request must have dynamic path variables. // Therefor it looks for '*' in the request path. ('*' denotes dynamic path variable). if (tempRoot == null) { - tempRoot = tempRoot.getChild(DYNAMIC_PATH_NOTATION); + tempRoot = currentRoot.getChild(DYNAMIC_PATH_NOTATION); // if tempRoot is null, that means there is no any permission which matches with the // given path if (tempRoot == null) { @@ -108,7 +109,8 @@ public class PermissionTree { return null; } } + currentRoot = tempRoot; } - return tempRoot.getPermission(httpMethod); + return currentRoot.getPermission(httpMethod); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionUtils.java index 35733cd7ca..d81d7a157c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionUtils.java @@ -55,6 +55,10 @@ public class PermissionUtils { } } + public static String getAbsolutePermissionPath(String permissionPath) { + return PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH + permissionPath; + } + public static Permission getPermission(String path) throws PermissionManagementException { try { Resource resource = PermissionUtils.getGovernanceRegistry().get(path); @@ -97,8 +101,7 @@ public class PermissionUtils { Resource resource = PermissionUtils.getGovernanceRegistry().newCollection(); resource.addProperty(PERMISSION_PROPERTY_NAME, resourceName); PermissionUtils.getGovernanceRegistry().beginTransaction(); - PermissionUtils.getGovernanceRegistry().put(ADMIN_PERMISSION_REGISTRY_PATH + - path, resource); + PermissionUtils.getGovernanceRegistry().put(path, resource); PermissionUtils.getGovernanceRegistry().commitTransaction(); } diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java index ed68a04a55..2f534f38fe 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/validators/ScopeValidator.java @@ -70,16 +70,14 @@ public class ScopeValidator extends OAuth2ScopeValidator { getPermissionManagerService(); try { Permission permission = permissionManagerService.getPermission(properties); - String username = accessTokenDO.getAuthzUser(); - status = CarbonContext.getThreadLocalCarbonContext().getUserRealm(). - getAuthorizationManager().isUserAuthorized(username, permission.getPath(), - ScopeValidator.PermissionMethod.READ); - UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm(); - if(userRealm != null && userRealm.getAuthorizationManager() != null){ - status = userRealm.getAuthorizationManager().isUserAuthorized(username, permission.getPath(), - ScopeValidator.PermissionMethod.READ); + if(permission != null){ + String username = accessTokenDO.getAuthzUser(); + UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm(); + if(userRealm != null && userRealm.getAuthorizationManager() != null){ + status = userRealm.getAuthorizationManager().isUserAuthorized(username, permission.getPath(), + PermissionMethod.READ); + } } - } catch (PermissionManagementException e) { log.error("Error occurred while validating the resource scope for : " + resource + ", Msg = " + e.getMessage(), e); From 36ca79d31aeb067ed892b004390f0bc57d56a712 Mon Sep 17 00:00:00 2001 From: harshanl Date: Wed, 7 Oct 2015 00:17:17 +0530 Subject: [PATCH 5/7] Fixed build issues --- .../pom.xml | 2 +- .../impl/DynamicClientRegistrationImpl.java | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml index 88b54304e8..51bce89c19 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml @@ -47,7 +47,7 @@ ${project.artifactId} ${carbon.device.mgt.version} Dynamic Client Registration Bundle - org.wso2.carbon.dynamic.client.registration.internal.DynamicClientRegistrationServiceComponent + org.wso2.carbon.dynamic.client.registration.internal.DynamicClientRegistrationBundleActivator org.wso2.carbon.dynamic.client.registration.internal !org.wso2.carbon.dynamic.client.registration.internal, diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java index cc09b05be5..fa8c10d1c6 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java @@ -160,13 +160,15 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS "Service"); } - ServiceProvider existingServiceProvider = appMgtService.getApplication(applicationName); + ServiceProvider existingServiceProvider = appMgtService.getServiceProvider( + applicationName, tenantDomain); if (existingServiceProvider == null) { - appMgtService.createApplication(serviceProvider); + appMgtService.createApplication(serviceProvider, userName, tenantDomain); } - ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName); + ServiceProvider createdServiceProvider = appMgtService.getServiceProvider( + applicationName, tenantDomain); if (createdServiceProvider == null) { throw new DynamicClientRegistrationException( "Couldn't create Service Provider Application " + applicationName); @@ -254,7 +256,7 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS createdServiceProvider.setLocalAndOutBoundAuthenticationConfig(localOutboundAuthConfig); // Update the Service Provider app to add OAuthApp as an Inbound Authentication Config - appMgtService.updateApplication(createdServiceProvider); + appMgtService.updateApplication(createdServiceProvider, tenantDomain, userName); OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo(); oAuthApplicationInfo.setClientId(createdApp.getOauthConsumerKey()); @@ -329,12 +331,13 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS "Error occurred while retrieving Application Management" + "Service"); } - ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName); + ServiceProvider createdServiceProvider = appMgtService.getServiceProvider( + applicationName, tenantDomain); if (createdServiceProvider == null) { throw new DynamicClientRegistrationException( "Couldn't retrieve Service Provider Application " + applicationName); } - appMgtService.deleteApplication(applicationName); + appMgtService.deleteApplication(applicationName, tenantDomain, userName); status = true; } catch (IdentityApplicationManagementException e) { throw new DynamicClientRegistrationException( @@ -361,7 +364,8 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS "Service"); } try { - if (ApplicationManagementService.getInstance().getApplication(applicationName) != null) { + if (ApplicationManagementService.getInstance().getServiceProvider(applicationName, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()) != null) { return true; } } catch (IdentityApplicationManagementException e) { From 1e90de48f22655ad8637874ca85768aa843c4872 Mon Sep 17 00:00:00 2001 From: harshanl Date: Wed, 7 Oct 2015 00:58:57 +0530 Subject: [PATCH 6/7] modified git ignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d2f0bcab39..9c3d08d3c0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ target *.iws *.ipr .idea - +*.ids # Mac crap .DS_Store From 134a13727f71803b1fe44346fd44814b46071200 Mon Sep 17 00:00:00 2001 From: harshanl Date: Wed, 7 Oct 2015 16:58:09 +0530 Subject: [PATCH 7/7] updated cxf version & fixed migration issues --- .../wso2/carbon/dynamic/client/web/RegistrationResponse.java | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java index 889e43ea81..76ff5ef110 100644 --- a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java @@ -20,7 +20,7 @@ package org.wso2.carbon.dynamic.client.web; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; -public class RegistrationResponse extends Response { +public abstract class RegistrationResponse extends Response { @Override public Object getEntity() { diff --git a/pom.xml b/pom.xml index c2bec61b78..13a2879eb1 100644 --- a/pom.xml +++ b/pom.xml @@ -1284,7 +1284,7 @@ 4.3.0-SNAPSHOT - 2.6.1 + 2.7.16 2.5.11 1.1.wso2v1 1.9.0