Merged changes

4.x.x
harshanl 9 years ago
commit 302eb3a8a9

@ -22,6 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.api.FaultGatewaysException;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
@ -48,10 +49,15 @@ public class APIPublisherServiceImpl implements APIPublisherService {
log.info("Successfully published API '" + api.getId().getApiName() + "' with context '" +
api.getContext() + "' and version '" + api.getId().getVersion() + "'");
} else {
provider.updateAPI(api);
log.info("An API already exists with the name '" + api.getId().getApiName() + "', context '" +
api.getContext() + "' and version '" + api.getId().getVersion() +
"'. Thus, the API config is updated");
try {
provider.updateAPI(api);
log.info("An API already exists with the name '" + api.getId().getApiName() + "', context '" +
api.getContext() + "' and version '" + api.getId().getVersion() +
"'. Thus, the API config is updated");
} catch (FaultGatewaysException e) {
throw new APIManagementException("Error occurred while updating API " + api.getId().getApiName() +
"' with context '" + api.getContext() + "' and version '" + api.getId().getVersion() + "'");
}
}
} else {
throw new APIManagementException("API provider configured for the given API configuration is null. " +

@ -67,30 +67,31 @@
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-http</artifactId>
<version>2.5.11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
@ -102,10 +103,12 @@
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>provided</scope>
</dependency>
<!-- Device management core dependencies -->
@ -143,6 +146,11 @@
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -47,7 +47,7 @@
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
<Bundle-Description>Dynamic Client Registration Bundle</Bundle-Description>
<Bundle-Activator>org.wso2.carbon.dynamic.client.registration.internal.DynamicClientRegistrationBundleActivator</Bundle-Activator>
<Bundle-Activator>org.wso2.carbon.dynamic.client.registration.internal.DynamicClientRegistrationServiceComponent</Bundle-Activator>
<Private-Package>org.wso2.carbon.dynamic.client.registration.internal</Private-Package>
<Export-Package>
!org.wso2.carbon.dynamic.client.registration.internal,

@ -25,37 +25,39 @@ import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile;
*/
public interface DynamicClientRegistrationService {
/**
* This method will register a new OAuth application using the data provided by
* RegistrationProfile.
*
* @param profile - RegistrationProfile of the OAuth application to be created.
* @return OAuthApplicationInfo object which holds the necessary data of created OAuth app.
* @throws DynamicClientRegistrationException
*/
public OAuthApplicationInfo registerOAuthApplication(RegistrationProfile profile) throws
DynamicClientRegistrationException;
/**
* This method will register a new OAuth application using the data provided by
* RegistrationProfile.
*
* @param profile - RegistrationProfile of the OAuth application to be created.
* @return OAuthApplicationInfo object which holds the necessary data of created OAuth app.
* @throws DynamicClientRegistrationException
*
*/
public OAuthApplicationInfo registerOAuthApplication(
RegistrationProfile profile) throws DynamicClientRegistrationException;
/**
* This method will unregister a created OAuth application.
*
* @param userName - Username of the owner
* @param applicationName - OAuth application name
* @param consumerKey - ConsumerKey of the OAuth application
* @return The status of the operation
* @throws DynamicClientRegistrationException
*/
public boolean unregisterOAuthApplication(String userName, String applicationName,
String consumerKey) throws DynamicClientRegistrationException;
/**
* This method will unregister a created OAuth application.
*
* @param userName - Username of the owner
* @param applicationName - OAuth application name
* @param consumerKey - ConsumerKey of the OAuth application
* @return The status of the operation
* @throws DynamicClientRegistrationException
*
*/
public boolean unregisterOAuthApplication(String userName, String applicationName,
String consumerKey) throws DynamicClientRegistrationException;
/**
* This method will check the existence of an OAuth application provided application-name.
*
* @param applicationName - OAuth application name
* @return The status of the operation
* @throws DynamicClientRegistrationException
*/
public boolean isOAuthApplicationExists(String applicationName)
throws DynamicClientRegistrationException;
/**
* This method will check the existence of an OAuth application provided application-name.
*
* @param applicationName - OAuth application name
* @return The status of the operation
* @throws DynamicClientRegistrationException
*
*/
public boolean isOAuthApplicationExists(String applicationName) throws DynamicClientRegistrationException;
}

@ -0,0 +1,40 @@
/*
* 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.registration;
public class DynamicClientRegistrationUtil {
public static void validateUsername(String username) {
if (username == null || username.isEmpty()) {
throw new IllegalArgumentException("Username cannot be null or empty");
}
}
public static void validateApplicationName(String applicationName) {
if (applicationName == null || applicationName.isEmpty()) {
throw new IllegalArgumentException("Application name cannot be null or empty");
}
}
public static void validateConsumerKey(String consumerKey) {
if (consumerKey == null || consumerKey.isEmpty()) {
throw new IllegalArgumentException("Consumer Key cannot be null or empty");
}
}
}

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

@ -70,8 +70,8 @@ public class ScopeValidator extends OAuth2ScopeValidator {
getPermissionManagerService();
try {
Permission permission = permissionManagerService.getPermission(properties);
if(permission != null){
String username = accessTokenDO.getAuthzUser();
if((permission != null) && (accessTokenDO.getAuthzUser() != null)) {
String username = accessTokenDO.getAuthzUser().getUserName();
UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
if(userRealm != null && userRealm.getAuthorizationManager() != null){
status = userRealm.getAuthorizationManager().isUserAuthorized(username, permission.getPath(),

@ -31,14 +31,12 @@ import org.wso2.carbon.webapp.authenticator.framework.DataHolder;
import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticationHandler;
import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator;
import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorRepository;
import org.wso2.carbon.webapp.authenticator.framework.authorizer.PermissionAuthorizationValve;
import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig;
import org.wso2.carbon.webapp.authenticator.framework.config.WebappAuthenticatorConfig;
import java.util.ArrayList;
import java.util.List;
/**
* @scr.component name="org.wso2.carbon.webapp.authenticator" immediate="true"
* @scr.reference name="user.realmservice.default"

@ -17,8 +17,7 @@
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -383,8 +382,8 @@
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
<!--<exclusion>-->
<!--<groupId>org.wso2.carbon</groupId>-->
<!--<artifactId>org.wso2.carbon.queuing</artifactId>-->
<!--<groupId>org.wso2.carbon</groupId>-->
<!--<artifactId>org.wso2.carbon.queuing</artifactId>-->
<!--</exclusion>-->
<exclusion>
<groupId>org.wso2.carbon</groupId>
@ -1019,13 +1018,17 @@
<artifactId>json</artifactId>
<version>${json.wso2.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${google.gson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<scm>
<url>https://github.com/wso2/carbon-device-mgt.git</url>
<developerConnection>scm:git:https://github.com/wso2/carbon-device-mgt.git
</developerConnection>
<developerConnection>scm:git:https://github.com/wso2/carbon-device-mgt.git</developerConnection>
<connection>scm:git:https://github.com/wso2/carbon-device-mgt.git</connection>
<tag>HEAD</tag>
</scm>
@ -1212,7 +1215,7 @@
<properties>
<testng.version>6.1.1</testng.version>
<carbon.kernel.version>4.4.0</carbon.kernel.version>
<carbon.kernel.version>4.4.1</carbon.kernel.version>
<carbon.p2.plugin.version>1.5.4</carbon.p2.plugin.version>
<maven-buildnumber-plugin.version>1.3</maven-buildnumber-plugin.version>
@ -1225,7 +1228,7 @@
<carbon.p2.plugin.version>1.5.4</carbon.p2.plugin.version>
<!-- Jaggery -->
<jaggery.version>0.10.0</jaggery.version>
<jaggery.version>0.10.2</jaggery.version>
<jaggery.extensions.version>1.3.0</jaggery.extensions.version>
<jaggery.extensions.sso.version>1.3.0</jaggery.extensions.sso.version>
<jaggery.extensions.carbon.version>1.3.0</jaggery.extensions.carbon.version>
@ -1249,19 +1252,19 @@
<tomcat.jdbc.pooling.version>7.0.34.wso2v2</tomcat.jdbc.pooling.version>
<!-- Carbon Deployment -->
<carbon.deployment.version>4.4.0</carbon.deployment.version>
<carbon.deployment.version>4.5.2</carbon.deployment.version>
<!-- Carbon Identity -->
<carbon.identity.version>4.4.0</carbon.identity.version>
<carbon.identity.version>4.6.0-M2</carbon.identity.version>
<!-- Carbon Multi-tenancy -->
<carbon.multitenancy.version>4.4.0</carbon.multitenancy.version>
<carbon.multitenancy.version>4.5.0-m1</carbon.multitenancy.version>
<!-- Carbon Registry -->
<carbon.registry.version>4.4.1</carbon.registry.version>
<carbon.registry.version>4.4.8</carbon.registry.version>
<!-- Carbon Governance -->
<carbon.governance.version>4.4.1</carbon.governance.version>
<carbon.governance.version>4.5.8</carbon.governance.version>
<!-- Axiom -->
<axiom.version>1.2.11-wso2v5</axiom.version>
@ -1272,13 +1275,13 @@
<carbon.device.mgt.version>0.9.2-SNAPSHOT</carbon.device.mgt.version>
<!-- Carbon Commons -->
<carbon.commons.version>4.4.0</carbon.commons.version>
<carbon.commons.version>4.4.7</carbon.commons.version>
<version.commons.codec>1.4.0.wso2v1</version.commons.codec>
<version.commons.io>2.4.0.wso2v1</version.commons.io>
<version.commons.lang>2.6.0.wso2v1</version.commons.lang>
<!-- Carbon API Management -->
<carbon.api.mgt.version>1.4.0</carbon.api.mgt.version>
<carbon.api.mgt.version>4.3.0-SNAPSHOT</carbon.api.mgt.version>
<!--CXF properties-->
<cxf.version>2.6.1</cxf.version>
@ -1300,6 +1303,7 @@
<nimbus.orbit.version>2.26.1.wso2v3</nimbus.orbit.version>
<json.wso2.version>2.0.0.wso2v1</json.wso2.version>
<google.gson.version>2.3.1</google.gson.version>
</properties>
</project>

Loading…
Cancel
Save