From fff1a3f16861d105fb45d636e709d1fe02b63b85 Mon Sep 17 00:00:00 2001 From: lakshani Date: Mon, 30 Jan 2017 18:44:23 +0530 Subject: [PATCH] fixed the issues in rest connector --- .../pom.xml | 6 ++- .../client/OAuthRequestInterceptor.java | 14 +++---- .../client/dto/AccessTokenInfo.java | 40 +++++++++---------- .../client/dto/ApiApplicationKey.java | 16 ++++---- pom.xml | 2 +- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/pom.xml b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/pom.xml index 904f6f453..2430a66d6 100644 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/pom.xml +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/pom.xml @@ -85,7 +85,8 @@ feign, feign.auth, feign.codec, - feign.gson + feign.gson, + *;resolution:=optional !org.wso2.carbon.appmgt.mdm.restconnector.internal, @@ -93,7 +94,8 @@ jsr311-api, - feign-jaxrs + feign-jaxrs, + org.wso2.carbon.device.mgt.common diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/OAuthRequestInterceptor.java b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/OAuthRequestInterceptor.java index d3e3692bd..48bf79df8 100755 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/OAuthRequestInterceptor.java +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/OAuthRequestInterceptor.java @@ -43,7 +43,7 @@ public class OAuthRequestInterceptor implements RequestInterceptor { private static final String DEVICE_MANAGEMENT_SERVICE_TAG[] = {"device_management"}; private static final String APPLICATION_NAME = "appm_restconnector_application"; private static final String PASSWORD_GRANT_TYPE = "password"; - private static final String REFRESH_GRANT_TYPE = "refreshToken"; + private static final String REFRESH_GRANT_TYPE = "refresh_token"; private ApiApplicationRegistrationService apiApplicationRegistrationService; private TokenIssuerService tokenIssuerService; @@ -74,7 +74,7 @@ public class OAuthRequestInterceptor implements RequestInterceptor { if (tokenInfo == null) { ApiRegistrationProfile apiRegistrationProfile = new ApiRegistrationProfile(); apiRegistrationProfile.setApplicationName(APPLICATION_NAME); - apiRegistrationProfile.setIsAllowedToAllDomains(true); + apiRegistrationProfile.setIsAllowedToAllDomains(false); apiRegistrationProfile.setIsMappingAnExistingOAuthApp(false); apiRegistrationProfile.setTags(DEVICE_MANAGEMENT_SERVICE_TAG); ApiApplicationKey apiApplicationKey = apiApplicationRegistrationService.register(apiRegistrationProfile); @@ -87,15 +87,15 @@ public class OAuthRequestInterceptor implements RequestInterceptor { .contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder()) .target(TokenIssuerService.class, AuthorizationConfigurationManager.getInstance().getTokenApiURL()); tokenInfo = tokenIssuerService.getToken(PASSWORD_GRANT_TYPE, username, password); - tokenInfo.setExpiresIn(System.currentTimeMillis() + tokenInfo.getExpiresIn()); + tokenInfo.setExpires_in(System.currentTimeMillis() + tokenInfo.getExpires_in()); } synchronized (this) { - if (System.currentTimeMillis() + Long.parseLong(refreshTimeOffset) > tokenInfo.getExpiresIn()) { - tokenInfo = tokenIssuerService.getToken(REFRESH_GRANT_TYPE, tokenInfo.getRefreshToken()); - tokenInfo.setExpiresIn(System.currentTimeMillis() + tokenInfo.getExpiresIn()); + if (System.currentTimeMillis() + Long.parseLong(refreshTimeOffset) > tokenInfo.getExpires_in()) { + tokenInfo = tokenIssuerService.getToken(REFRESH_GRANT_TYPE, tokenInfo.getRefresh_token()); + tokenInfo.setExpires_in(System.currentTimeMillis() + tokenInfo.getExpires_in()); } } - String headerValue = Constants.RestConstants.BEARER + tokenInfo.getAccessToken(); + String headerValue = Constants.RestConstants.BEARER + tokenInfo.getAccess_token(); template.header(Constants.RestConstants.AUTHORIZATION, headerValue); } } diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/dto/AccessTokenInfo.java b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/dto/AccessTokenInfo.java index a776b9013..f315ae116 100755 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/dto/AccessTokenInfo.java +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/dto/AccessTokenInfo.java @@ -21,40 +21,40 @@ package org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto; * This hold access token info that returned from the api call. */ public class AccessTokenInfo { - public String tokenType; - public long expiresIn; - public String refreshToken; - public String accessToken; + public String token_type; + public long expires_in; + public String refresh_token; + public String access_token; - public String getTokenType() { - return tokenType; + public String getToken_type() { + return token_type; } - public void setTokenType(String tokenType) { - this.tokenType = tokenType; + public void setToken_type(String token_type) { + this.token_type = token_type; } - public long getExpiresIn() { - return expiresIn; + public long getExpires_in() { + return expires_in; } - public void setExpiresIn(long expiresIn) { - this.expiresIn = expiresIn; + public void setExpires_in(long expires_in) { + this.expires_in = expires_in; } - public String getRefreshToken() { - return refreshToken; + public String getRefresh_token() { + return refresh_token; } - public void setRefreshToken(String refreshToken) { - this.refreshToken = refreshToken; + public void setRefresh_token(String refresh_token) { + this.refresh_token = refresh_token; } - public String getAccessToken() { - return accessToken; + public String getAccess_token() { + return access_token; } - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; + public void setAccess_token(String access_token) { + this.access_token = access_token; } } diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/dto/ApiApplicationKey.java b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/dto/ApiApplicationKey.java index 32dcc8718..0c34147e2 100644 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/dto/ApiApplicationKey.java +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/dto/ApiApplicationKey.java @@ -21,22 +21,22 @@ package org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto; * This holds api application consumer key and secret. */ public class ApiApplicationKey { - private String clientId; - private String clientSecret; + private String client_id; + private String client_secret; public String getConsumerKey() { - return this.clientId; + return this.client_id; } - public void setClientId(String consumerKey) { - this.clientId = consumerKey; + public void setClient_id(String consumerKey) { + this.client_id = consumerKey; } public String getConsumerSecret() { - return this.clientSecret; + return this.client_secret; } - public void setClientSecret(String consumerSecret) { - this.clientSecret = consumerSecret; + public void setClient_secret(String consumerSecret) { + this.client_secret = consumerSecret; } } diff --git a/pom.xml b/pom.xml index c772e4c76..6e7199266 100644 --- a/pom.xml +++ b/pom.xml @@ -1244,7 +1244,7 @@ 1.1.1 - 2.0.11 + 2.0.13 [2.0.0, 3.0.0)