|
|
@ -50,8 +50,6 @@ import javax.servlet.http.HttpSession;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Base64;
|
|
|
|
import java.util.Base64;
|
|
|
|
|
|
|
|
|
|
|
|
import static io.entgra.ui.request.interceptor.util.HandlerUtil.execute;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@MultipartConfig
|
|
|
|
@MultipartConfig
|
|
|
|
@WebServlet("/login")
|
|
|
|
@WebServlet("/login")
|
|
|
|
public class LoginHandler extends HttpServlet {
|
|
|
|
public class LoginHandler extends HttpServlet {
|
|
|
@ -78,12 +76,12 @@ public class LoginHandler extends HttpServlet {
|
|
|
|
httpSession.invalidate();
|
|
|
|
httpSession.invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
httpSession = req.getSession(true);
|
|
|
|
httpSession = req.getSession(true);
|
|
|
|
//setting session to expiry in 5 mins
|
|
|
|
//setting session to expiry in 5 minutes
|
|
|
|
httpSession.setMaxInactiveInterval(Math.toIntExact(HandlerConstants.TIMEOUT));
|
|
|
|
httpSession.setMaxInactiveInterval(Math.toIntExact(HandlerConstants.TIMEOUT));
|
|
|
|
|
|
|
|
|
|
|
|
HttpGet uiConfigEndpoint = new HttpGet(uiConfigUrl);
|
|
|
|
HttpGet uiConfigEndpoint = new HttpGet(uiConfigUrl);
|
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
|
ProxyResponse uiConfigResponse = execute(uiConfigEndpoint);
|
|
|
|
ProxyResponse uiConfigResponse = HandlerUtil.execute(uiConfigEndpoint);
|
|
|
|
String executorResponse = uiConfigResponse.getExecutorResponse();
|
|
|
|
String executorResponse = uiConfigResponse.getExecutorResponse();
|
|
|
|
if (!StringUtils.isEmpty(executorResponse) && executorResponse
|
|
|
|
if (!StringUtils.isEmpty(executorResponse) && executorResponse
|
|
|
|
.contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
|
|
|
|
.contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
|
|
|
@ -126,7 +124,7 @@ public class LoginHandler extends HttpServlet {
|
|
|
|
apiRegEndpoint.setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
|
|
|
|
apiRegEndpoint.setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
|
|
|
|
apiRegEndpoint.setEntity(constructAppRegPayload(tags));
|
|
|
|
apiRegEndpoint.setEntity(constructAppRegPayload(tags));
|
|
|
|
|
|
|
|
|
|
|
|
ProxyResponse clientAppResponse = execute(apiRegEndpoint);
|
|
|
|
ProxyResponse clientAppResponse = HandlerUtil.execute(apiRegEndpoint);
|
|
|
|
String clientAppResult = clientAppResponse.getData();
|
|
|
|
String clientAppResult = clientAppResponse.getData();
|
|
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(clientAppResult) && getTokenAndPersistInSession(req, resp,
|
|
|
|
if (!StringUtils.isEmpty(clientAppResult) && getTokenAndPersistInSession(req, resp,
|
|
|
@ -141,11 +139,11 @@ public class LoginHandler extends HttpServlet {
|
|
|
|
HandlerUtil.handleError(req, resp, serverUrl, platform, null);
|
|
|
|
HandlerUtil.handleError(req, resp, serverUrl, platform, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
log.error("Error occured while sending the response into the socket. ", e);
|
|
|
|
log.error("Error occurred while sending the response into the socket. ", e);
|
|
|
|
} catch (JsonSyntaxException e) {
|
|
|
|
} catch (JsonSyntaxException e) {
|
|
|
|
log.error("Error occured while parsing the response. ", e);
|
|
|
|
log.error("Error occurred while parsing the response. ", e);
|
|
|
|
} catch (LoginException e) {
|
|
|
|
} catch (LoginException e) {
|
|
|
|
log.error("Error occured while getting token data. ", e);
|
|
|
|
log.error("Error occurred while getting token data. ", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -203,7 +201,7 @@ public class LoginHandler extends HttpServlet {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new LoginException("Error occured while sending the response into the socket", e);
|
|
|
|
throw new LoginException("Error occurred while sending the response into the socket", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -216,8 +214,8 @@ public class LoginHandler extends HttpServlet {
|
|
|
|
if (scopes != null && scopes.size() > 0) {
|
|
|
|
if (scopes != null && scopes.size() > 0) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
for (JsonElement scope : scopes) {
|
|
|
|
for (JsonElement scope : scopes) {
|
|
|
|
String tmpscope = scope.getAsString() + " ";
|
|
|
|
String tmpScope = scope.getAsString() + " ";
|
|
|
|
builder.append(tmpscope);
|
|
|
|
builder.append(tmpScope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return builder.toString();
|
|
|
|
return builder.toString();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -248,7 +246,7 @@ public class LoginHandler extends HttpServlet {
|
|
|
|
" Invalid login request. Username or Password is not received for login request.");
|
|
|
|
" Invalid login request. Username or Password is not received for login request.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new LoginException("Error Occured while redirecting to default error page.", e);
|
|
|
|
throw new LoginException("Error occurred while redirecting to default error page.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -271,13 +269,13 @@ public class LoginHandler extends HttpServlet {
|
|
|
|
* @param encodedClientApp - Base64 encoded clientId:clientSecret.
|
|
|
|
* @param encodedClientApp - Base64 encoded clientId:clientSecret.
|
|
|
|
* @param scopes - Scopes which are retrieved by reading application-mgt configuration
|
|
|
|
* @param scopes - Scopes which are retrieved by reading application-mgt configuration
|
|
|
|
* @return Invoke token endpoint and return the response as string.
|
|
|
|
* @return Invoke token endpoint and return the response as string.
|
|
|
|
* @throws IOException IO exception throws if an error occured when invoking token endpoint
|
|
|
|
* @throws IOException IO exception throws if an error occurred when invoking token endpoint
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ProxyResponse getTokenResult(String encodedClientApp, JsonArray scopes) throws IOException {
|
|
|
|
private ProxyResponse getTokenResult(String encodedClientApp, JsonArray scopes) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
HttpPost tokenEndpoint = new HttpPost(serverUrl + HandlerConstants.TOKEN_ENDPOINT);
|
|
|
|
HttpPost tokenEndpoint = new HttpPost(serverUrl + HandlerConstants.TOKEN_ENDPOINT);
|
|
|
|
tokenEndpoint.setHeader("Authorization", "Basic " + encodedClientApp);
|
|
|
|
tokenEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC + encodedClientApp);
|
|
|
|
tokenEndpoint.setHeader("Content-Type", ContentType.APPLICATION_FORM_URLENCODED.toString());
|
|
|
|
tokenEndpoint.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString());
|
|
|
|
String scopeString = getScopeString(scopes);
|
|
|
|
String scopeString = getScopeString(scopes);
|
|
|
|
|
|
|
|
|
|
|
|
if (scopeString != null) {
|
|
|
|
if (scopeString != null) {
|
|
|
@ -290,6 +288,6 @@ public class LoginHandler extends HttpServlet {
|
|
|
|
"grant_type=password&username=" + username + "&password=" + password + "&scope=" + scopeString,
|
|
|
|
"grant_type=password&username=" + username + "&password=" + password + "&scope=" + scopeString,
|
|
|
|
ContentType.APPLICATION_FORM_URLENCODED);
|
|
|
|
ContentType.APPLICATION_FORM_URLENCODED);
|
|
|
|
tokenEndpoint.setEntity(tokenEPPayload);
|
|
|
|
tokenEndpoint.setEntity(tokenEPPayload);
|
|
|
|
return execute(tokenEndpoint);
|
|
|
|
return HandlerUtil.execute(tokenEndpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|