Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void processAuthenticationResponse(HttpServletRequest request,
- HttpServletResponse response, AuthenticationContext context)
- throws AuthenticationFailedException {
- String username = request.getParameter("username");
- String password = request.getParameter("password");
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> username: " + username);
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> password: " + password);
- boolean isAuthenticated = false;
- // Check the authentication
- try {
- int tenantId = IdentityUtil.getTenantIdOFUser(username);
- UserRealm userRealm = BasicCustomAuthenticatorComponent.getRealmService()
- .getTenantUserRealm(tenantId);
- if (userRealm != null) {
- UserStoreManager userStoreManager = (UserStoreManager)userRealm.getUserStoreManager();
- isAuthenticated = userStoreManager.authenticate(MultitenantUtils.getTenantAwareUsername(username),password);
- Map<String, String> parameterMap = getAuthenticatorConfig().getParameterMap();
- String FrstPWDUseOccrClaim = null;
- if(parameterMap != null) {
- FrstPWDUseOccrClaim = parameterMap.get("firstUsePwdEventClaimUri");
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> FrstPWDUseOccrClaim: " + FrstPWDUseOccrClaim);
- }
- if (FrstPWDUseOccrClaim == null) {
- FrstPWDUseOccrClaim = "http://wso2.org/claims/firstUsePwdEvent";
- System.out.println("+++++++++++++++++++++++++ FrstPWDUseOccrClaim: " + FrstPWDUseOccrClaim);
- }
- if(log.isDebugEnabled()) {
- log.debug("first use pwd event claim has been set as : " + FrstPWDUseOccrClaim);
- }
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MultitenantUtils.getTenantAwareUsername(username) : "+ MultitenantUtils.getTenantAwareUsername(username));
- String frstPWDUseOccr = userStoreManager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername(username),
- FrstPWDUseOccrClaim, null);
- boolean isFrstPWDUseOccr = false;
- if (frstPWDUseOccr!=null)
- isFrstPWDUseOccr = frstPWDUseOccr.equalsIgnoreCase("1");
- if (isAuthenticated && isFrstPWDUseOccr) {
- System.out.println("user password must be changed! due to userPassword used first!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- if (log.isDebugEnabled()) {
- log.debug("user password must be changed! due to userPassword used first");
- }
- //todo
- AuthenticationContext authenticationContext = FrameworkUtils.getContextData(request);
- String redirectURL = CarbonUIUtil.getAdminConsoleURL(request);
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>> : redirectURL before changes: " + redirectURL);
- redirectURL = redirectURL.replace("commonauth/carbon/", "authenticationendpoint/pwdreset.do");
- String queryParams = FrameworkUtils
- .getQueryStringWithFrameworkContextId(context.getQueryParams(),
- context.getCallerSessionKey(),
- context.getContextIdentifier());
- queryParams += "&authenticators=" + getName() + ":" + "LOCAL";
- //redirectURL += "?" + queryParams;
- System.out.println(">>>>>>>>>>>>>>>>>>>>>> authenticationContext.getRelyingParty() :" + authenticationContext.getRelyingParty());
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>> context.getCallerPath() : before changes : " + context.getCallerPath());
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>maxLoginAttemptCount : " + ConfigurationFacade.getInstance().getMaxLoginAttemptCount());
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> context.getSessionIdentifier() : " + context.getSessionIdentifier());
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> context.getCallerSessionKey() : " + context.getCallerSessionKey());
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> context.getContextIdentifier() : " + context.getContextIdentifier());
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> context.getContextIdIncludedQueryParams() : " + context.getContextIdIncludedQueryParams());
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> : request.getParameter(sessionDataKey) : " + request.getParameter("sessionDataKey"));
- String loginPage = ConfigurationFacade.getInstance().getAuthenticationEndpointURL();
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> : loginPage" + loginPage);
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> context.getQueryParams() :" + context.getQueryParams());
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> redirectURL : " + redirectURL);
- context.setProperty("username", username);
- context.setProperty("queryParams", queryParams);
- context.setCallerPath(redirectURL);
- context.setSubject(username);
- /*
- String redirectURL = CarbonUIUtil.getAdminConsoleURL(request);
- redirectURL = redirectURL.replace("commonauth/carbon/", "authenticationendpoint/pwdreset.do");
- response.sendRedirect(redirectURL);
- */
- } else {
- System.out.println("user password must be not changed! due to userPassword first is not occured!!!!!!!!!!!!!!!!!!!!!");
- }
- } else {
- throw new AuthenticationFailedException("Cannot find the user realm for the given tenant: " + tenantId);
- }
- } catch (IdentityException e) {
- log.error("CustomAuthentication failed while trying to get the tenant ID of the use", e);
- throw new AuthenticationFailedException(e.getMessage(), e);
- } catch (org.wso2.carbon.user.api.UserStoreException e) {
- log.error("CustomAuthentication failed while trying to authenticate", e);
- throw new AuthenticationFailedException(e.getMessage(), e);
- /*
- } catch (IOException e) {
- throw new AuthenticationFailedException(e.getMessage(), e);
- */
- }
- redirectURL = redirectURL+.replace("commonauth/carbon/", "authenticationendpoint/pwdreset.do?"+AssertionConsumerURL);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement