mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixed dynamic client registration issues with server startup
This commit is contained in:
parent
1c8bb7551d
commit
741777682a
@ -56,7 +56,25 @@
|
||||
!org.wso2.carbon.dynamic.client.registration.internal,
|
||||
org.wso2.carbon.dynamic.client.registration.*
|
||||
</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>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -87,6 +87,10 @@
|
||||
<groupId>org.wso2.carbon.identity</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.tomcat</groupId>
|
||||
<artifactId>tomcat</artifactId>
|
||||
|
||||
@ -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<RegistrationProfile> registrationProfileList = new ArrayList<>();
|
||||
private static Map<String, ServletContext> 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);
|
||||
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()) {
|
||||
if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) {
|
||||
registrationProfile = DynamicClientWebAppRegistrationUtil
|
||||
.constructRegistrationProfile(oAuthSettings, webAppName);
|
||||
oAuthApp = dynamicClientWebAppRegistrationManager
|
||||
.registerOAuthApplication(registrationProfile);
|
||||
} else {
|
||||
oAuthApp = dynamicClientWebAppRegistrationManager.getOAuthApplicationData(webAppName);
|
||||
}
|
||||
}
|
||||
}
|
||||
DynamicClientWebAppRegistrationUtil.addClientCredentialsToWebContext(oAuthApp,
|
||||
servletContext);
|
||||
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();
|
||||
|
||||
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)) {
|
||||
//Construct the RegistrationProfile
|
||||
registrationProfile = DynamicClientWebAppRegistrationUtil.
|
||||
constructRegistrationProfile(servletContext,
|
||||
webAppName);
|
||||
//Register the OAuth application
|
||||
oAuthAppDetails = dynamicClientWebAppRegistrationManager.registerOAuthApplication(
|
||||
registrationProfile);
|
||||
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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.
|
||||
*/
|
||||
|
||||
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;
|
||||
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
pom.xml
9
pom.xml
@ -152,10 +152,6 @@
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -410,6 +406,11 @@
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
<version>3.3.100.v20120522-1822</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.osgi.ut</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
<version>3.3.100.v20120522-1822</version>
|
||||
</dependency>
|
||||
<!-- End of OSGi dependencies -->
|
||||
|
||||
<dependency>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user