forked from community/device-mgt-core
parent
b644bb43b8
commit
b8720917e1
@ -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 {
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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<String, Object> getMetadata() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dynamic-client-registration</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.dynamic.client.registration</artifactId>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Dynamic client registration service</name>
|
||||
<description>WSO2 Carbon - Dynamic Client Registration Service</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>Dynamic Client Registration Bundle</Bundle-Description>
|
||||
<Bundle-Activator>org.wso2.carbon.dynamic.client.registration.internal.DynamicClientRegistrationBundleActivator</Bundle-Activator>
|
||||
<Private-Package>org.wso2.carbon.dynamic.client.registration.internal</Private-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.dynamic.client.registration.internal,
|
||||
org.wso2.carbon.dynamic.client.registration.*
|
||||
</Export-Package>
|
||||
<DynamicImport-Package>*</DynamicImport-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.application.mgt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.apimgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.apimgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.impl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.apimgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.keymgt.client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple.wso2</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json.wso2</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
28
components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/ApplicationConstants.java → components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java
28
components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/ApplicationConstants.java → 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 {
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
43
components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/OAuthApplicationInfo.java → components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java
43
components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/OAuthApplicationInfo.java → components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/OAuthApplicationInfo.java
168
components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java → components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.java
168
components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java → components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationImpl.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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
39
components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/RegistrationProfile.java → components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java
39
components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/RegistrationProfile.java → components/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/profile/RegistrationProfile.java
@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dynamic-client-registration</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.dynamic.client.web.app.registration</artifactId>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Dynamic client web app registration</name>
|
||||
<description>WSO2 Carbon - Dynamic Client Web-app Registration Service</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>Dynamic Client Web App Registration Bundle</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.dynamic.client.web.app.registration.internal</Private-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.dynamic.client.web.app.registration.internal,
|
||||
org.wso2.carbon.dynamic.client.web.app.registration.*
|
||||
</Export-Package>
|
||||
<DynamicImport-Package>*</DynamicImport-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.application.mgt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.apimgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.apimgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.impl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.apimgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.keymgt.client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.tomcat</groupId>
|
||||
<artifactId>tomcat</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.tomcat</groupId>
|
||||
<artifactId>tomcat-servlet-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.dynamic.client.registration</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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<String, Object> getMetadata() {
|
||||
return 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;
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,102 +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.
|
||||
-->
|
||||
<SyncML xmlns="SYNCML:SYNCML1.2">
|
||||
<SyncHdr>
|
||||
<VerDTD>1.2</VerDTD>
|
||||
<VerProto>DM/1.2</VerProto>
|
||||
<SessionID>1</SessionID>
|
||||
<MsgID>1</MsgID>
|
||||
<Target>
|
||||
<LocURI>TARGET_URI</LocURI>
|
||||
</Target>
|
||||
<Source>
|
||||
<LocURI>SOURCE_URI</LocURI>
|
||||
</Source>
|
||||
</SyncHdr>
|
||||
<SyncBody>
|
||||
<Status>
|
||||
<CmdID>1</CmdID>
|
||||
<MsgRef>1</MsgRef>
|
||||
<CmdRef>0</CmdRef>
|
||||
<Cmd>SyncHdr</Cmd>
|
||||
<TargetRef>TARGET_URI</TargetRef>
|
||||
<Data>212</Data>
|
||||
</Status>
|
||||
<Status>
|
||||
<CmdID>2</CmdID>
|
||||
<MsgRef>1</MsgRef>
|
||||
<CmdRef>2</CmdRef>
|
||||
<Cmd>Alert</Cmd>
|
||||
<Data>200</Data>
|
||||
</Status>
|
||||
<Status>
|
||||
<CmdID>3</CmdID>
|
||||
<MsgRef>1</MsgRef>
|
||||
<CmdRef>3</CmdRef>
|
||||
<Cmd>Replace</Cmd>
|
||||
<TargetRef>./devinf12</TargetRef>
|
||||
<Data>200</Data>
|
||||
</Status>
|
||||
<Get>
|
||||
<CmdID>75</CmdID>
|
||||
<Item>
|
||||
<Target>
|
||||
<LocURI>./DevDetail/SwV</LocURI>
|
||||
</Target>
|
||||
</Item>
|
||||
<Item>
|
||||
<Target>
|
||||
<LocURI>./Vendor/MSFT/DeviceInstanceService/Identity/Identity1/IMSI</LocURI>
|
||||
</Target>
|
||||
</Item>
|
||||
<Item>
|
||||
<Target>
|
||||
<LocURI>./Vendor/MSFT/DeviceInstanceService/Identity/Identity1/IMEI</LocURI>
|
||||
</Target>
|
||||
</Item>
|
||||
<Item>
|
||||
<Target>
|
||||
<LocURI>./DevInfo/DevId</LocURI>
|
||||
</Target>
|
||||
</Item>
|
||||
<Item>
|
||||
<Target>
|
||||
<LocURI>./DevInfo/Man</LocURI>
|
||||
</Target>
|
||||
</Item>
|
||||
<Item>
|
||||
<Target>
|
||||
<LocURI>./DevInfo/Mod</LocURI>
|
||||
</Target>
|
||||
</Item>
|
||||
<Item>
|
||||
<Target>
|
||||
<LocURI>./DevInfo/Lang</LocURI>
|
||||
</Target>
|
||||
</Item>
|
||||
</Get>
|
||||
<Exec>
|
||||
<CmdID>5</CmdID>
|
||||
<Item>
|
||||
<Target>
|
||||
<LocURI>./Vendor/MSFT/RemoteRing/Ring </LocURI>
|
||||
</Target>
|
||||
</Item>
|
||||
</Exec>
|
||||
</SyncBody>
|
||||
</SyncML>
|
@ -1,25 +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.
|
||||
-->
|
||||
<WindowsPlugin>
|
||||
<AuthPolicy>Federated</AuthPolicy>
|
||||
<Password>wso2carbon</Password>
|
||||
<PrivateKeyPassword>cacert</PrivateKeyPassword>
|
||||
<SignedCertCN>CN=mdmcn</SignedCertCN>
|
||||
<SignedCertNotBefore>3</SignedCertNotBefore>
|
||||
<SignedCertNotAfter>300</SignedCertNotAfter>
|
||||
</WindowsPlugin>
|
@ -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.
|
||||
-->
|
||||
<SyncML xmlns="SYNCML:SYNCML1.2">
|
||||
<SyncHdr>
|
||||
<VerDTD>1.2</VerDTD>
|
||||
<VerProto>DM/1.2</VerProto>
|
||||
<SessionID>1</SessionID>
|
||||
<MsgID>2</MsgID>
|
||||
<Target>
|
||||
<LocURI>TARGET_URI</LocURI>
|
||||
</Target>
|
||||
<Source>
|
||||
<LocURI>SOURCE_URI</LocURI>
|
||||
</Source>
|
||||
</SyncHdr>
|
||||
<SyncBody>
|
||||
<Status>
|
||||
<CmdID>1</CmdID>
|
||||
<MsgRef>1</MsgRef>
|
||||
<CmdRef>0</CmdRef>
|
||||
<Cmd>SyncHdr</Cmd>
|
||||
<TargetRef>TARGET_URI</TargetRef>
|
||||
<Data>212</Data>
|
||||
</Status>
|
||||
</SyncBody>
|
||||
</SyncML>
|
@ -1 +0,0 @@
|
||||
<SyncML xmlns="SYNCML:SYNCML1.2"><SyncHdr><VerDTD>1.2</VerDTD><VerProto>DM/1.2</VerProto><SessionID>1</SessionID><MsgID>1</MsgID><Target><LocURI>https://EnterpriseEnrollment.wso2.com/Synchml/initialquery</LocURI></Target><Source><LocURI>urn:uuid:FAEFB2D5-1771-5446-A635-797AFC474895</LocURI><LocName>dummy</LocName></Source><Cred><Meta><Format xmlns="syncml:metinf">b64</Format><Type xmlns="syncml:metinf">syncml:auth-md5</Type></Meta><Data>Zp3sdCvijPGIQ6JxuIJHlQ==</Data></Cred></SyncHdr><SyncBody><Alert><CmdID>2</CmdID><Data>1201</Data></Alert><Results><CmdID>3</CmdID><MsgRef>1</MsgRef><CmdRef>75</CmdRef><Item><Source><LocURI>./DevDetail/SwV</LocURI></Source><Data>8.10.12397.895</Data></Item></Results><Replace><CmdID>3</CmdID><Item><Source><LocURI>./DevInfo/DevId</LocURI></Source><Data>urn:uuid:FAEFB2D5-1771-5446-A635-797AFC474895</Data></Item><Item><Source><LocURI>./DevInfo/Man</LocURI></Source><Data>NOKIA</Data></Item><Item><Source><LocURI>./DevInfo/Mod</LocURI></Source><Data>Lumia 630</Data></Item><Item><Source><LocURI>./DevInfo/DmV</LocURI></Source><Data>1.3</Data></Item><Item><Source><LocURI>./DevInfo/Lang</LocURI></Source><Data>en-GB</Data></Item></Replace><Final /></SyncBody></SyncML>
|
Binary file not shown.
@ -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
|
@ -1,41 +0,0 @@
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2014, 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.
|
||||
-->
|
||||
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
|
||||
<suite name="DeviceManagementCore">
|
||||
<parameter name="useDefaultListeners" value="false"/>
|
||||
|
||||
<test name="DAO Unit Tests" preserve-order="true">
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.dao.DevicePersistTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.app.mgt.AppManagementConfigurationManagerTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.dao.ApplicationPersistenceTests"/>
|
||||
</classes>
|
||||
</test>
|
||||
<test name="Service Unit Tests" preserve-order="true">
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServiceTest"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
@ -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);\
|
@ -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);\
|
Loading…
Reference in new issue