Merge branch 'master' of github.com:wso2/carbon-device-mgt

revert-70aa11f8
Dulitha Wijewantha 9 years ago
commit 5e07e52be8

@ -56,7 +56,25 @@
!org.wso2.carbon.dynamic.client.registration.internal, !org.wso2.carbon.dynamic.client.registration.internal,
org.wso2.carbon.dynamic.client.registration.* org.wso2.carbon.dynamic.client.registration.*
</Export-Package> </Export-Package>
<DynamicImport-Package>*</DynamicImport-Package> <Import-Package>
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
</Import-Package>
</instructions> </instructions>
</configuration> </configuration>
</plugin> </plugin>

@ -91,7 +91,6 @@ public class OAuthApplicationInfo {
obj.put(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_NAME, this.getClientName()); obj.put(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_NAME, this.getClientName());
obj.put(ApplicationConstants.ClientMetadata.OAUTH_CALLBACK_URIS, this.getCallBackURL()); obj.put(ApplicationConstants.ClientMetadata.OAUTH_CALLBACK_URIS, this.getCallBackURL());
obj.put(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_SECRET, this.getClientSecret()); obj.put(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_SECRET, this.getClientSecret());
obj.put("parameters", this.getJsonString());
return obj.toString(); return obj.toString();
} }

@ -188,7 +188,8 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
log.debug("Creating OAuth App " + applicationName); log.debug("Creating OAuth App " + applicationName);
} }
if (existingServiceProvider == null) { if ((existingServiceProvider == null) || (existingServiceProvider.
getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs().length == 0)) {
oAuthAdminService.registerOAuthApplicationData(oAuthConsumerApp); oAuthAdminService.registerOAuthApplicationData(oAuthConsumerApp);
} }

@ -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.DynamicClientRegistrationService;
import org.wso2.carbon.dynamic.client.registration.impl.DynamicClientRegistrationImpl; import org.wso2.carbon.dynamic.client.registration.impl.DynamicClientRegistrationImpl;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; 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" * @scr.component name="org.wso2.carbon.dynamic.client.registration" immediate="true"
@ -82,4 +83,5 @@ public class DynamicClientRegistrationServiceComponent {
} }
DynamicClientRegistrationDataHolder.getInstance().setApplicationManagementService(null); DynamicClientRegistrationDataHolder.getInstance().setApplicationManagementService(null);
} }
} }

@ -87,6 +87,10 @@
<groupId>org.wso2.carbon.identity</groupId> <groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.oauth</artifactId> <artifactId>org.wso2.carbon.identity.oauth</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.core</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.wso2.tomcat</groupId> <groupId>org.wso2.tomcat</groupId>
<artifactId>tomcat</artifactId> <artifactId>tomcat</artifactId>

