From a3e385bd2ff3ea407c312658f1a10fc51a44da83 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 28 May 2015 22:06:40 +0530 Subject: [PATCH] Serializing the complete OAuthAPplicationInfo bean --- .../oauth/extension/OAuthApplicationInfo.java | 11 +++++++++++ .../extension/impl/ClientRegistrationServiceImpl.java | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/OAuthApplicationInfo.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/OAuthApplicationInfo.java index e994bad5553..74206f3def8 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/OAuthApplicationInfo.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/OAuthApplicationInfo.java @@ -18,8 +18,10 @@ */ package org.wso2.carbon.identity.oauth.extension; +import org.codehaus.jackson.map.ObjectMapper; import org.json.simple.JSONObject; +import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -101,4 +103,13 @@ public class OAuthApplicationInfo { this.parameters.remove(key); } + public String toString() { + ObjectMapper mapper = new ObjectMapper(); + try { + return mapper.writeValueAsString(this); + } catch (IOException e) { + throw new RuntimeException("Error occurred while serializing OAuthApplicationInfo bean"); + } + } + } 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 23b8aac24cc..f61454ebc0d 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 @@ -65,7 +65,7 @@ public class ClientRegistrationServiceImpl implements RegistrationService { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); OAuthApplicationInfo info = this.registerApplication(profile); - return Response.status(Response.Status.ACCEPTED).entity(info.getJsonString()).build(); + 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); @@ -125,6 +125,8 @@ public class ClientRegistrationServiceImpl implements RegistrationService { oAuthApplicationInfo.addParameter(ApplicationConstants. OAUTH_CLIENT_GRANT, jsonObject.get(ApplicationConstants.OAUTH_CLIENT_GRANT)); } + + } catch (JSONException e) { throw new APIManagementException("Can not retrieve information of the created OAuth application", e); }