Http Client update bug fixes.

secure-folder-policy
Lasantha Dharmakeerthi 11 months ago
commit 9a84a15368

@ -154,6 +154,12 @@
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>

@ -112,7 +112,7 @@ public class DefaultOauth2TokenHandler extends HttpServlet {
String defaultToken = tokenResult.get("accessToken").asText();
newDefaultAuthData.setAccessToken(defaultToken);
newDefaultAuthData.setRefreshToken(tokenResult.get("refreshToken").asText());
newDefaultAuthData.setScope(tokenResult.get("scopes").asText());
newDefaultAuthData.setScope(tokenResult.get("scopes"));
httpSession.setAttribute(HandlerConstants.SESSION_DEFAULT_AUTH_DATA_KEY, newDefaultAuthData);
HandlerUtil.handleSuccess(resp, constructSuccessProxyResponse(defaultToken));

@ -183,7 +183,7 @@ public class LoginHandler extends HttpServlet {
authData.setEncodedClientApp(encodedClientApp);
authData.setAccessToken(tokenResult.get("access_token").textValue());
authData.setRefreshToken(tokenResult.get("refresh_token").textValue());
authData.setScope(tokenResult.get("scope").textValue());
authData.setScope(tokenResult.get("scope"));
session.setAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY, authData);
return true;
} catch (IOException e) {

@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@MultipartConfig
@ -57,14 +58,13 @@ public class PermissionScopeHandler extends HttpServlet {
return;
}
if (!StringUtils.isEmpty(authData.getScope())) {
if (!StringUtils.isEmpty(authData.getScope().toString())) {
ProxyResponse proxyResponse = new ProxyResponse();
JsonNode authDataScope = authData.getScope();
ObjectMapper mapper = new ObjectMapper();
JsonNode node = JsonNodeFactory.instance.objectNode();
Map<String, Object> nodeMap = mapper.convertValue(node, new TypeReference<>() {
});
nodeMap.put(HandlerConstants.USER_SCOPES, authData.getScope());
Map<String, Object> nodeMap = new HashMap<>();
nodeMap.put(HandlerConstants.USER_SCOPES, authDataScope);
proxyResponse.setCode(HttpStatus.SC_OK);
proxyResponse.setStatus(ProxyResponse.Status.SUCCESS);
proxyResponse.setData(mapper.convertValue(nodeMap, JsonNode.class));

@ -96,7 +96,7 @@ public class SsoLoginCallbackHandler extends HttpServlet {
authData.setEncodedClientApp(session.getAttribute("encodedClientApp").toString());
authData.setAccessToken(jsonNode.get("access_token").textValue());
authData.setRefreshToken(jsonNode.get("refresh_token").textValue());
authData.setScope(jsonNode.get("scope").textValue());
authData.setScope(jsonNode.get("scope"));
session.setAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY, authData);
resp.sendRedirect(session.getAttribute("redirectUrl").toString());
} else {

@ -129,8 +129,8 @@ public class UserHandler extends HttpServlet {
HandlerUtil.handleSuccess(resp, proxyResponse);
httpSession.setAttribute(HandlerConstants.USERNAME_WITH_DOMAIN, nodeMap.get("username").toString());
log.info("Customer login",
userLogContextBuilder.setUserName(nodeMap.get("username").toString()).setUserRegistered(true).build());
// log.info("Customer login",
// userLogContextBuilder.setUserName(nodeMap.get("username").toString()).setUserRegistered(true).build());
} catch (IOException e) {
log.error("Error occurred while sending the response into the socket. ", e);
} catch (JsonSyntaxException e) {

@ -19,6 +19,8 @@
package io.entgra.device.mgt.core.ui.request.interceptor.beans;
import com.fasterxml.jackson.databind.JsonNode;
public class AuthData implements java.io.Serializable {
private static final long serialVersionUID = -5156750882531944849L;
@ -29,7 +31,7 @@ public class AuthData implements java.io.Serializable {
private String clientId;
private String clientSecret;
private String encodedClientApp;
private String scope;
private JsonNode scope;
public String getAccessToken() {
return accessToken;
@ -79,11 +81,11 @@ public class AuthData implements java.io.Serializable {
this.encodedClientApp = encodedClientApp;
}
public String getScope() {
public JsonNode getScope() {
return scope;
}
public void setScope(String scope) {
public void setScope(JsonNode scope) {
this.scope = scope;
}
}

@ -19,6 +19,7 @@
package io.entgra.device.mgt.core.ui.request.interceptor.util;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
@ -264,9 +265,17 @@ public class HandlerUtil {
resp.setStatus(proxyResponse.getCode());
resp.setContentType(ContentType.APPLICATION_JSON.getMimeType());
resp.setCharacterEncoding(Consts.UTF_8.name());
JsonNode responseData = proxyResponse.getData();
if (!(responseData == null)) {
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> newNodeMap = new HashMap<>();
newNodeMap.put("data", responseData);
responseData = mapper.convertValue(newNodeMap, JsonNode.class);
}
try (PrintWriter writer = resp.getWriter()) {
writer.write(proxyResponse.getData().toString());
writer.write(responseData != null ? responseData.toString() : "{}");
}
}
@ -665,7 +674,7 @@ public class HandlerUtil {
AuthData newAuthData = new AuthData();
newAuthData.setAccessToken(tokenResult.get("access_token").textValue());
newAuthData.setRefreshToken(tokenResult.get("refresh_token").textValue());
newAuthData.setScope(tokenResult.get("scope").textValue());
newAuthData.setScope(tokenResult.get("scope"));
newAuthData.setClientId(authData.getClientId());
newAuthData.setClientSecret(authData.getClientSecret());
newAuthData.setEncodedClientApp(authData.getEncodedClientApp());

Loading…
Cancel
Save