Fix enroll-web-agent login issue

fix-compile-failure
Rajitha Kumara 3 months ago
parent 45b90a4749
commit 55f5865726

@ -71,6 +71,8 @@ public class LoginHandler extends HttpServlet {
httpSession.invalidate(); httpSession.invalidate();
} }
httpSession = req.getSession(true); httpSession = req.getSession(true);
final String baseContextPath = req.getContextPath();
final String applicationName = baseContextPath.substring(1, baseContextPath.indexOf("-ui-request-handler")) + "-login";
JsonNode uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, JsonNode uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession,
resp); resp);
@ -83,14 +85,16 @@ public class LoginHandler extends HttpServlet {
// Check if OAuth app cache exists. If not create a new application. // Check if OAuth app cache exists. If not create a new application.
LoginCache loginCache = HandlerUtil.getLoginCache(httpSession); LoginCache loginCache = HandlerUtil.getLoginCache(httpSession);
OAuthAppCacheKey oAuthAppCacheKey = new OAuthAppCacheKey(HandlerConstants.PUBLISHER_APPLICATION_NAME, username); OAuthAppCacheKey oAuthAppCacheKey = new OAuthAppCacheKey(applicationName, username);
OAuthApp oAuthApp = loginCache.getOAuthAppCache(oAuthAppCacheKey); OAuthApp oAuthApp = loginCache.getOAuthAppCache(oAuthAppCacheKey);
if (oAuthApp == null) { if (oAuthApp == null) {
ArrayList<String> supportedGrantTypes = new ArrayList<>();
supportedGrantTypes.add(HandlerConstants.PASSWORD_GRANT_TYPE);
supportedGrantTypes.add(HandlerConstants.REFRESH_TOKEN_GRANT_TYPE);
ClassicHttpRequest apiRegEndpoint = ClassicRequestBuilder.post(gatewayUrl + HandlerConstants.APP_REG_ENDPOINT) ClassicHttpRequest apiRegEndpoint = ClassicRequestBuilder.post(gatewayUrl + HandlerConstants.APP_REG_ENDPOINT)
.setEntity(HandlerUtil.constructAppRegPayload(tags, HandlerConstants.PUBLISHER_APPLICATION_NAME, .setEntity(HandlerUtil.constructAppRegPayload(tags, applicationName,
username, password, null, null)) username, password, null, supportedGrantTypes))
.setHeader(org.apache.hc.core5.http.HttpHeaders.CONTENT_TYPE, .setHeader(org.apache.hc.core5.http.HttpHeaders.CONTENT_TYPE,
org.apache.hc.core5.http.ContentType.APPLICATION_JSON.toString()) org.apache.hc.core5.http.ContentType.APPLICATION_JSON.toString())
.setHeader(org.apache.hc.core5.http.HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC + Base64.getEncoder().encodeToString((username + HandlerConstants.COLON + password).getBytes())) .setHeader(org.apache.hc.core5.http.HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC + Base64.getEncoder().encodeToString((username + HandlerConstants.COLON + password).getBytes()))
@ -114,7 +118,7 @@ public class LoginHandler extends HttpServlet {
encodedClientApp = Base64.getEncoder() encodedClientApp = Base64.getEncoder()
.encodeToString((clientId + HandlerConstants.COLON + clientSecret).getBytes()); .encodeToString((clientId + HandlerConstants.COLON + clientSecret).getBytes());
oAuthApp = new OAuthApp( oAuthApp = new OAuthApp(
HandlerConstants.PUBLISHER_APPLICATION_NAME, applicationName,
username, username,
clientId, clientId,
clientSecret, clientSecret,

Loading…
Cancel
Save