From 63721cb79dc1301835feac2188e22ddad27fc082 Mon Sep 17 00:00:00 2001 From: milanperera Date: Tue, 28 Jul 2015 15:34:38 +0530 Subject: [PATCH] Refactored --- .../DynamicClientRegistrationUtil.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java index 4a64d6368d..0cdb0a097f 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java @@ -43,30 +43,26 @@ import java.util.Arrays; public class DynamicClientRegistrationUtil { + private static final String TOKEN_SCOPE = "tokenScope"; private static final Log log = LogFactory.getLog(DynamicClientRegistrationUtil.class); public static OAuthApplicationInfo registerApplication(RegistrationProfile profile) throws APIManagementException { OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo(); - //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 + "'"); } - String callBackURL = profile.getCallbackUrl(); - String tokenScope = profile.getTokenScope(); String tokenScopes[] = new String[1]; tokenScopes[0] = tokenScope; - oAuthApplicationInfo.addParameter("tokenScope", Arrays.toString(tokenScopes)); + oAuthApplicationInfo.addParameter(TOKEN_SCOPE, Arrays.toString(tokenScopes)); OAuthApplicationInfo info; try { - info = createOAuthApplication(userId, applicationName, callBackURL, grantType); + info = createOAuthApplication(profile); } catch (Exception e) { throw new APIManagementException("Can not create OAuth application : " + applicationName, e); } @@ -98,8 +94,15 @@ public class DynamicClientRegistrationUtil { } public static OAuthApplicationInfo createOAuthApplication( - String userId, String applicationName, String callbackUrl, String grantType) + RegistrationProfile profile) throws APIManagementException, IdentityException { + + //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(); + if (userId == null || userId.isEmpty()) { return null; }