diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/PermissionManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/PermissionManager.java index 0e370b3825..4cdf10ad77 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/PermissionManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/PermissionManager.java @@ -33,6 +33,8 @@ public class PermissionManager { private static PermissionManager permissionManager; + private PermissionManager(){}; + public static PermissionManager getInstance() { if (permissionManager == null) { synchronized (PermissionManager.class) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerConfigTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerConfigTests.java new file mode 100644 index 0000000000..97ac0721b5 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerConfigTests.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.core.permission.mgt; + +public class PermissionManagerConfigTests { +} diff --git a/components/oauth-extensions/dynamic-client-manager/pom.xml b/components/dynamic-client-registration/dynamic-client-web/pom.xml similarity index 82% rename from components/oauth-extensions/dynamic-client-manager/pom.xml rename to components/dynamic-client-registration/dynamic-client-web/pom.xml index 80af542393..927f8e1f77 100644 --- a/components/oauth-extensions/dynamic-client-manager/pom.xml +++ b/components/dynamic-client-registration/dynamic-client-web/pom.xml @@ -4,9 +4,9 @@ ~ 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 + ~ you may obtain a copy of the License at ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ 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 @@ -14,24 +14,25 @@ ~ KIND, either express or implied. See the License for the ~ specific language governing permissions and limitations ~ under the License. ---> + --> + dynamic-client-registration org.wso2.carbon.devicemgt - oauth-extensions 0.9.2-SNAPSHOT ../pom.xml 4.0.0 org.wso2.mdm - dynamic-client-manager - WSO2 Carbon - Dynamic Client Registration Impl - WSO2 Carbon - Dynamic Client Registration Impl + dynamic-client-web + 0.9.2-SNAPSHOT + WSO2 Carbon - Dynamic Client Registration Web Service + WSO2 Carbon - Dynamic Client Registration Web war @@ -119,33 +120,18 @@ provided - org.wso2.carbon - org.wso2.carbon.utils - provided - - - org.wso2.carbon.identity - org.wso2.carbon.identity.application.mgt - provided - - - org.wso2.carbon.apimgt - org.wso2.carbon.apimgt.api - provided - - - org.wso2.carbon.apimgt - org.wso2.carbon.apimgt.impl + org.wso2.carbon.devicemgt + org.wso2.carbon.dynamic.client.registration provided - org.wso2.carbon.apimgt - org.wso2.carbon.apimgt.keymgt.client + org.wso2.carbon + org.wso2.carbon.utils provided org.wso2.carbon.identity - org.wso2.carbon.identity.oauth + org.wso2.carbon.identity.application.mgt provided diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/ConfigurationService.java b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/ConfigurationService.java new file mode 100644 index 0000000000..0d97308f54 --- /dev/null +++ b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/ConfigurationService.java @@ -0,0 +1,33 @@ +/* + * 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; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +@Path("/connect") +public interface ConfigurationService { + + @GET + @Path("/register") + Response getProfile(@PathParam("client_id") String clientId); + +} diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/DynamicClientUtil.java b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/DynamicClientUtil.java new file mode 100644 index 0000000000..21f2aec018 --- /dev/null +++ b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/DynamicClientUtil.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.dynamic.client.web; + +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService; + +/** + * Created by harshan on 9/8/15. + */ +public class DynamicClientUtil { + + public static DynamicClientRegistrationService getDynamicClientRegistrationService() { + DynamicClientRegistrationService dynamicClientRegistrationService; + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + dynamicClientRegistrationService = + (DynamicClientRegistrationService) ctx.getOSGiService(DynamicClientRegistrationService.class, null); + return dynamicClientRegistrationService; + } +} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/FaultMessageBodyWriter.java b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultMessageBodyWriter.java similarity index 73% rename from components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/FaultMessageBodyWriter.java rename to components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultMessageBodyWriter.java index ff43d4aad9..39f3c6dfb0 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/FaultMessageBodyWriter.java +++ b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultMessageBodyWriter.java @@ -1,22 +1,21 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. - * + * 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.identity.oauth.extension; +package org.wso2.carbon.dynamic.client.web; import com.google.gson.Gson; import com.google.gson.GsonBuilder; diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultResponse.java b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultResponse.java new file mode 100644 index 0000000000..395673e565 --- /dev/null +++ b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/FaultResponse.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; + +public class FaultResponse { + + private RegistrationService.ErrorCode code; + private String description; + + public FaultResponse(RegistrationService.ErrorCode code, String description) { + this.code = code; + this.description = description; + } + + public RegistrationService.ErrorCode getCode() { + return code; + } + + public String getDescription() { + return description; + } + +} diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java new file mode 100644 index 0000000000..889e43ea81 --- /dev/null +++ b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationResponse.java @@ -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.web; + +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; + +public class RegistrationResponse extends Response { + + @Override + public Object getEntity() { + return null; + } + + @Override + public int getStatus() { + return 0; + } + + @Override + public MultivaluedMap getMetadata() { + return null; + } + +} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java similarity index 68% rename from components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java rename to components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java index 962b721091..194d5e966d 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java +++ b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java @@ -1,24 +1,23 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. - * + * 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.identity.oauth.extension; +package org.wso2.carbon.dynamic.client.web; -import org.wso2.carbon.identity.oauth.extension.profile.RegistrationProfile; +import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java new file mode 100644 index 0000000000..7fcf7fa075 --- /dev/null +++ b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java @@ -0,0 +1,32 @@ +/* + * 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.impl; + +import org.wso2.carbon.dynamic.client.web.ConfigurationService; + +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +public class ConfigurationServiceImpl implements ConfigurationService { + + @Override + public Response getProfile(@PathParam("client_id") String clientId) { + return null; + } + +} \ No newline at end of file diff --git a/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java new file mode 100644 index 0000000000..0640943479 --- /dev/null +++ b/components/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java @@ -0,0 +1,103 @@ +/* + * 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.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.api.APIManagementException; +import org.wso2.carbon.context.PrivilegedCarbonContext; +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.DynamicClientUtil; +import org.wso2.carbon.dynamic.client.web.FaultResponse; +import org.wso2.carbon.dynamic.client.web.RegistrationService; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.QueryParam; + +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class RegistrationServiceImpl implements RegistrationService { + + private static final Log log = LogFactory.getLog(RegistrationServiceImpl.class); + + @POST + @Override + public Response register(RegistrationProfile profile) { + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext(). + setTenantId(MultitenantConstants.SUPER_TENANT_ID); + + DynamicClientRegistrationService dynamicClientRegistrationService = DynamicClientUtil. + getDynamicClientRegistrationService(); + if(dynamicClientRegistrationService != null){ + OAuthApplicationInfo info = dynamicClientRegistrationService. + registerOAuthApplication(profile); + return Response.status(Response.Status.CREATED).entity(info.toString()).build(); + } + return Response.status(Response.Status.INTERNAL_SERVER_ERROR). + entity("Dynamic Client Registration Service not available.").build(); + } catch (DynamicClientRegistrationException e) { + String msg = "Error occurred while registering client '" + profile.getClientName() + "'"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new FaultResponse(ErrorCode.INVALID_CLIENT_METADATA, msg)).build(); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + + @DELETE + @Override + public Response unregister(@QueryParam("applicationName") String applicationName, + @QueryParam("userId") String userId, + @QueryParam("consumerKey") String consumerKey) { + try { + DynamicClientRegistrationService dynamicClientRegistrationService = DynamicClientUtil. + getDynamicClientRegistrationService(); + if(dynamicClientRegistrationService != null){ + boolean status = dynamicClientRegistrationService.unregisterOAuthApplication(userId, + applicationName, + consumerKey); + if(status){ + return Response.status(Response.Status.ACCEPTED).build(); + } + return Response.status(Response.Status.BAD_REQUEST).build(); + } + return Response.status(Response.Status.INTERNAL_SERVER_ERROR). + entity("Dynamic Client Registration Service not available.").build(); + } catch (DynamicClientRegistrationException e) { + String msg = "Error occurred while un-registering client '" + applicationName + "'"; + log.error(msg, e); + return Response.serverError(). + entity(new FaultResponse(ErrorCode.INVALID_CLIENT_METADATA, msg)).build(); + } + } + +} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/webapp/META-INF/webapp-classloading.xml b/components/dynamic-client-registration/dynamic-client-web/src/main/webapp/META-INF/webapp-classloading.xml similarity index 100% rename from components/oauth-extensions/dynamic-client-manager/src/main/webapp/META-INF/webapp-classloading.xml rename to components/dynamic-client-registration/dynamic-client-web/src/main/webapp/META-INF/webapp-classloading.xml diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/cxf-servlet.xml similarity index 57% rename from components/oauth-extensions/dynamic-client-manager/src/main/webapp/WEB-INF/cxf-servlet.xml rename to components/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/cxf-servlet.xml index 78ccf40375..3d7ec54290 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -2,19 +2,19 @@ - + - + diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/webapp/WEB-INF/web.xml b/components/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from components/oauth-extensions/dynamic-client-manager/src/main/webapp/WEB-INF/web.xml rename to components/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/webapp/servicelist.css b/components/dynamic-client-registration/dynamic-client-web/src/main/webapp/servicelist.css similarity index 100% rename from components/oauth-extensions/dynamic-client-manager/src/main/webapp/servicelist.css rename to components/dynamic-client-registration/dynamic-client-web/src/main/webapp/servicelist.css diff --git a/components/oauth-extensions/dynamic-client-manager/src/test/resources/log4j.properties b/components/dynamic-client-registration/dynamic-client-web/src/test/resources/log4j.properties similarity index 100% rename from components/oauth-extensions/dynamic-client-manager/src/test/resources/log4j.properties rename to components/dynamic-client-registration/dynamic-client-web/src/test/resources/log4j.properties diff --git a/components/oauth-extensions/dynamic-client-manager/src/test/resources/testng.xml b/components/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml similarity index 100% rename from components/oauth-extensions/dynamic-client-manager/src/test/resources/testng.xml rename to components/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml new file mode 100644 index 0000000000..e1aa38e3f6 --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/pom.xml @@ -0,0 +1,108 @@ + + + + + + dynamic-client-registration + org.wso2.carbon.devicemgt + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.dynamic.client.registration + 0.9.2-SNAPSHOT + bundle + WSO2 Carbon - Dynamic client registration service + WSO2 Carbon - Dynamic Client Registration Service + http://wso2.org + + + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Dynamic Client Registration Bundle + org.wso2.carbon.dynamic.client.registration.internal.DynamicClientRegistrationBundleActivator + org.wso2.carbon.dynamic.client.registration.internal + + !org.wso2.carbon.dynamic.client.registration.internal, + org.wso2.carbon.dynamic.client.registration.* + + * + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.testng + testng + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.wso2.carbon.identity + org.wso2.carbon.identity.application.mgt + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.api + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.impl + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.keymgt.client + + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth + + + com.googlecode.json-simple.wso2 + json-simple + + + org.json.wso2 + json + + + \ No newline at end of file diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/ApplicationConstants.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java similarity index 74% rename from components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/ApplicationConstants.java rename to components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java index ad160b6ff3..c326ee6af8 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/ApplicationConstants.java +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java @@ -1,23 +1,25 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. - * + * 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.identity.oauth.extension; +package org.wso2.carbon.dynamic.client.registration; +/** + * This class holds the constants used by DynamicClientRegistration component. + */ public final class ApplicationConstants { public static class ClientMetadata { diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationException.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationException.java new file mode 100644 index 0000000000..f01d817d71 --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationException.java @@ -0,0 +1,61 @@ +/* + * 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; + +/** + * Custom exception to be thrown inside DynamicClientRegistration related functionalities. + */ +public class DynamicClientRegistrationException extends Exception { + + private static final long serialVersionUID = -3151279311929070297L; + + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public DynamicClientRegistrationException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public DynamicClientRegistrationException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public DynamicClientRegistrationException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public DynamicClientRegistrationException() { + super(); + } + + public DynamicClientRegistrationException(Throwable cause) { + super(cause); + } + +} diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationService.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationService.java new file mode 100644 index 0000000000..e6aea31a71 --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationService.java @@ -0,0 +1,61 @@ +/* + * 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; + +import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; + +/** + * This class represents the interface to be implemented by DynamicClientRegistrationService. + */ +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 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; + +} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/OAuthApplicationInfo.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java similarity index 55% rename from components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/OAuthApplicationInfo.java rename to components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java index 3457b60d38..2eb570cb59 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/OAuthApplicationInfo.java +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java @@ -1,30 +1,30 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. - * + * 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.identity.oauth.extension; +package org.wso2.carbon.dynamic.client.registration; -import org.codehaus.jackson.map.ObjectMapper; import org.json.simple.JSONObject; -import java.io.IOException; import java.util.HashMap; import java.util.Map; +/** + * This class represents an OAuth application populated with necessary data. + */ public class OAuthApplicationInfo { private String clientId; @@ -86,12 +86,13 @@ public class OAuthApplicationInfo { } public String toString() { - ObjectMapper mapper = new ObjectMapper(); - try { - return mapper.writeValueAsString(this); - } catch (IOException e) { - throw new RuntimeException("Error occurred while serializing OAuthApplicationInfo bean"); - } + JSONObject obj = new JSONObject(); + obj.put(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_ID, this.getClientId()); + 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/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java similarity index 58% rename from components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java rename to components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java index c823323364..599619cfc1 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java @@ -1,31 +1,34 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. - * + * 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.identity.oauth.extension; + +package org.wso2.carbon.dynamic.client.registration.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.json.JSONObject; -import org.wso2.carbon.apimgt.api.APIManagementException; -import org.wso2.carbon.apimgt.impl.utils.APIUtil; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; +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.profile.RegistrationProfile; import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; import org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig; import org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig; @@ -37,22 +40,25 @@ import org.wso2.carbon.identity.oauth.OAuthAdminService; import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; -import org.wso2.carbon.identity.oauth.extension.profile.RegistrationProfile; - import java.util.Arrays; -public class DynamicClientRegistrationUtil { +/** + * Implementation of DynamicClientRegistrationService. + */ +public class DynamicClientRegistrationImpl implements DynamicClientRegistrationService { private static final String TOKEN_SCOPE = "tokenScope"; - private static final Log log = LogFactory.getLog(DynamicClientRegistrationUtil.class); + private static final Log log = LogFactory.getLog(DynamicClientRegistrationService.class); - public static OAuthApplicationInfo registerApplication(RegistrationProfile profile) throws APIManagementException { + @Override + public OAuthApplicationInfo registerOAuthApplication(RegistrationProfile profile) + throws DynamicClientRegistrationException { OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo(); String applicationName = profile.getClientName(); if (log.isDebugEnabled()) { - log.debug("Trying to create OAuth application: '" + applicationName + "'"); + log.debug("Trying to register OAuth application: '" + applicationName + "'"); } String tokenScope = profile.getTokenScope(); @@ -62,13 +68,15 @@ public class DynamicClientRegistrationUtil { oAuthApplicationInfo.addParameter(TOKEN_SCOPE, Arrays.toString(tokenScopes)); OAuthApplicationInfo info; try { - info = createOAuthApplication(profile); + info = this.createOAuthApplication(profile); } catch (Exception e) { - throw new APIManagementException("Can not create OAuth application : " + applicationName, e); + throw new DynamicClientRegistrationException( + "Can not create OAuth application : " + applicationName, e); } if (info == null || info.getJsonString() == null) { - throw new APIManagementException("OAuth app does not contain required data: '" + applicationName + "'"); + throw new DynamicClientRegistrationException( + "OAuth app does not contain required data: '" + applicationName + "'"); } oAuthApplicationInfo.setClientName(info.getClientName()); @@ -79,29 +87,37 @@ public class DynamicClientRegistrationUtil { try { JSONObject jsonObject = new JSONObject(info.getJsonString()); if (jsonObject.has(ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS)) { - oAuthApplicationInfo.addParameter(ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS, - jsonObject.get(ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS)); + oAuthApplicationInfo + .addParameter(ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS, + jsonObject + .get(ApplicationConstants.ClientMetadata. + OAUTH_REDIRECT_URIS)); } if (jsonObject.has(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_GRANT)) { oAuthApplicationInfo.addParameter(ApplicationConstants.ClientMetadata. - OAUTH_CLIENT_GRANT, jsonObject.get(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_GRANT)); + OAUTH_CLIENT_GRANT, jsonObject + .get(ApplicationConstants.ClientMetadata. + OAUTH_CLIENT_GRANT)); } } catch (JSONException e) { - throw new APIManagementException("Can not retrieve information of the created OAuth application", e); + throw new DynamicClientRegistrationException( + "Can not retrieve information of the created OAuth application", e); } return oAuthApplicationInfo; } - public static OAuthApplicationInfo createOAuthApplication( + private OAuthApplicationInfo createOAuthApplication( RegistrationProfile profile) - throws APIManagementException, IdentityException { + throws DynamicClientRegistrationException, IdentityException { - //Subscriber's name should be passed as a parameter, since it's under the subscriber the OAuth App is created. + //Subscriber's name should be passed as a parameter, since it's under the subscriber + //the OAuth App is created. String userId = profile.getOwner(); String applicationName = profile.getClientName(); String grantType = profile.getGrantType(); String callbackUrl = profile.getCallbackUrl(); + boolean isSaaSApp = profile.isSaasApp(); if (userId == null || userId.isEmpty()) { return null; @@ -125,20 +141,24 @@ public class DynamicClientRegistrationUtil { // Create the Service Provider ServiceProvider serviceProvider = new ServiceProvider(); serviceProvider.setApplicationName(applicationName); + serviceProvider.setDescription("Service Provider for application " + applicationName); ApplicationManagementService appMgtService = ApplicationManagementService.getInstance(); if (appMgtService == null) { - throw new IllegalStateException("Error occurred while retrieving Application Management" + + throw new IllegalStateException( + "Error occurred while retrieving Application Management" + "Service"); } appMgtService.createApplication(serviceProvider); ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName); if (createdServiceProvider == null) { - throw new APIManagementException("Couldn't create Service Provider Application " + applicationName); + throw new DynamicClientRegistrationException( + "Couldn't create Service Provider Application " + applicationName); } - + //Set SaaS app option + createdServiceProvider.setSaasApp(isSaaSApp); // Then Create OAuthApp OAuthAdminService oAuthAdminService = new OAuthAdminService(); @@ -155,13 +175,15 @@ public class DynamicClientRegistrationUtil { log.debug("Created OAuth App " + applicationName); } - OAuthConsumerAppDTO createdApp = oAuthAdminService.getOAuthApplicationDataByAppName(oAuthConsumerAppDTO - .getApplicationName()); + OAuthConsumerAppDTO createdApp = + oAuthAdminService.getOAuthApplicationDataByAppName(oAuthConsumerAppDTO + .getApplicationName()); if (log.isDebugEnabled()) { log.debug("Retrieved Details for OAuth App " + createdApp.getApplicationName()); } // Set the OAuthApp in InboundAuthenticationConfig - InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig(); + InboundAuthenticationConfig inboundAuthenticationConfig = + new InboundAuthenticationConfig(); InboundAuthenticationRequestConfig[] inboundAuthenticationRequestConfigs = new InboundAuthenticationRequestConfig[1]; InboundAuthenticationRequestConfig inboundAuthenticationRequestConfig = new @@ -170,16 +192,18 @@ public class DynamicClientRegistrationUtil { inboundAuthenticationRequestConfig.setInboundAuthKey(createdApp.getOauthConsumerKey()); inboundAuthenticationRequestConfig.setInboundAuthType("oauth2"); if (createdApp.getOauthConsumerSecret() != null && !createdApp. - getOauthConsumerSecret().isEmpty()) { + getOauthConsumerSecret() + .isEmpty()) { Property property = new Property(); property.setName("oauthConsumerSecret"); property.setValue(createdApp.getOauthConsumerSecret()); - Property[] properties = {property}; + Property[] properties = { property }; inboundAuthenticationRequestConfig.setProperties(properties); } inboundAuthenticationRequestConfigs[0] = inboundAuthenticationRequestConfig; - inboundAuthenticationConfig.setInboundAuthenticationRequestConfigs(inboundAuthenticationRequestConfigs); + inboundAuthenticationConfig + .setInboundAuthenticationRequestConfigs(inboundAuthenticationRequestConfigs); createdServiceProvider.setInboundAuthenticationConfig(inboundAuthenticationConfig); // Update the Service Provider app to add OAuthApp as an Inbound Authentication Config @@ -192,23 +216,29 @@ public class DynamicClientRegistrationUtil { oAuthApplicationInfo.setClientName(createdApp.getApplicationName()); oAuthApplicationInfo.addParameter( - ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS, createdApp.getCallbackUrl()); + ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS, + createdApp.getCallbackUrl()); oAuthApplicationInfo.addParameter( - ApplicationConstants.ClientMetadata.OAUTH_CLIENT_GRANT, createdApp.getGrantTypes()); + ApplicationConstants.ClientMetadata.OAUTH_CLIENT_GRANT, + createdApp.getGrantTypes()); return oAuthApplicationInfo; } catch (IdentityApplicationManagementException e) { - APIUtil.handleException("Error occurred while creating ServiceProvider for app " + applicationName, e); + throw new DynamicClientRegistrationException( + "Error occurred while creating ServiceProvider for app " + applicationName, e); } catch (Exception e) { - APIUtil.handleException("Error occurred while creating OAuthApp " + applicationName, e); + throw new DynamicClientRegistrationException( + "Error occurred while creating OAuthApp " + applicationName, e); } finally { PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(baseUser); } - return null; } - public static void unregisterApplication(String userId, String applicationName, - String consumerKey) throws APIManagementException { + @Override + public boolean unregisterOAuthApplication(String userId, String applicationName, + String consumerKey) + throws DynamicClientRegistrationException { + boolean status = false; String tenantDomain = MultitenantUtils.getTenantDomain(userId); String baseUser = CarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = MultitenantUtils.getTenantAwareUsername(userId); @@ -218,15 +248,18 @@ public class DynamicClientRegistrationUtil { PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName); if (userId == null || userId.isEmpty()) { - throw new APIManagementException("Error occurred while unregistering Application: userId cannot " + + throw new DynamicClientRegistrationException( + "Error occurred while unregistering Application: userId cannot " + "be null/empty"); } try { OAuthAdminService oAuthAdminService = new OAuthAdminService(); - OAuthConsumerAppDTO oAuthConsumerAppDTO = oAuthAdminService.getOAuthApplicationData(consumerKey); + OAuthConsumerAppDTO oAuthConsumerAppDTO = + oAuthAdminService.getOAuthApplicationData(consumerKey); if (oAuthConsumerAppDTO == null) { - throw new APIManagementException("Couldn't retrieve OAuth Consumer Application associated with the " + + throw new DynamicClientRegistrationException( + "Couldn't retrieve OAuth Consumer Application associated with the " + "given consumer key: " + consumerKey); } oAuthAdminService.removeOAuthApplicationData(consumerKey); @@ -234,24 +267,49 @@ public class DynamicClientRegistrationUtil { ApplicationManagementService appMgtService = ApplicationManagementService.getInstance(); if (appMgtService == null) { - throw new IllegalStateException("Error occurred while retrieving Application Management" + + throw new IllegalStateException( + "Error occurred while retrieving Application Management" + "Service"); } ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName); if (createdServiceProvider == null) { - throw new APIManagementException("Couldn't retrieve Service Provider Application " + applicationName); + throw new DynamicClientRegistrationException( + "Couldn't retrieve Service Provider Application " + applicationName); } appMgtService.deleteApplication(applicationName); - + status = true; } catch (IdentityApplicationManagementException e) { - APIUtil.handleException("Error occurred while removing ServiceProvider for app " + applicationName, e); + throw new DynamicClientRegistrationException( + "Error occurred while removing ServiceProvider for app " + applicationName, e); } catch (Exception e) { - APIUtil.handleException("Error occurred while removing OAuthApp " + applicationName, e); + throw new DynamicClientRegistrationException( + "Error occurred while removing OAuthApp " + applicationName, e); } finally { PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(baseUser); } + return status; } + @Override + public boolean isOAuthApplicationExists(String applicationName) + throws DynamicClientRegistrationException { + ApplicationManagementService appMgtService = ApplicationManagementService.getInstance(); + if (appMgtService == null) { + throw new IllegalStateException( + "Error occurred while retrieving Application Management" + + "Service"); + } + try { + if (appMgtService.getApplication(applicationName) != null) { + return true; + } + } catch (IdentityApplicationManagementException e) { + throw new DynamicClientRegistrationException( + "Error occurred while retrieving information of OAuthApp " + applicationName, + e); + } + return false; + } } diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java new file mode 100644 index 0000000000..e3ae13e4df --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/internal/DynamicClientRegistrationBundleActivator.java @@ -0,0 +1,44 @@ +/* + * 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.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService; +import org.wso2.carbon.dynamic.client.registration.impl.DynamicClientRegistrationImpl; + +/** + * BundleActivator class of DynamicClientRegistration component. + */ +public class DynamicClientRegistrationBundleActivator implements BundleActivator{ + + @Override + public void start(BundleContext bundleContext) throws Exception { + DynamicClientRegistrationService dynamicClientRegistrationService = + new DynamicClientRegistrationImpl(); + bundleContext.registerService(DynamicClientRegistrationService.class.getName(), + dynamicClientRegistrationService, null); + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + + } + +} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/RegistrationProfile.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java similarity index 79% rename from components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/RegistrationProfile.java rename to components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java index 25a760ab25..8f8286ba68 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/RegistrationProfile.java +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java @@ -1,23 +1,27 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. - * + * 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.identity.oauth.extension.profile; +package org.wso2.carbon.dynamic.client.registration.profile; +/** + * + * DTO class to be used when registering a OAuth application. + * +* */ public class RegistrationProfile { private String applicationType; @@ -36,6 +40,15 @@ public class RegistrationProfile { private String callbackUrl; private String tokenScope; private String grantType; + private boolean saasApp; + + public boolean isSaasApp() { + return saasApp; + } + + public void setSaasApp(boolean saasApp) { + this.saasApp = saasApp; + } public String getApplicationType() { return applicationType; diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml new file mode 100644 index 0000000000..1e5d699887 --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml @@ -0,0 +1,127 @@ + + + + + + dynamic-client-registration + org.wso2.carbon.devicemgt + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.dynamic.client.web.app.registration + 0.9.2-SNAPSHOT + bundle + WSO2 Carbon - Dynamic client web app registration + WSO2 Carbon - Dynamic Client Web-app Registration Service + http://wso2.org + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Dynamic Client Web App Registration Bundle + org.wso2.carbon.dynamic.client.web.app.registration.internal + + !org.wso2.carbon.dynamic.client.web.app.registration.internal, + org.wso2.carbon.dynamic.client.web.app.registration.* + + * + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.testng + testng + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.wso2.carbon.identity + org.wso2.carbon.identity.application.mgt + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.api + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.impl + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.keymgt.client + + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth + + + org.wso2.tomcat + tomcat + + + org.wso2.tomcat + tomcat-servlet-api + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.user.core + + + org.wso2.carbon + org.wso2.carbon.registry.core + + + org.wso2.carbon.devicemgt + org.wso2.carbon.dynamic.client.registration + + + \ No newline at end of file diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java new file mode 100644 index 0000000000..cbe973aae3 --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicRegistrationManager.java @@ -0,0 +1,90 @@ +/* + * 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.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.internal.DynamicClientRegistrationDataHolder; +import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil; + +/** + * This class contains the logic to handle the OAuth application creation process. + */ +public class DynamicRegistrationManager { + + private static DynamicRegistrationManager dynamicRegistrationManager; + private static final Log log = + LogFactory.getLog(DynamicRegistrationManager.class); + + private DynamicRegistrationManager() { + } + + public static DynamicRegistrationManager getInstance() { + if (dynamicRegistrationManager == null) { + synchronized (DynamicRegistrationManager.class) { + if (dynamicRegistrationManager == null) { + dynamicRegistrationManager = new DynamicRegistrationManager(); + } + } + } + return dynamicRegistrationManager; + } + + public boolean registerOAuthApplication(RegistrationProfile registrationProfile) { + DynamicClientRegistrationService dynamicClientRegistrationService = + DynamicClientRegistrationDataHolder.getInstance() + .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()); + //store it in registry + return DynamicClientWebAppRegistrationUtil.putOAuthApplicationData(oAuthApp); + } catch (DynamicClientRegistrationException e) { + log.error("Error occurred while registering the OAuth application.",e); + } + return false; + } + + public OAuthApp 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(); + } + + public boolean isRegisteredOAuthApplication(String clientName) { + OAuthApp oAuthApp = this.getOAuthApplicationData(clientName); + if (oAuthApp.getClientKey() != null && oAuthApp.getClientSecret() != null) { + return true; + } + return false; + } + +} diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthApp.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthApp.java new file mode 100644 index 0000000000..ec8ea8e762 --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/OAuthApp.java @@ -0,0 +1,70 @@ +/* + * 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 javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Represents a OAuth application with basic data. + */ +@XmlRootElement(name = "OAuthApp") +public class OAuthApp { + + private String clientName; + private String clientKey; + private String clientSecret; + private String webAppName; + + @XmlElement(name = "clientName", required = true) + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + @XmlElement(name = "clientKey", required = false) + public String getClientKey() { + return clientKey; + } + + public void setClientKey(String clientKey) { + this.clientKey = clientKey; + } + + @XmlElement(name = "clientSecret", required = false) + public String getClientSecret() { + return clientSecret; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + + @XmlElement(name = "webAppName", required = true) + public String getWebAppName() { + return webAppName; + } + + public void setWebAppName(String webAppName) { + this.webAppName = webAppName; + } +} diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java new file mode 100644 index 0000000000..5d8cf806cd --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientRegistrationDataHolder.java @@ -0,0 +1,66 @@ +/* + * 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.internal; + +import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService; +import org.wso2.carbon.registry.core.service.RegistryService; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * Dataholder class of DynamicClient Webapp Registration component. + */ +public class DynamicClientRegistrationDataHolder { + + private RealmService realmService; + private RegistryService registryService; + private DynamicClientRegistrationService dynamicClientRegistrationService; + + public DynamicClientRegistrationService getDynamicClientRegistrationService() { + return dynamicClientRegistrationService; + } + + public void setDynamicClientRegistrationService( + DynamicClientRegistrationService dynamicClientRegistrationService) { + this.dynamicClientRegistrationService = dynamicClientRegistrationService; + } + + private static DynamicClientRegistrationDataHolder thisInstance = new DynamicClientRegistrationDataHolder(); + + private DynamicClientRegistrationDataHolder() {} + + public static DynamicClientRegistrationDataHolder getInstance() { + return thisInstance; + } + + public RealmService getRealmService() { + return realmService; + } + + public void setRealmService(RealmService realmService) { + this.realmService = realmService; + } + + public RegistryService getRegistryService() { + return registryService; + } + + public void setRegistryService(RegistryService registryService) { + this.registryService = registryService; + } +} diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java b/components/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 new file mode 100644 index 0000000000..84572e93cb --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/internal/DynamicClientWebAppRegistrationServiceComponent.java @@ -0,0 +1,136 @@ +/* + * 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.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService; +import org.wso2.carbon.registry.core.service.RegistryService; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * @scr.component name="org.wso2.carbon.device.manager" immediate="true" + * @scr.reference name="user.realmservice.default" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + * @scr.reference name="registry.service" + * interface="org.wso2.carbon.registry.core.service.RegistryService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRegistryService" + * unbind="unsetRegistryService" + * @scr.reference name="dynamic.client.service" + * interface="org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDynamicClientService" + * unbind="unsetDynamicClientService" + */ +public class DynamicClientWebAppRegistrationServiceComponent { + + private static Log log = LogFactory.getLog(DynamicClientWebAppRegistrationServiceComponent.class); + + @SuppressWarnings("unused") + protected void activate(ComponentContext componentContext) { + + } + + @SuppressWarnings("unused") + protected void deactivate(ComponentContext componentContext) { + //do nothing + } + + /** + * Sets Realm Service. + * + * @param realmService An instance of RealmService + */ + protected void setRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Setting Realm Service"); + } + DynamicClientRegistrationDataHolder.getInstance().setRealmService(realmService); + } + + /** + * Unsets Realm Service. + * + * @param realmService An instance of RealmService + */ + protected void unsetRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Realm Service"); + } + DynamicClientRegistrationDataHolder.getInstance().setRealmService(null); + } + + /** + * Sets Registry Service. + * + * @param registryService An instance of RegistryService + */ + protected void setRegistryService(RegistryService registryService) { + if (log.isDebugEnabled()) { + log.debug("Setting Registry Service"); + } + DynamicClientRegistrationDataHolder.getInstance().setRegistryService(registryService); + } + + /** + * Unsets Registry Service. + * + * @param registryService An instance of RegistryService + */ + protected void unsetRegistryService(RegistryService registryService) { + if (log.isDebugEnabled()) { + log.debug("Un setting Registry Service"); + } + DynamicClientRegistrationDataHolder.getInstance().setRegistryService(null); + } + + /** + * Sets Dynamic Client Registration Service. + * + * @param dynamicClientRegistrationService An instance of DynamicClientRegistrationService + */ + protected void setDynamicClientService(DynamicClientRegistrationService dynamicClientRegistrationService) { + if (log.isDebugEnabled()) { + log.debug("Setting Dynamic Client Registration Service"); + } + DynamicClientRegistrationDataHolder.getInstance().setDynamicClientRegistrationService( + dynamicClientRegistrationService); + } + + /** + * Unsets Dynamic Client Registration Service. + * + * @param dynamicClientRegistrationService An instance of DynamicClientRegistrationService + */ + protected void unsetDynamicClientService(DynamicClientRegistrationService dynamicClientRegistrationService) { + if (log.isDebugEnabled()) { + log.debug("Un setting Dynamic Client Registration Service"); + } + DynamicClientRegistrationDataHolder.getInstance().setDynamicClientRegistrationService(null); + } + +} diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java b/components/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 new file mode 100644 index 0000000000..32c3d1c382 --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/listner/DynamicClientWebAppDeploymentLifecycleListener.java @@ -0,0 +1,70 @@ +/* + * 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.listner; + +import org.apache.catalina.Lifecycle; +import org.apache.catalina.LifecycleEvent; +import org.apache.catalina.LifecycleListener; +import org.apache.catalina.core.StandardContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException; +import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; +import org.wso2.carbon.dynamic.client.web.app.registration.DynamicRegistrationManager; +import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientRegistrationConstants; +import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil; + +import javax.servlet.ServletContext; + +/** + * This class initiates the dynamic client registration flow for Web applications upon on deployment + * of the web application. + */ +@SuppressWarnings("unused") +public class DynamicClientWebAppDeploymentLifecycleListener implements LifecycleListener { + + private static final Log log = + LogFactory.getLog(DynamicClientWebAppDeploymentLifecycleListener.class); + + @Override + public void lifecycleEvent(LifecycleEvent lifecycleEvent) { + if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType())) { + StandardContext context = (StandardContext) lifecycleEvent.getLifecycle(); + ServletContext servletContext = context.getServletContext(); + String requiredDynamicClientRegistration = servletContext.getInitParameter( + DynamicClientRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG_PARAM); + if ((requiredDynamicClientRegistration != null) && + (Boolean.parseBoolean(requiredDynamicClientRegistration))) { + DynamicRegistrationManager dynamicRegistrationManager = + DynamicRegistrationManager.getInstance(); + //Get the application name from web-context + String webAppName = context.getBaseName(); + if (!dynamicRegistrationManager.isRegisteredOAuthApplication(webAppName)) { + RegistrationProfile registrationProfile = DynamicClientWebAppRegistrationUtil + .constructRegistrationProfile(servletContext, webAppName); + if(DynamicClientWebAppRegistrationUtil.validateRegistrationProfile(registrationProfile)){ + dynamicRegistrationManager.registerOAuthApplication(registrationProfile); + } + } + } else { + //TODO: Need to have the necessary logic to handle jaggery webapp scenario + } + } + } +} diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java new file mode 100644 index 0000000000..7b8169d486 --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientRegistrationConstants.java @@ -0,0 +1,49 @@ +/* + * 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.util; + +/** + * Holds the constants to be used in Dynamic client web app registration component. + */ +public class DynamicClientRegistrationConstants { + + public final static String OAUTH_APP_DATA_REGISTRY_PATH = "/OAuth"; + public final static String OAUTH_APP_NAME = "appName"; + public final static String OAUTH_CLIENT_KEY = "clientKey"; + public final static String OAUTH_CLIENT_SECRET = "clientSecret"; + public final static String DYNAMIC_CLIENT_REQUIRED_FLAG_PARAM = + "require-dynamic-client-registration"; + + public static final class ContentTypes { + private ContentTypes() { + throw new AssertionError(); + } + + public static final String CONTENT_TYPE_ANY = "*/*"; + public static final String MEDIA_TYPE_XML = "application/xml"; + } + + public static final class CharSets { + private CharSets() { + throw new AssertionError(); + } + + public static final String CHARSET_UTF8 = "UTF8"; + } +} diff --git a/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java b/components/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 new file mode 100644 index 0000000000..8977faefee --- /dev/null +++ b/components/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java @@ -0,0 +1,196 @@ +/* + * 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.util; + +import org.apache.commons.logging.Log; +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.internal.DynamicClientRegistrationDataHolder; +import org.wso2.carbon.registry.api.RegistryException; +import org.wso2.carbon.registry.api.Resource; +import org.wso2.carbon.registry.core.Registry; +import org.wso2.carbon.user.core.service.RealmService; +import org.wso2.carbon.utils.CarbonUtils; + +import javax.servlet.ServletContext; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import java.io.StringReader; +import java.io.StringWriter; +import java.nio.charset.Charset; + +/** + * Holds the utility methods to be used in Dynamic client web app registration component. + */ +public class DynamicClientWebAppRegistrationUtil { + + private final static String OAUTH_PARAM_GRANT_TYPE = "grant-type"; + private final static String OAUTH_PARAM_TOKEN_SCOPE = "token-scope"; + private final static String SP_PARAM_SAAS_APP = "saas-app"; + + private static final Log log = + LogFactory.getLog(DynamicClientWebAppRegistrationUtil.class); + + public static Registry getGovernanceRegistry() throws DynamicClientRegistrationException { + try { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + return DynamicClientRegistrationDataHolder.getInstance().getRegistryService() + .getGovernanceSystemRegistry( + tenantId); + } catch (RegistryException e) { + throw new DynamicClientRegistrationException( + "Error in retrieving governance registry instance: " + + e.getMessage(), e); + } + } + + public static OAuthApp getOAuthApplicationData(String appName) + throws DynamicClientRegistrationException { + Resource resource; + String resourcePath = DynamicClientRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + appName; + try { + resource = DynamicClientWebAppRegistrationUtil.getRegistryResource(resourcePath); + if (resource != null) { + JAXBContext context = JAXBContext.newInstance(OAuthApp.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + return (OAuthApp) unmarshaller.unmarshal( + new StringReader(new String((byte[]) resource.getContent(), Charset + .forName( + DynamicClientRegistrationConstants.CharSets.CHARSET_UTF8)))); + } + return new OAuthApp(); + } catch (JAXBException e) { + throw new DynamicClientRegistrationException( + "Error occurred while parsing the OAuth application data : " + appName, e); + } catch (RegistryException e) { + throw new DynamicClientRegistrationException( + "Error occurred while retrieving the Registry resource of OAuth application : " + + appName, e); + } + } + + public static boolean putOAuthApplicationData(OAuthApp oAuthApp) + throws DynamicClientRegistrationException { + boolean status = false; + try { + if (log.isDebugEnabled()) { + log.debug("Persisting OAuth application data in Registry"); + } + StringWriter writer = new StringWriter(); + JAXBContext context = JAXBContext.newInstance(OAuthApp.class); + Marshaller marshaller = context.createMarshaller(); + marshaller.marshal(oAuthApp, writer); + + Resource resource = DynamicClientWebAppRegistrationUtil.getGovernanceRegistry().newResource(); + resource.setContent(writer.toString()); + resource.setMediaType(DynamicClientRegistrationConstants.ContentTypes.MEDIA_TYPE_XML); + String resourcePath = + DynamicClientRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + + oAuthApp.getWebAppName(); + status = DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource); + } catch (RegistryException e) { + throw new DynamicClientRegistrationException( + "Error occurred while persisting OAuth application data : " + + oAuthApp.getClientName(), e); + } catch (JAXBException e) { + e.printStackTrace(); + } + return status; + } + + public static boolean putRegistryResource(String path, + Resource resource) + throws DynamicClientRegistrationException { + boolean status; + try { + Registry governanceRegistry = DynamicClientWebAppRegistrationUtil + .getGovernanceRegistry(); + governanceRegistry.beginTransaction(); + governanceRegistry.put(path, resource); + governanceRegistry.commitTransaction(); + status = true; + } catch (RegistryException e) { + throw new DynamicClientRegistrationException( + "Error occurred while persisting registry resource : " + + e.getMessage(), e); + } + return status; + } + + public static Resource getRegistryResource(String path) + throws DynamicClientRegistrationException { + try { + Registry governanceRegistry = DynamicClientWebAppRegistrationUtil + .getGovernanceRegistry(); + if (governanceRegistry.resourceExists(path)) { + return governanceRegistry.get(path); + } + return null; + } catch (RegistryException e) { + throw new DynamicClientRegistrationException( + "Error in retrieving registry resource : " + + e.getMessage(), e); + } + } + + public static String getUserName(){ + String username = ""; + RealmService realmService = + DynamicClientRegistrationDataHolder.getInstance().getRealmService(); + if(realmService != null){ + username = realmService.getBootstrapRealmConfiguration().getAdminUserName(); + } + return username; + } + + public static RegistrationProfile constructRegistrationProfile(ServletContext servletContext, String webAppName) { + RegistrationProfile registrationProfile = new RegistrationProfile(); + registrationProfile.setGrantType(servletContext.getInitParameter( + DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_GRANT_TYPE)); + registrationProfile.setTokenScope(servletContext.getInitParameter( + DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_TOKEN_SCOPE)); + registrationProfile.setOwner(DynamicClientWebAppRegistrationUtil.getUserName()); + //TODO : Need to get the hostname properly + registrationProfile.setCallbackUrl("http://localhost:9763/" + webAppName); + registrationProfile.setClientName(webAppName); + registrationProfile.setSaasApp(Boolean.parseBoolean(servletContext.getInitParameter( + DynamicClientWebAppRegistrationUtil.SP_PARAM_SAAS_APP))); + return registrationProfile; + } + + public static boolean validateRegistrationProfile(RegistrationProfile registrationProfile) { + boolean status = true; + if(registrationProfile.getGrantType() == null){ + status = false; + log.warn("Required parameter 'grant-type' is missing for initiating Dynamic-Client " + + "registration for webapp : " + registrationProfile.getClientName()); + } + if(registrationProfile.getTokenScope() == null){ + status = false; + log.warn("Required parameter 'token-scope' is missing for initiating Dynamic-Client " + + "registration for webapp : " + registrationProfile.getClientName()); + } + return status; + } +} diff --git a/components/oauth-extensions/pom.xml b/components/dynamic-client-registration/pom.xml similarity index 57% rename from components/oauth-extensions/pom.xml rename to components/dynamic-client-registration/pom.xml index 7b9aa75794..95cd219a42 100644 --- a/components/oauth-extensions/pom.xml +++ b/components/dynamic-client-registration/pom.xml @@ -1,21 +1,21 @@ + ~ 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. + --> @@ -28,14 +28,16 @@ 4.0.0 org.wso2.carbon.devicemgt - oauth-extensions + dynamic-client-registration 0.9.2-SNAPSHOT pom - WSO2 Carbon - OAuth Extensions + WSO2 Carbon - Dynamic Client Registration Component http://wso2.org - dynamic-client-manager + org.wso2.carbon.dynamic.client.registration + org.wso2.carbon.dynamic.client.web.app.registration + dynamic-client-web diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/ConfigurationService.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/ConfigurationService.java deleted file mode 100644 index 032f090a1d..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/ConfigurationService.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.identity.oauth.extension; - -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -@Path("/connect") -public interface ConfigurationService { - - @GET - @Path("/register") - Response getProfile(@PathParam("client_id") String clientId); - -} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/FaultResponse.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/FaultResponse.java deleted file mode 100644 index 5e71a41237..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/FaultResponse.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.identity.oauth.extension; - -public class FaultResponse { - - private RegistrationService.ErrorCode code; - private String description; - - public FaultResponse(RegistrationService.ErrorCode code, String description) { - this.code = code; - this.description = description; - } - - public RegistrationService.ErrorCode getCode() { - return code; - } - - public String getDescription() { - return description; - } - -} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationResponse.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationResponse.java deleted file mode 100644 index 23d60a8f11..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationResponse.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.identity.oauth.extension; - -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; - -public class RegistrationResponse extends Response { - - @Override - public Object getEntity() { - return null; - } - - @Override - public int getStatus() { - return 0; - } - - @Override - public MultivaluedMap getMetadata() { - return null; - } - -} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ConfigurationServiceImpl.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ConfigurationServiceImpl.java deleted file mode 100644 index 840e0ee935..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ConfigurationServiceImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.identity.oauth.extension.impl; - -import org.wso2.carbon.identity.oauth.extension.ConfigurationService; - -import javax.ws.rs.PathParam; -import javax.ws.rs.core.Response; - -public class ConfigurationServiceImpl implements ConfigurationService { - - @Override - public Response getProfile(@PathParam("client_id") String clientId) { - return null; - } - -} \ No newline at end of file diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java deleted file mode 100644 index 2fdb539988..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.identity.oauth.extension.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.apimgt.api.APIManagementException; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.oauth.extension.DynamicClientRegistrationUtil; -import org.wso2.carbon.identity.oauth.extension.FaultResponse; -import org.wso2.carbon.identity.oauth.extension.OAuthApplicationInfo; -import org.wso2.carbon.identity.oauth.extension.RegistrationService; -import org.wso2.carbon.identity.oauth.extension.profile.RegistrationProfile; -import org.wso2.carbon.utils.multitenancy.MultitenantConstants; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.QueryParam; - -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class RegistrationServiceImpl implements RegistrationService { - - private static final Log log = LogFactory.getLog(RegistrationServiceImpl.class); - - @POST - @Override - public Response register(RegistrationProfile profile) { - try { - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( - MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); - - OAuthApplicationInfo info = DynamicClientRegistrationUtil.registerApplication(profile); - return Response.status(Response.Status.ACCEPTED).entity(info.toString()).build(); - } catch (APIManagementException e) { - String msg = "Error occurred while registering client '" + profile.getClientName() + "'"; - log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).entity( - new FaultResponse(ErrorCode.INVALID_CLIENT_METADATA, msg)).build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - @DELETE - @Override - public Response unregister(@QueryParam("applicationName") String applicationName, - @QueryParam("userId") String userId, - @QueryParam("consumerKey") String consumerKey) { - try { - DynamicClientRegistrationUtil.unregisterApplication(userId, applicationName, consumerKey); - return Response.status(Response.Status.ACCEPTED).build(); - } catch (APIManagementException e) { - String msg = "Error occurred while un-registering client '" + applicationName + "'"; - log.error(msg, e); - return Response.serverError().entity(new FaultResponse(ErrorCode.INVALID_CLIENT_METADATA, msg)).build(); - } - } - -} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/resources/device-info-response.xml b/components/oauth-extensions/dynamic-client-manager/src/main/resources/device-info-response.xml deleted file mode 100644 index 7468d847ba..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/resources/device-info-response.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - 1.2 - DM/1.2 - 1 - 1 - - TARGET_URI - - - SOURCE_URI - - - - - 1 - 1 - 0 - SyncHdr - TARGET_URI - 212 - - - 2 - 1 - 2 - Alert - 200 - - - 3 - 1 - 3 - Replace - ./devinf12 - 200 - - - 75 - - - ./DevDetail/SwV - - - - - ./Vendor/MSFT/DeviceInstanceService/Identity/Identity1/IMSI - - - - - ./Vendor/MSFT/DeviceInstanceService/Identity/Identity1/IMEI - - - - - ./DevInfo/DevId - - - - - ./DevInfo/Man - - - - - ./DevInfo/Mod - - - - - ./DevInfo/Lang - - - - - 5 - - - ./Vendor/MSFT/RemoteRing/Ring - - - - - \ No newline at end of file diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/resources/properties.xml b/components/oauth-extensions/dynamic-client-manager/src/main/resources/properties.xml deleted file mode 100644 index 63b0686e0e..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/resources/properties.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - Federated - wso2carbon - cacert - CN=mdmcn - 3 - 300 - \ No newline at end of file diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/resources/syncml-session-ending-response.xml b/components/oauth-extensions/dynamic-client-manager/src/main/resources/syncml-session-ending-response.xml deleted file mode 100644 index ae3f93bb87..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/resources/syncml-session-ending-response.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - 1.2 - DM/1.2 - 1 - 2 - - TARGET_URI - - - SOURCE_URI - - - - - 1 - 1 - 0 - SyncHdr - TARGET_URI - 212 - - - \ No newline at end of file diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/resources/syncml-test-message.xml b/components/oauth-extensions/dynamic-client-manager/src/main/resources/syncml-test-message.xml deleted file mode 100644 index 1e015d436d..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/resources/syncml-test-message.xml +++ /dev/null @@ -1 +0,0 @@ -1.2DM/1.211https://EnterpriseEnrollment.wso2.com/Synchml/initialqueryurn:uuid:FAEFB2D5-1771-5446-A635-797AFC474895dummyb64syncml:auth-md5Zp3sdCvijPGIQ6JxuIJHlQ==212013175./DevDetail/SwV8.10.12397.8953./DevInfo/DevIdurn:uuid:FAEFB2D5-1771-5446-A635-797AFC474895./DevInfo/ManNOKIA./DevInfo/ModLumia 630./DevInfo/DmV1.3./DevInfo/Langen-GB \ No newline at end of file diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/resources/wap-provisioning.xml b/components/oauth-extensions/dynamic-client-manager/src/main/resources/wap-provisioning.xml deleted file mode 100644 index 896b451255..0000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/resources/wap-provisioning.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/resources/wso2mdm.jks b/components/oauth-extensions/dynamic-client-manager/src/main/resources/wso2mdm.jks deleted file mode 100644 index 66b68ea395..0000000000 Binary files a/components/oauth-extensions/dynamic-client-manager/src/main/resources/wso2mdm.jks and /dev/null differ diff --git a/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/log4j.properties b/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/log4j.properties deleted file mode 100644 index 7da6d6c9e1..0000000000 --- a/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/log4j.properties +++ /dev/null @@ -1,32 +0,0 @@ -# -# Copyright 2009 WSO2, Inc. (http://wso2.com) -# -# Licensed 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. -# - -# -# This is the log4j configuration file used by WSO2 Carbon -# -# IMPORTANT : Please do not remove or change the names of any -# of the Appenders defined here. The layout pattern & log file -# can be changed using the WSO2 Carbon Management Console, and those -# settings will override the settings in this file. -# - -log4j.rootLogger=DEBUG, STD_OUT - -# Redirect log messages to console -log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender -log4j.appender.STD_OUT.Target=System.out -log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout -log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/testng.xml b/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/testng.xml deleted file mode 100644 index 4da53d1247..0000000000 --- a/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/testng.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java index 974480fd5a..e359375eb3 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java @@ -28,6 +28,8 @@ import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.tomcat.util.buf.ByteChunk; +import org.apache.tomcat.util.buf.MessageBytes; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.core.util.KeyStoreManager; import org.wso2.carbon.user.api.TenantManager; @@ -35,11 +37,13 @@ import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; +import org.wso2.carbon.webapp.authenticator.framework.Constants; import org.wso2.carbon.webapp.authenticator.framework.DataHolder; import java.security.interfaces.RSAPublicKey; import java.text.ParseException; import java.util.StringTokenizer; +import java.util.regex.Matcher; /** * This authenticator authenticates HTTP requests using JWT header. @@ -52,7 +56,11 @@ public class JWTAuthenticator implements WebappAuthenticator { @Override public boolean canHandle(Request request) { - return false; + String authorizationHeader = request.getHeader(HTTPConstants.HEADER_AUTHORIZATION); + if(decodeAuthorizationHeader(authorizationHeader) != null){ + return true; + } + return false; } @Override diff --git a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml b/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/pom.xml similarity index 69% rename from features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml rename to features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/pom.xml index eae36b42e9..3f55389989 100644 --- a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml +++ b/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/pom.xml @@ -23,19 +23,37 @@ org.wso2.carbon.devicemgt - oauth-extentions-feature + dynamic-client-registration-feature 0.9.2-SNAPSHOT ../pom.xml 4.0.0 - org.wso2.carbon.oauth.extensions.server.feature + org.wso2.carbon.dynamic.client.registration.server.feature pom 0.9.2-SNAPSHOT - WSO2 Carbon - Oauth Extensions Server Feature + WSO2 Carbon - Dynamic Client Registration Server Feature http://wso2.org - This feature contains oauth functionality - + This feature contains dynamic client registration features + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.dynamic.client.registration + + + org.wso2.carbon.devicemgt + org.wso2.carbon.dynamic.client.web.app.registration + + + com.googlecode.json-simple.wso2 + json-simple + + + org.json.wso2 + json + + @@ -80,12 +98,12 @@ org.wso2.mdm - dynamic-client-manager - ${project.version} + dynamic-client-web + ${carbon.device.mgt.version} war true ${basedir}/src/main/resources/ - dynamic-client-manager.war + dynamic-client-web.war @@ -105,7 +123,7 @@ p2-feature-gen - org.wso2.carbon.oauth.extensions.server + org.wso2.carbon.dynamic.client.registration.server ../../../features/etc/feature.properties @@ -113,6 +131,20 @@ org.eclipse.equinox.p2.type.group:false + + + org.wso2.carbon.devicemgt:org.wso2.carbon.dynamic.client.registration:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:org.wso2.carbon.dynamic.client.web.app.registration:${carbon.device.mgt.version} + + + com.googlecode.json-simple.wso2:json-simple:${json-simple.version} + + + org.json.wso2:json:${json.wso2.version} + + org.wso2.carbon.core.server:${carbon.kernel.version} diff --git a/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/src/main/resources/p2.inf b/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..0f2ca3fd11 --- /dev/null +++ b/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/src/main/resources/p2.inf @@ -0,0 +1,2 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.dynamic.client.registration.server_${feature.version}/dynamic-client-web.war,target:${installFolder}/../../deployment/server/webapps/dynamic-client-web.war,overwrite:true);\ \ No newline at end of file diff --git a/features/oauth-extensions/pom.xml b/features/dynamic-client-registration/pom.xml similarity index 86% rename from features/oauth-extensions/pom.xml rename to features/dynamic-client-registration/pom.xml index 87ed9a7ef0..2df634c5b2 100644 --- a/features/oauth-extensions/pom.xml +++ b/features/dynamic-client-registration/pom.xml @@ -29,14 +29,14 @@ 4.0.0 org.wso2.carbon.devicemgt - oauth-extentions-feature + dynamic-client-registration-feature 0.9.2-SNAPSHOT pom - WSO2 Carbon - Policy Management Feature + WSO2 Carbon - Dynamic Client Registration Feature http://wso2.org - org.wso2.carbon.oauth.extensions.server.feature + org.wso2.carbon.dynamic.client.registration.server.feature diff --git a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf deleted file mode 100644 index 3143c5e9df..0000000000 --- a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf +++ /dev/null @@ -1,2 +0,0 @@ -instructions.configure = \ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.oauth.extensions.server_${feature.version}/dynamic-client-manager.war,target:${installFolder}/../../deployment/server/webapps/dynamic-client-manager.war,overwrite:true);\ \ No newline at end of file diff --git a/pom.xml b/pom.xml index a3f508df4f..ce2f4a193f 100644 --- a/pom.xml +++ b/pom.xml @@ -41,13 +41,13 @@ components/policy-mgt components/certificate-mgt components/webapp-authenticator-framework - components/oauth-extensions + components/dynamic-client-registration features/device-mgt features/apimgt-extensions features/policy-mgt features/webapp-authenticator-framework - features/oauth-extensions features/certificate-mgt + features/dynamic-client-registration @@ -170,6 +170,21 @@ org.wso2.carbon.apimgt.webapp.publisher ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + org.wso2.carbon.dynamic.client.registration + ${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt + org.wso2.carbon.dynamic.client.web.app.registration + ${carbon.device.mgt.version} + + + org.wso2.mdm + dynamic-client-web + ${carbon.device.mgt.version} + @@ -981,6 +996,11 @@ commons-lang ${version.commons.lang} + + org.json.wso2 + json + ${json.wso2.version} + @@ -1259,6 +1279,8 @@ 2.26.1.wso2v3 + + 2.0.0.wso2v1