@ -19,17 +19,21 @@
package org.wso2.carbon.dynamic.client.web.app.registration; package org.wso2.carbon.dynamic.client.web.app.registration;
import org.apache.catalina.core.StandardContext; import org.apache.catalina.core.StandardContext;
import org.apache.commons.collections.iterators.IteratorEnumeration;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException; import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException;
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService; import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService;
import org.wso2.carbon.dynamic.client.registration.OAuthApplicationInfo; import org.wso2.carbon.dynamic.client.registration.OAuthApplicationInfo;
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile;
import org.wso2.carbon.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.internal.DynamicClientWebAppRegistrationDataHolder;
import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationConstants; import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationConstants;
import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil; import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import java.util.*;
/** /**
* This class contains the logic to handle the OAuth application creation process. * This class contains the logic to handle the OAuth application creation process.
@ -37,6 +41,9 @@ import javax.servlet.ServletContext;
public class DynamicClientWebAppRegistrationManager { public class DynamicClientWebAppRegistrationManager {
private static DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager; private static DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager;
private static List<RegistrationProfile> registrationProfileList = new ArrayList<>();
private static Map<String, ServletContext> webAppContexts = new HashMap<>();
private static final Log log = private static final Log log =
LogFactory.getLog(DynamicClientWebAppRegistrationManager.class); LogFactory.getLog(DynamicClientWebAppRegistrationManager.class);
@ -47,108 +54,132 @@ public class DynamicClientWebAppRegistrationManager {
if (dynamicClientWebAppRegistrationManager == null) { if (dynamicClientWebAppRegistrationManager == null) {
synchronized (DynamicClientWebAppRegistrationManager.class) { synchronized (DynamicClientWebAppRegistrationManager.class) {
if (dynamicClientWebAppRegistrationManager == null) { if (dynamicClientWebAppRegistrationManager == null) {
dynamicClientWebAppRegistrationManager = new DynamicClientWebAppRegistrationManager(); dynamicClientWebAppRegistrationManager =
new DynamicClientWebAppRegistrationManager();
} }
} }
} }
return dynamicClientWebAppRegistrationManager; return dynamicClientWebAppRegistrationManager;
} }
public OAuthApp registerOAuthApplication(RegistrationProfile registrationProfile) { public OAuthAppDetails registerOAuthApplication(RegistrationProfile registrationProfile) {
if (log.isDebugEnabled()) { 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)) { if (DynamicClientWebAppRegistrationUtil.validateRegistrationProfile(registrationProfile)) {
DynamicClientRegistrationService dynamicClientRegistrationService = DynamicClientRegistrationService dynamicClientRegistrationService =
DynamicClientWebAppRegistrationDataHolder.getInstance() DynamicClientWebAppRegistrationDataHolder.getInstance()
.getDynamicClientRegistrationService(); .getDynamicClientRegistrationService();
try { try {
OAuthApplicationInfo oAuthApplicationInfo = OAuthApplicationInfo oAuthApplicationInfo =
dynamicClientRegistrationService dynamicClientRegistrationService
.registerOAuthApplication(registrationProfile); .registerOAuthApplication(registrationProfile);
OAuthApp oAuthApp = new OAuthApp(); OAuthAppDetails oAuthAppDetails = new OAuthAppDetails();
oAuthApp.setWebAppName(registrationProfile.getClientName()); oAuthAppDetails.setWebAppName(registrationProfile.getClientName());
oAuthApp.setClientName(oAuthApplicationInfo.getClientName()); oAuthAppDetails.setClientName(oAuthApplicationInfo.getClientName());
oAuthApp.setClientKey(oAuthApplicationInfo.getClientId()); oAuthAppDetails.setClientKey(oAuthApplicationInfo.getClientId());
oAuthApp.setClientSecret(oAuthApplicationInfo.getClientSecret()); oAuthAppDetails.setClientSecret(oAuthApplicationInfo.getClientSecret());
//store it in registry //store it in registry
if (DynamicClientWebAppRegistrationUtil.putOAuthApplicationData(oAuthApp)) { if (DynamicClientWebAppRegistrationUtil.putOAuthApplicationData(oAuthAppDetails)) {
return oAuthApp; return oAuthAppDetails;
} else { } else {
dynamicClientRegistrationService dynamicClientRegistrationService
.unregisterOAuthApplication(registrationProfile.getOwner(), .unregisterOAuthApplication(registrationProfile.getOwner(),
oAuthApplicationInfo.getClientName(), oAuthApplicationInfo.getClientName(),
oAuthApplicationInfo.getClientId()); 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) { } catch (DynamicClientRegistrationException e) {
log.error("Error occurred while registering the OAuth application : " + log.error("Error occurred while registering the OAuth application : " +
registrationProfile.getClientName(), e); registrationProfile.getClientName(), e);
} }
} }
return new OAuthApp(); return new OAuthAppDetails();
} }
public OAuthApp getOAuthApplicationData(String clientName) { public OAuthAppDetails getOAuthApplicationData(String clientName) {
try { try {
return DynamicClientWebAppRegistrationUtil.getOAuthApplicationData(clientName); return DynamicClientWebAppRegistrationUtil.getOAuthApplicationData(clientName);
} catch (DynamicClientRegistrationException e) { } catch (DynamicClientRegistrationException e) {
log.error("Error occurred while fetching the OAuth application data for web app : " + log.error("Error occurred while fetching the OAuth application data for web app : " +
clientName, e); clientName, e);
} }
return new OAuthApp(); return new OAuthAppDetails();
} }
public boolean isRegisteredOAuthApplication(String clientName) { public boolean isRegisteredOAuthApplication(String clientName) {
OAuthApp oAuthApp = this.getOAuthApplicationData(clientName); OAuthAppDetails oAuthAppDetails = this.getOAuthApplicationData(clientName);
if (oAuthApp.getClientKey() != null && oAuthApp.getClientSecret() != null) { if (oAuthAppDetails.getClientKey() != null && oAuthAppDetails.getClientSecret() != null) {
return true; return true;
} }
return false; return false;
} }
public void initiateDynamicClientRegistrationProcess(StandardContext context) { public void saveServletContextToCache(StandardContext context) {
ServletContext servletContext = context.getServletContext(); DynamicClientWebAppRegistrationManager.webAppContexts.put(context.getBaseName(),
String requiredDynamicClientRegistration = servletContext.getInitParameter( context.getServletContext());
DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG); }
public void initiateDynamicClientRegistration() {
String requiredDynamicClientRegistration, webAppName;
ServletContext servletContext;
RegistrationProfile registrationProfile;
OAuthAppDetails oAuthAppDetails = new OAuthAppDetails();
DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager = DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager =
DynamicClientWebAppRegistrationManager.getInstance(); 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 { Enumeration enumeration = new IteratorEnumeration(DynamicClientWebAppRegistrationManager.
oAuthApp = dynamicClientWebAppRegistrationManager.getOAuthApplicationData(webAppName); webAppContexts.keySet().iterator());
} if (log.isDebugEnabled()) {
} else { log.debug("Initiating the DynamicClientRegistration service for web-apps");
//Jaggery apps }
OAuthSettings oAuthSettings = DynamicClientWebAppRegistrationUtil while (enumeration.hasMoreElements()){
.getJaggeryAppOAuthSettings(servletContext); webAppName = (String) enumeration.nextElement();
if (oAuthSettings.isRequireDynamicClientRegistration()) { 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)) { if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) {
registrationProfile = DynamicClientWebAppRegistrationUtil //Construct the RegistrationProfile
.constructRegistrationProfile(oAuthSettings, webAppName); registrationProfile = DynamicClientWebAppRegistrationUtil.
oAuthApp = dynamicClientWebAppRegistrationManager constructRegistrationProfile(servletContext,
.registerOAuthApplication(registrationProfile); webAppName);
//Register the OAuth application
oAuthAppDetails = dynamicClientWebAppRegistrationManager.registerOAuthApplication(
registrationProfile);
} else { } 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);
} }
}
}

@ -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();
}
}

@ -16,7 +16,7 @@
* under the License. * 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.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@ -25,7 +25,7 @@ import javax.xml.bind.annotation.XmlRootElement;
* Represents OAuthConfiguration data. * Represents OAuthConfiguration data.
*/ */
@XmlRootElement(name = "OAuthSettings") @XmlRootElement(name = "OAuthSettings")
public class OAuthSettings { public class JaggeryOAuthConfigurationSettings {
private String grantType; private String grantType;
private boolean saasApp; private boolean saasApp;

@ -16,7 +16,7 @@
* under the License. * 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.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@ -24,8 +24,8 @@ import javax.xml.bind.annotation.XmlRootElement;
/** /**
* Represents an OAuth application with basic data. * Represents an OAuth application with basic data.
*/ */
@XmlRootElement(name = "OAuthApp") @XmlRootElement(name = "OAuthAppDetails")
public class OAuthApp { public class OAuthAppDetails {
private String clientName; private String clientName;
private String clientKey; private String clientKey;

@ -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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext; 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.registration.DynamicClientRegistrationService;
import org.wso2.carbon.dynamic.client.web.app.registration.WebAppRegistrationServerStartupObserver;
import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.ConfigurationContextService; import org.wso2.carbon.utils.ConfigurationContextService;
@ -55,16 +58,18 @@ import org.wso2.carbon.utils.ConfigurationContextService;
*/ */
public class DynamicClientWebAppRegistrationServiceComponent { public class DynamicClientWebAppRegistrationServiceComponent {
private ServiceTracker serviceTracker;
private static Log log = LogFactory.getLog(DynamicClientWebAppRegistrationServiceComponent.class); private static Log log = LogFactory.getLog(DynamicClientWebAppRegistrationServiceComponent.class);
@SuppressWarnings("unused") @SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) { protected void activate(ComponentContext componentContext) {
componentContext.getBundleContext().registerService(ServerStartupObserver.class.getName(),
new WebAppRegistrationServerStartupObserver(), null) ;
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
protected void deactivate(ComponentContext componentContext) { protected void deactivate(ComponentContext componentContext) {
//do nothing
} }
/** /**
@ -163,5 +168,4 @@ public class DynamicClientWebAppRegistrationServiceComponent {
} }
DynamicClientWebAppRegistrationDataHolder.getInstance().setConfigurationContextService(null); DynamicClientWebAppRegistrationDataHolder.getInstance().setConfigurationContextService(null);
} }
}
}

@ -40,7 +40,7 @@ public class DynamicClientWebAppDeploymentLifecycleListener implements Lifecycle
public void lifecycleEvent(LifecycleEvent lifecycleEvent) { public void lifecycleEvent(LifecycleEvent lifecycleEvent) {
if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType())) { if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType())) {
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle(); StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
DynamicClientWebAppRegistrationManager.getInstance().initiateDynamicClientRegistrationProcess( DynamicClientWebAppRegistrationManager.getInstance().saveServletContextToCache(
context); context);
} }
} }

@ -24,8 +24,8 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException; import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException;
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; 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.dto.OAuthAppDetails;
import org.wso2.carbon.dynamic.client.web.app.registration.OAuthSettings; 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.internal.DynamicClientWebAppRegistrationDataHolder;
import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.RegistryException;
import org.wso2.carbon.registry.api.Resource; 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 { throws DynamicClientRegistrationException {
Resource resource; Resource resource;
String resourcePath = String resourcePath =
@ -83,14 +83,14 @@ public class DynamicClientWebAppRegistrationUtil {
} }
resource = DynamicClientWebAppRegistrationUtil.getRegistryResource(resourcePath); resource = DynamicClientWebAppRegistrationUtil.getRegistryResource(resourcePath);
if (resource != null) { if (resource != null) {
JAXBContext context = JAXBContext.newInstance(OAuthApp.class); JAXBContext context = JAXBContext.newInstance(OAuthAppDetails.class);
Unmarshaller unmarshaller = context.createUnmarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller();
return (OAuthApp) unmarshaller.unmarshal( return (OAuthAppDetails) unmarshaller.unmarshal(
new StringReader(new String((byte[]) resource.getContent(), Charset new StringReader(new String((byte[]) resource.getContent(), Charset
.forName( .forName(
DynamicClientWebAppRegistrationConstants.CharSets.CHARSET_UTF8)))); DynamicClientWebAppRegistrationConstants.CharSets.CHARSET_UTF8))));
} }
return new OAuthApp(); return new OAuthAppDetails();
} catch (JAXBException e) { } catch (JAXBException e) {
throw new DynamicClientRegistrationException( throw new DynamicClientRegistrationException(
"Error occurred while parsing the OAuth application data : " + appName, e); "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 { throws DynamicClientRegistrationException {
boolean status; boolean status;
try { try {
@ -109,9 +109,9 @@ public class DynamicClientWebAppRegistrationUtil {
log.debug("Persisting OAuth application data in Registry"); log.debug("Persisting OAuth application data in Registry");
} }
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
JAXBContext context = JAXBContext.newInstance(OAuthApp.class); JAXBContext context = JAXBContext.newInstance(OAuthAppDetails.class);
Marshaller marshaller = context.createMarshaller(); Marshaller marshaller = context.createMarshaller();
marshaller.marshal(oAuthApp, writer); marshaller.marshal(oAuthAppDetails, writer);
Resource resource = Resource resource =
DynamicClientWebAppRegistrationUtil.getGovernanceRegistry().newResource(); DynamicClientWebAppRegistrationUtil.getGovernanceRegistry().newResource();
@ -119,17 +119,17 @@ public class DynamicClientWebAppRegistrationUtil {
resource.setMediaType(DynamicClientWebAppRegistrationConstants.ContentTypes.MEDIA_TYPE_XML); resource.setMediaType(DynamicClientWebAppRegistrationConstants.ContentTypes.MEDIA_TYPE_XML);
String resourcePath = String resourcePath =
DynamicClientWebAppRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + DynamicClientWebAppRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" +
oAuthApp.getWebAppName(); oAuthAppDetails.getWebAppName();
status = status =
DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource); DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource);
} catch (RegistryException e) { } catch (RegistryException e) {
throw new DynamicClientRegistrationException( throw new DynamicClientRegistrationException(
"Error occurred while persisting OAuth application data : " + "Error occurred while persisting OAuth application data : " +
oAuthApp.getClientName(), e); oAuthAppDetails.getClientName(), e);
} catch (JAXBException e) { } catch (JAXBException e) {
throw new DynamicClientRegistrationException( throw new DynamicClientRegistrationException(
"Error occurred while parsing the OAuth application data : " + "Error occurred while parsing the OAuth application data : " +
oAuthApp.getWebAppName(), e); oAuthAppDetails.getWebAppName(), e);
} }
return status; return status;
} }
@ -204,16 +204,16 @@ public class DynamicClientWebAppRegistrationUtil {
} }
public static RegistrationProfile constructRegistrationProfile( public static RegistrationProfile constructRegistrationProfile(
OAuthSettings oAuthSettings, String webAppName) { JaggeryOAuthConfigurationSettings jaggeryOAuthConfigurationSettings, String webAppName) {
RegistrationProfile registrationProfile = new RegistrationProfile(); RegistrationProfile registrationProfile = new RegistrationProfile();
if (oAuthSettings != null) { if (jaggeryOAuthConfigurationSettings != null) {
registrationProfile.setGrantType(oAuthSettings.getGrantType()); registrationProfile.setGrantType(jaggeryOAuthConfigurationSettings.getGrantType());
registrationProfile.setTokenScope(oAuthSettings.getTokenScope()); registrationProfile.setTokenScope(jaggeryOAuthConfigurationSettings.getTokenScope());
registrationProfile.setClientName(webAppName); registrationProfile.setClientName(webAppName);
registrationProfile.setSaasApp(oAuthSettings.isSaasApp()); registrationProfile.setSaasApp(jaggeryOAuthConfigurationSettings.isSaasApp());
registrationProfile.setOwner(DynamicClientWebAppRegistrationUtil.getUserName()); registrationProfile.setOwner(DynamicClientWebAppRegistrationUtil.getUserName());
if (oAuthSettings.getCallbackURL() != null) { if (jaggeryOAuthConfigurationSettings.getCallbackURL() != null) {
registrationProfile.setCallbackUrl(oAuthSettings.getCallbackURL()); registrationProfile.setCallbackUrl(jaggeryOAuthConfigurationSettings.getCallbackURL());
} else { } else {
registrationProfile.setCallbackUrl( registrationProfile.setCallbackUrl(
DynamicClientWebAppRegistrationUtil.getCallbackUrl(webAppName)); DynamicClientWebAppRegistrationUtil.getCallbackUrl(webAppName));
@ -240,8 +240,9 @@ public class DynamicClientWebAppRegistrationUtil {
return status; return status;
} }
public static OAuthSettings getJaggeryAppOAuthSettings(ServletContext servletContext) { public static JaggeryOAuthConfigurationSettings getJaggeryAppOAuthSettings(ServletContext servletContext) {
OAuthSettings oAuthSettings = new OAuthSettings(); JaggeryOAuthConfigurationSettings
jaggeryOAuthConfigurationSettings = new JaggeryOAuthConfigurationSettings();
try { try {
InputStream inputStream = InputStream inputStream =
servletContext.getResourceAsStream(JAGGERY_APP_OAUTH_CONFIG_PATH); servletContext.getResourceAsStream(JAGGERY_APP_OAUTH_CONFIG_PATH);
@ -253,30 +254,30 @@ public class DynamicClientWebAppRegistrationUtil {
String key = reader.nextName(); String key = reader.nextName();
switch (key) { switch (key) {
case DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG: case DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG:
oAuthSettings.setRequireDynamicClientRegistration(reader.nextBoolean()); jaggeryOAuthConfigurationSettings.setRequireDynamicClientRegistration(reader.nextBoolean());
break; break;
case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_GRANT_TYPE: case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_GRANT_TYPE:
oAuthSettings.setGrantType(reader.nextString()); jaggeryOAuthConfigurationSettings.setGrantType(reader.nextString());
break; break;
case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_TOKEN_SCOPE: case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_TOKEN_SCOPE:
oAuthSettings.setTokenScope(reader.nextString()); jaggeryOAuthConfigurationSettings.setTokenScope(reader.nextString());
break; break;
case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_SAAS_APP: case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_SAAS_APP:
oAuthSettings.setSaasApp(reader.nextBoolean()); jaggeryOAuthConfigurationSettings.setSaasApp(reader.nextBoolean());
break; break;
case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_CALLBACK_URL: case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_CALLBACK_URL:
oAuthSettings.setCallbackURL(reader.nextString()); jaggeryOAuthConfigurationSettings.setCallbackURL(reader.nextString());
break; break;
} }
} }
return oAuthSettings; return jaggeryOAuthConfigurationSettings;
} }
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
log.error("Error occurred while initializing OAuth settings for the Jaggery app.", e); log.error("Error occurred while initializing OAuth settings for the Jaggery app.", e);
} catch (IOException e) { } catch (IOException e) {
log.error("Error occurred while initializing OAuth settings for the Jaggery app.", e); log.error("Error occurred while initializing OAuth settings for the Jaggery app.", e);
} }
return oAuthSettings; return jaggeryOAuthConfigurationSettings;
} }
public static String getServerBaseUrl() { public static String getServerBaseUrl() {
@ -304,18 +305,18 @@ public class DynamicClientWebAppRegistrationUtil {
return getServerBaseUrl() + "/" + context; return getServerBaseUrl() + "/" + context;
} }
public static void addClientCredentialsToWebContext(OAuthApp oAuthApp, public static void addClientCredentialsToWebContext(OAuthAppDetails oAuthAppDetails,
ServletContext servletContext) { ServletContext servletContext) {
if(oAuthApp != null){ if(oAuthAppDetails != null){
//Check for client credentials //Check for client credentials
if ((oAuthApp.getClientKey() != null && !oAuthApp.getClientKey().isEmpty()) && if ((oAuthAppDetails.getClientKey() != null && !oAuthAppDetails.getClientKey().isEmpty()) &&
(oAuthApp.getClientSecret() != null && !oAuthApp.getClientSecret().isEmpty())) { (oAuthAppDetails.getClientSecret() != null && !oAuthAppDetails.getClientSecret().isEmpty())) {
servletContext.setAttribute(DynamicClientWebAppRegistrationConstants.OAUTH_CLIENT_KEY, servletContext.setAttribute(DynamicClientWebAppRegistrationConstants.OAUTH_CLIENT_KEY,
oAuthApp.getClientKey()); oAuthAppDetails.getClientKey());
servletContext.setAttribute(DynamicClientWebAppRegistrationConstants.OAUTH_CLIENT_SECRET, servletContext.setAttribute(DynamicClientWebAppRegistrationConstants.OAUTH_CLIENT_SECRET,
oAuthApp.getClientSecret()); oAuthAppDetails.getClientSecret());
} else { } else {
log.warn("Client credentials not found for web app : " + oAuthApp.getWebAppName()); log.warn("Client credentials not found for web app : " + oAuthAppDetails.getWebAppName());
} }
} }
} }

@ -152,10 +152,6 @@
<groupId>org.eclipse.osgi</groupId> <groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId> <artifactId>org.eclipse.osgi</artifactId>
</exclusion> </exclusion>
<exclusion>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi.services</artifactId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
@ -410,6 +406,11 @@
<artifactId>org.eclipse.osgi.services</artifactId> <artifactId>org.eclipse.osgi.services</artifactId>
<version>3.3.100.v20120522-1822</version> <version>3.3.100.v20120522-1822</version>
</dependency> </dependency>
<dependency>
<groupId>org.osgi.ut</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.3.100.v20120522-1822</version>
</dependency>
<!-- End of OSGi dependencies --> <!-- End of OSGi dependencies -->
<dependency> <dependency>

Loading…
Cancel
Save