From 16cc17369cca2cfd60876b7e2a8c198e9e99cac3 Mon Sep 17 00:00:00 2001 From: mharindu Date: Tue, 2 Jun 2015 18:58:43 +0530 Subject: [PATCH] Refactored DCA --- .../oauth/extension/RegistrationProfile.java | 10 ++++++++++ .../impl/ClientRegistrationServiceImpl.java | 19 ++++++++----------- .../carbon/policy/mgt/common/PIPDevice.java | 10 +++++----- .../policy/mgt/common/PolicyFilter.java | 1 - 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationProfile.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationProfile.java index 8014bde2f5..e1e819110f 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationProfile.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationProfile.java @@ -35,6 +35,7 @@ public class RegistrationProfile { private String owner; private String callbackUrl; private String tokenScope; + private String grantType; public String getApplicationType() { return applicationType; @@ -156,4 +157,13 @@ public class RegistrationProfile { this.tokenScope = tokenScope; } + public String getGrantType() { + return grantType; + } + + public void setGrantType(String grantType) { + this.grantType = grantType; + } + + } diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ClientRegistrationServiceImpl.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ClientRegistrationServiceImpl.java index f61454ebc0..3a112a6b43 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ClientRegistrationServiceImpl.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ClientRegistrationServiceImpl.java @@ -22,7 +22,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.json.JSONObject; -import org.json.simple.JSONArray; import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.impl.utils.APIUtil; import org.wso2.carbon.context.CarbonContext; @@ -48,6 +47,7 @@ import javax.ws.rs.POST; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.util.Arrays; @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -82,6 +82,7 @@ public class ClientRegistrationServiceImpl implements RegistrationService { //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(); if (log.isDebugEnabled()) { log.debug("Trying to create OAuth application: '" + applicationName + "'"); @@ -93,10 +94,10 @@ public class ClientRegistrationServiceImpl implements RegistrationService { String tokenScopes[] = new String[1]; tokenScopes[0] = tokenScope; - oAuthApplicationInfo.addParameter("tokenScope", tokenScopes); + oAuthApplicationInfo.addParameter("tokenScope", Arrays.toString(tokenScopes)); OAuthApplicationInfo info; try { - info = this.createOAuthApplication(userId, applicationName, callBackURL); + info = this.createOAuthApplication(userId, applicationName, callBackURL, grantType); } catch (Exception e) { throw new APIManagementException("Can not create OAuth application : " + applicationName, e); } @@ -116,11 +117,6 @@ public class ClientRegistrationServiceImpl implements RegistrationService { oAuthApplicationInfo.addParameter(ApplicationConstants.OAUTH_REDIRECT_URIS, jsonObject.get(ApplicationConstants.OAUTH_REDIRECT_URIS)); } - if (jsonObject.has(ApplicationConstants.OAUTH_CLIENT_NAME)) { - oAuthApplicationInfo.addParameter(ApplicationConstants. - OAUTH_CLIENT_NAME, jsonObject.get(ApplicationConstants.OAUTH_CLIENT_NAME)); - } - if (jsonObject.has(ApplicationConstants.OAUTH_CLIENT_GRANT)) { oAuthApplicationInfo.addParameter(ApplicationConstants. OAUTH_CLIENT_GRANT, jsonObject.get(ApplicationConstants.OAUTH_CLIENT_GRANT)); @@ -134,7 +130,8 @@ public class ClientRegistrationServiceImpl implements RegistrationService { } public OAuthApplicationInfo createOAuthApplication( - String userId, String applicationName, String callbackUrl) throws APIManagementException, IdentityException { + String userId, String applicationName, String callbackUrl, String grantType) + throws APIManagementException, IdentityException { if (userId == null || userId.isEmpty()) { return null; @@ -177,6 +174,7 @@ public class ClientRegistrationServiceImpl implements RegistrationService { oAuthConsumerAppDTO.setApplicationName(applicationName); oAuthConsumerAppDTO.setCallbackUrl(callbackUrl); + oAuthConsumerAppDTO.setGrantTypes(grantType); log.debug("Creating OAuth App " + applicationName); oAuthAdminService.registerOAuthApplicationData(oAuthConsumerAppDTO); log.debug("Created OAuth App " + applicationName); @@ -214,11 +212,10 @@ public class ClientRegistrationServiceImpl implements RegistrationService { oAuthApplicationInfo.setClientId(createdApp.getOauthConsumerKey()); oAuthApplicationInfo.setCallBackURL(createdApp.getCallbackUrl()); oAuthApplicationInfo.setClientSecret(createdApp.getOauthConsumerSecret()); + oAuthApplicationInfo.setClientName(createdApp.getApplicationName()); oAuthApplicationInfo.addParameter(ApplicationConstants. OAUTH_REDIRECT_URIS, createdApp.getCallbackUrl()); - oAuthApplicationInfo.addParameter(ApplicationConstants. - OAUTH_CLIENT_NAME, createdApp.getApplicationName()); oAuthApplicationInfo.addParameter(ApplicationConstants. OAUTH_CLIENT_GRANT, createdApp.getGrantTypes()); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java index 2bef8e1497..e758e2ca7e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java @@ -36,7 +36,7 @@ public class PIPDevice { private String ownershipType; private List userIds; private String roles[]; - private String altitude; + private String latitude; private String longitude; private Timestamp timestamp; @@ -83,12 +83,12 @@ public class PIPDevice { this.roles = roles; } - public String getAltitude() { - return altitude; + public String getLatitude() { + return latitude; } - public void setAltitude(String altitude) { - this.altitude = altitude; + public void setLatitude(String latitude) { + this.latitude = latitude; } public String getLongitude() { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java index 3e8cf71756..a654e786dc 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java @@ -31,5 +31,4 @@ public interface PolicyFilter { void filterDeviceTypeBasedPolicies(String deviceType, List policies); - }