revert-70aa11f8
Dilshan Edirisuriya 9 years ago
commit 3907c0fba2

@ -33,6 +33,8 @@ public class PermissionManager {
private static PermissionManager permissionManager;
private PermissionManager(){};
public static PermissionManager getInstance() {
if (permissionManager == null) {
synchronized (PermissionManager.class) {

@ -34,15 +34,23 @@ public interface DeviceDAO {
/**
* This method is used to add a device.
*
* @param typeId device type id.
* @param device device object.
* @param typeId device type id.
* @param device device object.
* @param tenantId tenant id.
* @return returns the id of the persisted device record.
* @throws DeviceManagementDAOException
*/
int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to update a given device.
*
* @param typeId device type id.
* @param device device object.
* @param tenantId tenant id.
* @return returns the id of updated device.
* @throws DeviceManagementDAOException
*/
boolean updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException;
/**
@ -95,7 +103,7 @@ public interface DeviceDAO {
/**
* This method is used to retrieve all the devices of a given tenant and device type.
*
* @param type device type.
* @param type device type.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
@ -104,6 +112,7 @@ public interface DeviceDAO {
/**
* This method is used to retrieve devices of a given user.
*
* @param username user name.
* @param tenantId tenant id.
* @return returns list of devices.
@ -122,8 +131,9 @@ public interface DeviceDAO {
/**
* This method is used to retrieve devices of a given device name.
*
* @param deviceName device name.
* @param tenantId tenant id.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
*/
@ -132,7 +142,7 @@ public interface DeviceDAO {
/**
* This method is used to add an enrollment information of a given device.
*
* @param device device object.
* @param device device object.
* @param tenantId tenant id.
* @return returns the id of the enrollment.
* @throws DeviceManagementDAOException
@ -142,22 +152,22 @@ public interface DeviceDAO {
/**
* This method is used to set the current enrollment status of given device and user.
*
* @param deviceId device id.
* @param deviceId device id.
* @param currentOwner current user name.
* @param status device status.
* @param tenantId tenant id.
* @param status device status.
* @param tenantId tenant id.
* @return returns true if success.
* @throws DeviceManagementDAOException
*/
boolean setEnrolmentStatus(DeviceIdentifier deviceId, String currentOwner, Status status,
int tenantId) throws DeviceManagementDAOException;
int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to get the status of current enrollment of a given user and device.
*
* @param deviceId device id.
* @param deviceId device id.
* @param currentOwner device owner.
* @param tenantId tenant id.
* @param tenantId tenant id.
* @return returns current enrollment status.
* @throws DeviceManagementDAOException
*/
@ -167,9 +177,9 @@ public interface DeviceDAO {
/**
* This method is used to retrieve current enrollment of a given device and user.
*
* @param deviceId device id.
* @param deviceId device id.
* @param currentUser user name.
* @param tenantId tenant id.
* @param tenantId tenant id.
* @return returns EnrolmentInfo object.
* @throws DeviceManagementDAOException
*/
@ -179,7 +189,7 @@ public interface DeviceDAO {
/**
* This method is used to retrieve devices of a given enrollment status.
*
* @param status enrollment status.
* @param status enrollment status.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
@ -190,12 +200,24 @@ public interface DeviceDAO {
* This method is used to retrieve the enrollment id of a given device and status.
*
* @param deviceId device id.
* @param status enrollment status.
* @param status enrollment status.
* @param tenantId tenant id.
* @return returns the id of current enrollment.
* @throws DeviceManagementDAOException
*/
int getEnrolmentByStatus(DeviceIdentifier deviceId, Status status,
int tenantId) throws DeviceManagementDAOException;
int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve the enrollment info of a given list of devices and status.
*
* @param deviceIds A list of device identifiers.
* @param status enrollment status.
* @param tenantId tenant id.
* @return returns a list of enrolment info objects.
* @throws DeviceManagementDAOException
*/
List<EnrolmentInfo> getEnrolmentsByStatus(List<DeviceIdentifier> deviceIds, Status status,
int tenantId) throws DeviceManagementDAOException;
}

@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.HashMap;
import java.util.List;
@ -516,6 +517,51 @@ public class DeviceDAOImpl implements DeviceDAO {
}
}
public List<EnrolmentInfo> getEnrolmentsByStatus(List<DeviceIdentifier> deviceIds, Status status,
int tenantId) throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<EnrolmentInfo> enrolments = new ArrayList<>();
try {
conn = this.getConnection();
StringBuilder sql = new StringBuilder();
sql.append("SELECT e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, " +
"e.STATUS FROM DM_ENROLMENT e WHERE e.DEVICE_ID IN (SELECT d.ID FROM DM_DEVICE d " +
"WHERE d.DEVICE_IDENTIFICATION IN (");
// adding arguments to the sql query
Iterator iterator = deviceIds.iterator();
while (iterator.hasNext()) {
iterator.next();
sql.append(" ?");
if (iterator.hasNext()) {
sql.append(",");
}
}
sql.append(") AND d.TENANT_ID = ?) AND e.STATUS = ? AND e.TENANT_ID = ?");
stmt = conn.prepareStatement(sql.toString());
int index = 1;
for (DeviceIdentifier id : deviceIds) {
stmt.setString(index++, id.getId());
}
stmt.setInt(index++, tenantId);
stmt.setString(index++, status.toString());
stmt.setInt(index, tenantId);
rs = stmt.executeQuery();
if (rs.next()) {
enrolments.add(this.loadEnrolment(rs));
}
return enrolments;
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " +
"ids of devices", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
}
private Device loadDevice(ResultSet rs) throws SQLException {
Device device = new Device();
device.setId(rs.getInt("DEVICE_ID"));

@ -80,34 +80,26 @@ public class OperationManagerImpl implements OperationManager {
}
}
try {
OperationManagementDAOFactory.beginTransaction();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
List<EnrolmentInfo> enrolments;
try {
DeviceManagementDAOFactory.openConnection();
enrolments = deviceDAO.getEnrolmentsByStatus(deviceIds, EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection the data " +
"source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
OperationManagementDAOFactory.beginTransaction();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
int enrolmentId;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
for (DeviceIdentifier deviceId : deviceIds) {
try {
DeviceManagementDAOFactory.openConnection();
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection the data " +
"source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
if (enrolmentId < 0) {
String errorMsg = "The operation not added for device.The device not found for " +
"device Identifier type -'" + deviceId.getType() + "' and device Id '" +
deviceId.getId();
log.error(errorMsg);
} else {
operationMappingDAO.addOperationMapping(operationId, enrolmentId);
}
for (EnrolmentInfo enrolmentInfo : enrolments) {
operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId());
}
OperationManagementDAOFactory.commitTransaction();
return operationId;

@ -246,6 +246,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.beginTransaction();
Device device = deviceDAO.getDevice(deviceId, tenantId);
if (device == null) {
if (log.isDebugEnabled()) {
log.debug("Device not found for id '" + deviceId.getId() + "'");
}
throw new DeviceManagementException("Device not found");
}
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());

@ -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 {
}

@ -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.
-->
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>dynamic-client-registration</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>oauth-extensions</artifactId>
<version>0.9.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.mdm</groupId>
<artifactId>dynamic-client-manager</artifactId>
<name>WSO2 Carbon - Dynamic Client Registration Impl</name>
<description>WSO2 Carbon - Dynamic Client Registration Impl</description>
<artifactId>dynamic-client-web</artifactId>
<version>0.9.2-SNAPSHOT</version>
<name>WSO2 Carbon - Dynamic Client Registration Web Service</name>
<description>WSO2 Carbon - Dynamic Client Registration Web</description>
<packaging>war</packaging>
<build>
@ -119,33 +120,18 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.application.mgt</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.impl</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.dynamic.client.registration</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.keymgt.client</artifactId>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
<artifactId>org.wso2.carbon.identity.application.mgt</artifactId>
<scope>provided</scope>
</dependency>
<dependency>

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

@ -2,19 +2,19 @@
<!--
~ 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
~ 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@ -37,8 +37,8 @@
</jaxrs:providers>
</jaxrs:server>
<bean id="RegistrationServiceBean" class="org.wso2.carbon.identity.oauth.extension.impl.RegistrationServiceImpl"/>
<bean id="RegistrationServiceBean" class="org.wso2.carbon.dynamic.client.web.impl.RegistrationServiceImpl"/>
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
<bean id="faultResponseWriter" class="org.wso2.carbon.identity.oauth.extension.FaultMessageBodyWriter"/>
<bean id="faultResponseWriter" class="org.wso2.carbon.dynamic.client.web.FaultMessageBodyWriter"/>
</beans>

@ -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>

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

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

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

@ -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 {
}
}

@ -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;

@ -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,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
~ 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">
@ -28,14 +28,16 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>oauth-extensions</artifactId>
<artifactId>dynamic-client-registration</artifactId>
<version>0.9.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>WSO2 Carbon - OAuth Extensions</name>
<name>WSO2 Carbon - Dynamic Client Registration Component</name>
<url>http://wso2.org</url>
<modules>
<module>dynamic-client-manager</module>
<module>org.wso2.carbon.dynamic.client.registration</module>
<module>org.wso2.carbon.dynamic.client.web.app.registration</module>
<module>dynamic-client-web</module>
</modules>
<build>

@ -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>

@ -1,87 +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.
-->
<wap-provisioningdoc version="1.1">
<characteristic type="CertificateStore">
<characteristic type="Root">
<characteristic type="System">
<characteristic type="">
<parm name="EncodedCertificate" value=""/>
</characteristic>
</characteristic>
</characteristic>
<characteristic type="My">
<characteristic type="User">
<characteristic type="">
<parm name="EncodedCertificate" value=""/>
</characteristic>
<characteristic type="PrivateKeyContainer"/>
</characteristic>
<characteristic type="WSTEP">
<characteristic type="Renew">
<parm name="ROBOSupport" value="true" datatype="boolean" />
<parm name="RenewPeriod" value="60" datatype="integer" />
<parm name="RetryInterval" value="4" datatype="integer" />
</characteristic>
</characteristic>
</characteristic>
</characteristic>
<characteristic type="APPLICATION">
<parm name="APPID" value="w7"/>
<parm name="PROVIDER-ID" value="MobiCDMServer"/>
<parm name="NAME" value="wso2"/>
<parm name="ADDR" value="https://EnterpriseEnrollment.wso2.com/Synchml/initialquery"/>
<parm name="CONNRETRYFREQ" value="6"/>
<parm name="INITIALBACKOFFTIME" value="30000"/>
<parm name="MAXBACKOFFTIME" value="120000"/>
<parm name="BACKCOMPATRETRYDISABLED"/>
<parm name="DEFAULTENCODING" value="application/vnd.syncml.dm+xml"/>
<parm name="SSLCLIENTCERTSEARCHCRITERIA"
value="Subject=CN%3Dmdmcn&amp;Stores=My%5CUser"/>
<characteristic type="APPAUTH">
<parm name="AAUTHLEVEL" value="CLIENT"/>
<parm name="AAUTHTYPE" value="DIGEST"/>
<parm name="AAUTHSECRET" value="dummy"/>
<parm name="AAUTHDATA" value="ZHVtbXk="/>
</characteristic>
<characteristic type="APPAUTH">
<parm name="AAUTHLEVEL" value="APPSRV"/>
<parm name="AAUTHTYPE" value="DIGEST"/>
<parm name="AAUTHNAME" value="dummy"/>
<parm name="AAUTHSECRET" value="dummy"/>
<parm name="AAUTHDATA" value="ZHVtbXk="/>
</characteristic>
</characteristic>
<characteristic type="DMClient">
<!-- Staring with Windows Phone 8.1, an enrollment server should use DMClient CSP XML to configure DM polling schedules. The polling schedule regisitry keys will be deprecated after Windows Phone 8.1.-->
<characteristic type="Provider">
<!-- ProviderID in DMClient CSP must match to PROVIDER-ID in w7 APPLICATION characteristics -->
<characteristic type="MobiCDMServer">
<characteristic type="Poll">
<parm name="NumberOfFirstRetries" value="8" datatype="integer" />
<parm name="IntervalForFirstSetOfRetries" value="15" datatype="integer" />
<parm name="NumberOfSecondRetries" value="5" datatype="integer" />
<parm name="IntervalForSecondSetOfRetries" value="3" datatype="integer" />
<parm name="NumberOfRemainingScheduledRetries" value="0" datatype="integer" />
<!-- In Windows Phone 8.1, MDM push is supported for real-time communication. The DM client long term polling schedules retry waiting interval should be more than 24 hours (1440) to reduce the impact to data consumption and battery life. Refer to the DMClient Configuration Service Provider section for information about polling schedule parameters.-->
<parm name="IntervalForRemainingScheduledRetries" value="1560" datatype="integer" />
</characteristic>
<parm name="EntDeviceName" value="AdministratorWindowsPhone" datatype="string" />
</characteristic>
</characteristic>
</characteristic>
</wap-provisioningdoc>

@ -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>

@ -45,7 +45,7 @@ public class ComplianceFeature {
this.featureCode = featureCode;
}
public boolean isCompliance() {
public boolean isCompliant() {
return compliance;
}

@ -219,7 +219,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
for (ComplianceFeature feature : complianceFeatures) {
stmt.setInt(1, policyComplianceStatusId);
stmt.setString(2, feature.getFeatureCode());
if (feature.isCompliance()) {
if (feature.isCompliant()) {
stmt.setInt(3, 1);
} else {
stmt.setInt(3, 0);

@ -133,8 +133,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo();
triggerInfo.setIntervalMillis(0);
triggerInfo.setRepeatCount(1);
triggerInfo.setRepeatCount(0);
Map<String, String> properties = new HashMap<>();
properties.put(PolicyManagementConstants.TENANT_ID, String.valueOf(tenantId));

@ -107,12 +107,12 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
log.debug("Re-enforcing policy started...!");
int sixe = policies.size();
int size = policies.size();
sortPolicies(policies);
int x = 0;
for (Policy policy : policies) {
policy.setPriorityId(sixe - x);
policy.setPriorityId(size - x);
x++;
}

@ -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

@ -23,19 +23,37 @@
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>oauth-extentions-feature</artifactId>
<artifactId>dynamic-client-registration-feature</artifactId>
<version>0.9.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.oauth.extensions.server.feature</artifactId>
<artifactId>org.wso2.carbon.dynamic.client.registration.server.feature</artifactId>
<packaging>pom</packaging>
<version>0.9.2-SNAPSHOT</version>
<name>WSO2 Carbon - Oauth Extensions Server Feature</name>
<name>WSO2 Carbon - Dynamic Client Registration Server Feature</name>
<url>http://wso2.org</url>
<description>This feature contains oauth functionality
</description>
<description>This feature contains dynamic client registration features</description>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.dynamic.client.registration</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.dynamic.client.web.app.registration</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>
<build>
<plugins>
@ -80,12 +98,12 @@
<artifactItems>
<artifactItem>
<groupId>org.wso2.mdm</groupId>
<artifactId>dynamic-client-manager</artifactId>
<version>${project.version}</version>
<artifactId>dynamic-client-web</artifactId>
<version>${carbon.device.mgt.version}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>${basedir}/src/main/resources/</outputDirectory>
<destFileName>dynamic-client-manager.war</destFileName>
<destFileName>dynamic-client-web.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
@ -105,7 +123,7 @@
<goal>p2-feature-gen</goal>
</goals>
<configuration>
<id>org.wso2.carbon.oauth.extensions.server</id>
<id>org.wso2.carbon.dynamic.client.registration.server</id>
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
<adviceFile>
<properties>
@ -113,6 +131,20 @@
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
</properties>
</adviceFile>
<bundles>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.dynamic.client.registration:${carbon.device.mgt.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.dynamic.client.web.app.registration:${carbon.device.mgt.version}
</bundleDef>
<bundleDef>
com.googlecode.json-simple.wso2:json-simple:${json-simple.version}
</bundleDef>
<bundleDef>
org.json.wso2:json:${json.wso2.version}
</bundleDef>
</bundles>
<importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}
</importFeatureDef>

@ -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);\

@ -29,14 +29,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>oauth-extentions-feature</artifactId>
<artifactId>dynamic-client-registration-feature</artifactId>
<version>0.9.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>WSO2 Carbon - Policy Management Feature</name>
<name>WSO2 Carbon - Dynamic Client Registration Feature</name>
<url>http://wso2.org</url>
<modules>
<module>org.wso2.carbon.oauth.extensions.server.feature</module>
<module>org.wso2.carbon.dynamic.client.registration.server.feature</module>
</modules>
</project>

@ -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);\

@ -41,13 +41,13 @@
<module>components/policy-mgt</module>
<module>components/certificate-mgt</module>
<module>components/webapp-authenticator-framework</module>
<module>components/oauth-extensions</module>
<module>components/dynamic-client-registration</module>
<module>features/device-mgt</module>
<module>features/apimgt-extensions</module>
<module>features/policy-mgt</module>
<module>features/webapp-authenticator-framework</module>
<module>features/oauth-extensions</module>
<module>features/certificate-mgt</module>
<module>features/dynamic-client-registration</module>
</modules>
<dependencyManagement>
@ -170,6 +170,21 @@
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.dynamic.client.registration</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.dynamic.client.web.app.registration</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.mdm</groupId>
<artifactId>dynamic-client-web</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
<!-- Device Management dependencies -->
<!-- Governance dependencies -->
@ -981,6 +996,11 @@
<artifactId>commons-lang</artifactId>
<version>${version.commons.lang}</version>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
<version>${json.wso2.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
@ -1259,6 +1279,8 @@
<!-- Nimbus Jose-->
<nimbus.orbit.version>2.26.1.wso2v3</nimbus.orbit.version>
<json.wso2.version>2.0.0.wso2v1</json.wso2.version>
</properties>
</project>

Loading…
Cancel
Save