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 b2d8ec58b9..9b44329b6b 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 @@ -56,7 +56,25 @@ !org.wso2.carbon.dynamic.client.registration.internal, org.wso2.carbon.dynamic.client.registration.* - * + + org.apache.commons.logging, + org.json, + org.json.simple, + org.osgi.framework, + org.osgi.service.component, + org.wso2.carbon.context, + org.wso2.carbon.identity.application.common, + org.wso2.carbon.identity.application.common.model, + org.wso2.carbon.identity.application.mgt, + org.wso2.carbon.identity.base, + org.wso2.carbon.identity.oauth, + org.wso2.carbon.identity.oauth.dto, + org.wso2.carbon.identity.sso.saml.admin, + org.wso2.carbon.identity.sso.saml.dto, + org.wso2.carbon.registry.api, + org.wso2.carbon.registry.core, + org.wso2.carbon.utils.multitenancy + diff --git a/components/identity-extensions/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 index 2eb570cb59..379194a3bf 100644 --- a/components/identity-extensions/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 @@ -91,7 +91,6 @@ public class OAuthApplicationInfo { obj.put(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_NAME, this.getClientName()); obj.put(ApplicationConstants.ClientMetadata.OAUTH_CALLBACK_URIS, this.getCallBackURL()); obj.put(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_SECRET, this.getClientSecret()); - obj.put("parameters", this.getJsonString()); return obj.toString(); } 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 339a0d32f2..3c2c49f002 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 @@ -188,7 +188,8 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS log.debug("Creating OAuth App " + applicationName); } - if (existingServiceProvider == null) { + if ((existingServiceProvider == null) || (existingServiceProvider. + getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs().length == 0)) { oAuthAdminService.registerOAuthApplicationData(oAuthConsumerApp); } diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationServiceComponent.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationServiceComponent.java index daaa7366e5..d01b7fa524 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationServiceComponent.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationServiceComponent.java @@ -24,6 +24,7 @@ import org.osgi.service.component.ComponentContext; import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService; import org.wso2.carbon.dynamic.client.registration.impl.DynamicClientRegistrationImpl; import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; +import org.wso2.carbon.identity.core.util.IdentityCoreInitializedEvent; /** * @scr.component name="org.wso2.carbon.dynamic.client.registration" immediate="true" @@ -82,4 +83,5 @@ public class DynamicClientRegistrationServiceComponent { } DynamicClientRegistrationDataHolder.getInstance().setApplicationManagementService(null); } + } diff --git a/components/identity-extensions/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 index 79be0e0b4f..438dbcefd9 100644 --- a/components/identity-extensions/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 @@ -87,6 +87,10 @@ org.wso2.carbon.identity org.wso2.carbon.identity.oauth + + org.wso2.carbon.identity + org.wso2.carbon.identity.core + org.wso2.tomcat tomcat 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/DynamicClientWebAppRegistrationManager.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 index a5f2453f11..b159a3515c 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/DynamicClientWebAppRegistrationManager.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 @@ -19,17 +19,21 @@ package org.wso2.carbon.dynamic.client.web.app.registration; import org.apache.catalina.core.StandardContext; +import org.apache.commons.collections.iterators.IteratorEnumeration; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException; import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService; import org.wso2.carbon.dynamic.client.registration.OAuthApplicationInfo; import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; +import org.wso2.carbon.dynamic.client.web.app.registration.dto.OAuthAppDetails; +import org.wso2.carbon.dynamic.client.web.app.registration.dto.JaggeryOAuthConfigurationSettings; 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; +import java.util.*; /** * This class contains the logic to handle the OAuth application creation process. @@ -37,6 +41,9 @@ import javax.servlet.ServletContext; public class DynamicClientWebAppRegistrationManager { private static DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager; + private static List registrationProfileList = new ArrayList<>(); + private static Map webAppContexts = new HashMap<>(); + private static final Log log = LogFactory.getLog(DynamicClientWebAppRegistrationManager.class); @@ -47,108 +54,132 @@ public class DynamicClientWebAppRegistrationManager { if (dynamicClientWebAppRegistrationManager == null) { synchronized (DynamicClientWebAppRegistrationManager.class) { if (dynamicClientWebAppRegistrationManager == null) { - dynamicClientWebAppRegistrationManager = new DynamicClientWebAppRegistrationManager(); + dynamicClientWebAppRegistrationManager = + new DynamicClientWebAppRegistrationManager(); } } } return dynamicClientWebAppRegistrationManager; } - public OAuthApp registerOAuthApplication(RegistrationProfile registrationProfile) { + public OAuthAppDetails registerOAuthApplication(RegistrationProfile registrationProfile) { if (log.isDebugEnabled()) { - log.debug("Registering OAuth application for web app : " + registrationProfile.getClientName()); + log.debug("Registering OAuth application for web app : " + + registrationProfile.getClientName()); } if (DynamicClientWebAppRegistrationUtil.validateRegistrationProfile(registrationProfile)) { DynamicClientRegistrationService dynamicClientRegistrationService = DynamicClientWebAppRegistrationDataHolder.getInstance() - .getDynamicClientRegistrationService(); + .getDynamicClientRegistrationService(); try { OAuthApplicationInfo oAuthApplicationInfo = dynamicClientRegistrationService .registerOAuthApplication(registrationProfile); - OAuthApp oAuthApp = new OAuthApp(); - oAuthApp.setWebAppName(registrationProfile.getClientName()); - oAuthApp.setClientName(oAuthApplicationInfo.getClientName()); - oAuthApp.setClientKey(oAuthApplicationInfo.getClientId()); - oAuthApp.setClientSecret(oAuthApplicationInfo.getClientSecret()); + OAuthAppDetails oAuthAppDetails = new OAuthAppDetails(); + oAuthAppDetails.setWebAppName(registrationProfile.getClientName()); + oAuthAppDetails.setClientName(oAuthApplicationInfo.getClientName()); + oAuthAppDetails.setClientKey(oAuthApplicationInfo.getClientId()); + oAuthAppDetails.setClientSecret(oAuthApplicationInfo.getClientSecret()); //store it in registry - if (DynamicClientWebAppRegistrationUtil.putOAuthApplicationData(oAuthApp)) { - return oAuthApp; + if (DynamicClientWebAppRegistrationUtil.putOAuthApplicationData(oAuthAppDetails)) { + return oAuthAppDetails; } else { dynamicClientRegistrationService .unregisterOAuthApplication(registrationProfile.getOwner(), oAuthApplicationInfo.getClientName(), oAuthApplicationInfo.getClientId()); - log.warn("Error occurred while persisting the OAuth application data in registry."); + log.warn( + "Error occurred while persisting the OAuth application data in registry."); } } catch (DynamicClientRegistrationException e) { log.error("Error occurred while registering the OAuth application : " + registrationProfile.getClientName(), e); } } - return new OAuthApp(); + return new OAuthAppDetails(); } - public OAuthApp getOAuthApplicationData(String clientName) { + public OAuthAppDetails getOAuthApplicationData(String clientName) { try { return DynamicClientWebAppRegistrationUtil.getOAuthApplicationData(clientName); } catch (DynamicClientRegistrationException e) { log.error("Error occurred while fetching the OAuth application data for web app : " + clientName, e); } - return new OAuthApp(); + return new OAuthAppDetails(); } public boolean isRegisteredOAuthApplication(String clientName) { - OAuthApp oAuthApp = this.getOAuthApplicationData(clientName); - if (oAuthApp.getClientKey() != null && oAuthApp.getClientSecret() != null) { + OAuthAppDetails oAuthAppDetails = this.getOAuthApplicationData(clientName); + if (oAuthAppDetails.getClientKey() != null && oAuthAppDetails.getClientSecret() != null) { return true; } return false; } - public void initiateDynamicClientRegistrationProcess(StandardContext context) { - ServletContext servletContext = context.getServletContext(); - String requiredDynamicClientRegistration = servletContext.getInitParameter( - DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG); + public void saveServletContextToCache(StandardContext context) { + DynamicClientWebAppRegistrationManager.webAppContexts.put(context.getBaseName(), + context.getServletContext()); + } + + public void initiateDynamicClientRegistration() { + String requiredDynamicClientRegistration, webAppName; + ServletContext servletContext; + RegistrationProfile registrationProfile; + OAuthAppDetails oAuthAppDetails = new OAuthAppDetails(); DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager = DynamicClientWebAppRegistrationManager.getInstance(); - //Get the application name from web-context - String webAppName = context.getBaseName(); - RegistrationProfile registrationProfile; - OAuthApp oAuthApp = null; - //Java web-app section - if ((requiredDynamicClientRegistration != null) && - (Boolean.parseBoolean(requiredDynamicClientRegistration))) { - //Check whether this is an already registered application - if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) { - //Construct the RegistrationProfile - registrationProfile = DynamicClientWebAppRegistrationUtil. - constructRegistrationProfile(servletContext, webAppName); - //Register the OAuth application - oAuthApp = dynamicClientWebAppRegistrationManager.registerOAuthApplication( - registrationProfile); - } else { - oAuthApp = dynamicClientWebAppRegistrationManager.getOAuthApplicationData(webAppName); - } - } else { - //Jaggery apps - OAuthSettings oAuthSettings = DynamicClientWebAppRegistrationUtil - .getJaggeryAppOAuthSettings(servletContext); - if (oAuthSettings.isRequireDynamicClientRegistration()) { + Enumeration enumeration = new IteratorEnumeration(DynamicClientWebAppRegistrationManager. + webAppContexts.keySet().iterator()); + if (log.isDebugEnabled()) { + log.debug("Initiating the DynamicClientRegistration service for web-apps"); + } + while (enumeration.hasMoreElements()){ + webAppName = (String) enumeration.nextElement(); + servletContext = DynamicClientWebAppRegistrationManager.webAppContexts.get(webAppName); + requiredDynamicClientRegistration = servletContext.getInitParameter( + DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG); + //Java web-app section + if ((requiredDynamicClientRegistration != null) && + (Boolean.parseBoolean(requiredDynamicClientRegistration))) { + //Check whether this is an already registered application if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) { - registrationProfile = DynamicClientWebAppRegistrationUtil - .constructRegistrationProfile(oAuthSettings, webAppName); - oAuthApp = dynamicClientWebAppRegistrationManager - .registerOAuthApplication(registrationProfile); + //Construct the RegistrationProfile + registrationProfile = DynamicClientWebAppRegistrationUtil. + constructRegistrationProfile(servletContext, + webAppName); + //Register the OAuth application + oAuthAppDetails = dynamicClientWebAppRegistrationManager.registerOAuthApplication( + registrationProfile); + } else { - oAuthApp = dynamicClientWebAppRegistrationManager.getOAuthApplicationData(webAppName); + oAuthAppDetails = + dynamicClientWebAppRegistrationManager.getOAuthApplicationData(webAppName); + } + } else if (requiredDynamicClientRegistration == null) { + //Jaggery apps + JaggeryOAuthConfigurationSettings jaggeryOAuthConfigurationSettings = DynamicClientWebAppRegistrationUtil + .getJaggeryAppOAuthSettings(servletContext); + if (jaggeryOAuthConfigurationSettings.isRequireDynamicClientRegistration()) { + if (!dynamicClientWebAppRegistrationManager + .isRegisteredOAuthApplication(webAppName)) { + registrationProfile = DynamicClientWebAppRegistrationUtil + .constructRegistrationProfile(jaggeryOAuthConfigurationSettings, webAppName); + oAuthAppDetails = dynamicClientWebAppRegistrationManager + .registerOAuthApplication(registrationProfile); + } else { + oAuthAppDetails = dynamicClientWebAppRegistrationManager + .getOAuthApplicationData(webAppName); + } } } + //Add client credentials to the web-context + if (oAuthAppDetails.getClientKey() != null) { + DynamicClientWebAppRegistrationUtil.addClientCredentialsToWebContext(oAuthAppDetails, + servletContext); + log.info("Added OAuth application credentials to webapp context of webapp : " + webAppName); + } } - DynamicClientWebAppRegistrationUtil.addClientCredentialsToWebContext(oAuthApp, - servletContext); } - -} +} \ No newline at end of file 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/WebAppRegistrationServerStartupObserver.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/WebAppRegistrationServerStartupObserver.java new file mode 100644 index 0000000000..6ed87bc28d --- /dev/null +++ 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/WebAppRegistrationServerStartupObserver.java @@ -0,0 +1,38 @@ +/* + * 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.dynamic.client.web.app.registration; + +import org.wso2.carbon.core.ServerStartupObserver; + +/** + * ServerStartupObserver implementation to initiate the DynamicClientRegistration process for web + * apps after the Carbon server is up and ready. + */ +public class WebAppRegistrationServerStartupObserver implements ServerStartupObserver { + + @Override + public void completingServerStartup() { + + } + + @Override + public void completedServerStartup() { + DynamicClientWebAppRegistrationManager.getInstance().initiateDynamicClientRegistration(); + } +} 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/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/dto/JaggeryOAuthConfigurationSettings.java similarity index 95% 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/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/dto/JaggeryOAuthConfigurationSettings.java index 42ee098f28..8b9849175c 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/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/dto/JaggeryOAuthConfigurationSettings.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.dynamic.client.web.app.registration; +package org.wso2.carbon.dynamic.client.web.app.registration.dto; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -25,7 +25,7 @@ import javax.xml.bind.annotation.XmlRootElement; * Represents OAuthConfiguration data. */ @XmlRootElement(name = "OAuthSettings") -public class OAuthSettings { +public class JaggeryOAuthConfigurationSettings { private String grantType; private boolean saasApp; 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/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/dto/OAuthAppDetails.java similarity index 93% 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/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/dto/OAuthAppDetails.java index 7195f55706..9fc1b359e8 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/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/dto/OAuthAppDetails.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.dynamic.client.web.app.registration; +package org.wso2.carbon.dynamic.client.web.app.registration.dto; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -24,8 +24,8 @@ import javax.xml.bind.annotation.XmlRootElement; /** * Represents an OAuth application with basic data. */ -@XmlRootElement(name = "OAuthApp") -public class OAuthApp { +@XmlRootElement(name = "OAuthAppDetails") +public class OAuthAppDetails { private String clientName; private String clientKey; 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 7950a4dbb8..8ecfc33b2d 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 @@ -21,7 +21,10 @@ package org.wso2.carbon.dynamic.client.web.app.registration.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; +import org.osgi.util.tracker.ServiceTracker; +import org.wso2.carbon.core.ServerStartupObserver; import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService; +import org.wso2.carbon.dynamic.client.web.app.registration.WebAppRegistrationServerStartupObserver; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.ConfigurationContextService; @@ -55,16 +58,18 @@ import org.wso2.carbon.utils.ConfigurationContextService; */ public class DynamicClientWebAppRegistrationServiceComponent { + private ServiceTracker serviceTracker; private static Log log = LogFactory.getLog(DynamicClientWebAppRegistrationServiceComponent.class); @SuppressWarnings("unused") protected void activate(ComponentContext componentContext) { - + componentContext.getBundleContext().registerService(ServerStartupObserver.class.getName(), + new WebAppRegistrationServerStartupObserver(), null) ; } @SuppressWarnings("unused") protected void deactivate(ComponentContext componentContext) { - //do nothing + } /** @@ -163,5 +168,4 @@ public class DynamicClientWebAppRegistrationServiceComponent { } DynamicClientWebAppRegistrationDataHolder.getInstance().setConfigurationContextService(null); } - -} +} \ No newline at end of file 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 ce8e452a82..aeff85c2a6 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 @@ -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(); - DynamicClientWebAppRegistrationManager.getInstance().initiateDynamicClientRegistrationProcess( + DynamicClientWebAppRegistrationManager.getInstance().saveServletContextToCache( 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/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 1dd54c40f1..765b0191e3 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 @@ -24,8 +24,8 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException; 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.dto.OAuthAppDetails; +import org.wso2.carbon.dynamic.client.web.app.registration.dto.JaggeryOAuthConfigurationSettings; 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; @@ -72,7 +72,7 @@ public class DynamicClientWebAppRegistrationUtil { } } - public static OAuthApp getOAuthApplicationData(String appName) + public static OAuthAppDetails getOAuthApplicationData(String appName) throws DynamicClientRegistrationException { Resource resource; String resourcePath = @@ -83,14 +83,14 @@ public class DynamicClientWebAppRegistrationUtil { } resource = DynamicClientWebAppRegistrationUtil.getRegistryResource(resourcePath); if (resource != null) { - JAXBContext context = JAXBContext.newInstance(OAuthApp.class); + JAXBContext context = JAXBContext.newInstance(OAuthAppDetails.class); Unmarshaller unmarshaller = context.createUnmarshaller(); - return (OAuthApp) unmarshaller.unmarshal( + return (OAuthAppDetails) unmarshaller.unmarshal( new StringReader(new String((byte[]) resource.getContent(), Charset .forName( DynamicClientWebAppRegistrationConstants.CharSets.CHARSET_UTF8)))); } - return new OAuthApp(); + return new OAuthAppDetails(); } catch (JAXBException e) { throw new DynamicClientRegistrationException( "Error occurred while parsing the OAuth application data : " + appName, e); @@ -101,7 +101,7 @@ public class DynamicClientWebAppRegistrationUtil { } } - public static boolean putOAuthApplicationData(OAuthApp oAuthApp) + public static boolean putOAuthApplicationData(OAuthAppDetails oAuthAppDetails) throws DynamicClientRegistrationException { boolean status; try { @@ -109,9 +109,9 @@ public class DynamicClientWebAppRegistrationUtil { log.debug("Persisting OAuth application data in Registry"); } StringWriter writer = new StringWriter(); - JAXBContext context = JAXBContext.newInstance(OAuthApp.class); + JAXBContext context = JAXBContext.newInstance(OAuthAppDetails.class); Marshaller marshaller = context.createMarshaller(); - marshaller.marshal(oAuthApp, writer); + marshaller.marshal(oAuthAppDetails, writer); Resource resource = DynamicClientWebAppRegistrationUtil.getGovernanceRegistry().newResource(); @@ -119,17 +119,17 @@ public class DynamicClientWebAppRegistrationUtil { resource.setMediaType(DynamicClientWebAppRegistrationConstants.ContentTypes.MEDIA_TYPE_XML); String resourcePath = DynamicClientWebAppRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + - oAuthApp.getWebAppName(); + oAuthAppDetails.getWebAppName(); status = DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource); } catch (RegistryException e) { throw new DynamicClientRegistrationException( "Error occurred while persisting OAuth application data : " + - oAuthApp.getClientName(), e); + oAuthAppDetails.getClientName(), e); } catch (JAXBException e) { throw new DynamicClientRegistrationException( "Error occurred while parsing the OAuth application data : " + - oAuthApp.getWebAppName(), e); + oAuthAppDetails.getWebAppName(), e); } return status; } @@ -204,16 +204,16 @@ public class DynamicClientWebAppRegistrationUtil { } public static RegistrationProfile constructRegistrationProfile( - OAuthSettings oAuthSettings, String webAppName) { + JaggeryOAuthConfigurationSettings jaggeryOAuthConfigurationSettings, String webAppName) { RegistrationProfile registrationProfile = new RegistrationProfile(); - if (oAuthSettings != null) { - registrationProfile.setGrantType(oAuthSettings.getGrantType()); - registrationProfile.setTokenScope(oAuthSettings.getTokenScope()); + if (jaggeryOAuthConfigurationSettings != null) { + registrationProfile.setGrantType(jaggeryOAuthConfigurationSettings.getGrantType()); + registrationProfile.setTokenScope(jaggeryOAuthConfigurationSettings.getTokenScope()); registrationProfile.setClientName(webAppName); - registrationProfile.setSaasApp(oAuthSettings.isSaasApp()); + registrationProfile.setSaasApp(jaggeryOAuthConfigurationSettings.isSaasApp()); registrationProfile.setOwner(DynamicClientWebAppRegistrationUtil.getUserName()); - if (oAuthSettings.getCallbackURL() != null) { - registrationProfile.setCallbackUrl(oAuthSettings.getCallbackURL()); + if (jaggeryOAuthConfigurationSettings.getCallbackURL() != null) { + registrationProfile.setCallbackUrl(jaggeryOAuthConfigurationSettings.getCallbackURL()); } else { registrationProfile.setCallbackUrl( DynamicClientWebAppRegistrationUtil.getCallbackUrl(webAppName)); @@ -240,8 +240,9 @@ public class DynamicClientWebAppRegistrationUtil { return status; } - public static OAuthSettings getJaggeryAppOAuthSettings(ServletContext servletContext) { - OAuthSettings oAuthSettings = new OAuthSettings(); + public static JaggeryOAuthConfigurationSettings getJaggeryAppOAuthSettings(ServletContext servletContext) { + JaggeryOAuthConfigurationSettings + jaggeryOAuthConfigurationSettings = new JaggeryOAuthConfigurationSettings(); try { InputStream inputStream = servletContext.getResourceAsStream(JAGGERY_APP_OAUTH_CONFIG_PATH); @@ -253,30 +254,30 @@ public class DynamicClientWebAppRegistrationUtil { String key = reader.nextName(); switch (key) { case DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG: - oAuthSettings.setRequireDynamicClientRegistration(reader.nextBoolean()); + jaggeryOAuthConfigurationSettings.setRequireDynamicClientRegistration(reader.nextBoolean()); break; case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_GRANT_TYPE: - oAuthSettings.setGrantType(reader.nextString()); + jaggeryOAuthConfigurationSettings.setGrantType(reader.nextString()); break; case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_TOKEN_SCOPE: - oAuthSettings.setTokenScope(reader.nextString()); + jaggeryOAuthConfigurationSettings.setTokenScope(reader.nextString()); break; case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_SAAS_APP: - oAuthSettings.setSaasApp(reader.nextBoolean()); + jaggeryOAuthConfigurationSettings.setSaasApp(reader.nextBoolean()); break; case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_CALLBACK_URL: - oAuthSettings.setCallbackURL(reader.nextString()); + jaggeryOAuthConfigurationSettings.setCallbackURL(reader.nextString()); break; } } - return oAuthSettings; + return jaggeryOAuthConfigurationSettings; } } catch (UnsupportedEncodingException e) { log.error("Error occurred while initializing OAuth settings for the Jaggery app.", e); } catch (IOException e) { log.error("Error occurred while initializing OAuth settings for the Jaggery app.", e); } - return oAuthSettings; + return jaggeryOAuthConfigurationSettings; } public static String getServerBaseUrl() { @@ -304,18 +305,18 @@ public class DynamicClientWebAppRegistrationUtil { return getServerBaseUrl() + "/" + context; } - public static void addClientCredentialsToWebContext(OAuthApp oAuthApp, + public static void addClientCredentialsToWebContext(OAuthAppDetails oAuthAppDetails, ServletContext servletContext) { - if(oAuthApp != null){ + if(oAuthAppDetails != null){ //Check for client credentials - if ((oAuthApp.getClientKey() != null && !oAuthApp.getClientKey().isEmpty()) && - (oAuthApp.getClientSecret() != null && !oAuthApp.getClientSecret().isEmpty())) { + if ((oAuthAppDetails.getClientKey() != null && !oAuthAppDetails.getClientKey().isEmpty()) && + (oAuthAppDetails.getClientSecret() != null && !oAuthAppDetails.getClientSecret().isEmpty())) { servletContext.setAttribute(DynamicClientWebAppRegistrationConstants.OAUTH_CLIENT_KEY, - oAuthApp.getClientKey()); + oAuthAppDetails.getClientKey()); servletContext.setAttribute(DynamicClientWebAppRegistrationConstants.OAUTH_CLIENT_SECRET, - oAuthApp.getClientSecret()); + oAuthAppDetails.getClientSecret()); } else { - log.warn("Client credentials not found for web app : " + oAuthApp.getWebAppName()); + log.warn("Client credentials not found for web app : " + oAuthAppDetails.getWebAppName()); } } } diff --git a/pom.xml b/pom.xml index 26df26d760..d3b520e7bb 100644 --- a/pom.xml +++ b/pom.xml @@ -152,10 +152,6 @@ org.eclipse.osgi org.eclipse.osgi - - org.eclipse.osgi - org.eclipse.osgi.services - @@ -410,6 +406,11 @@ org.eclipse.osgi.services 3.3.100.v20120522-1822 + + org.osgi.ut + org.eclipse.osgi + 3.3.100.v20120522-1822 +