List of usage examples for org.springframework.security.core AuthenticationException getCause
public synchronized Throwable getCause()
From source file:org.carewebframework.security.spring.controller.LoginWindowController.java
/** * If this authentication exception (or its cause) is of the expected type, return it. * Otherwise, return null.//from w w w. j av a 2s . c o m * * @param exc The authentication exception. * @param clazz The desired type. * @return The original exception or its cause if one of them is of the expected type. */ @SuppressWarnings("unchecked") protected static <T extends AuthenticationException> T getException(AuthenticationException exc, Class<T> clazz) { if (exc != null) { if (clazz.isInstance(exc)) { return (T) exc; } else if (clazz.isInstance(exc.getCause())) { return (T) exc.getCause(); } } return null; }
From source file:com.iflytek.edu.cloud.frame.spring.OAuth2AuthenticationEntryPointExt.java
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { if (authException.getCause() instanceof InvalidTokenException) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); MainError mainError = MainErrors.getError(MainErrorType.INVALID_ACCESS_TOKEN, (Locale) request.getAttribute("locale")); messageConverter.convertData(request, response, mainError); } else {//from ww w .j a v a 2 s . c o m response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); doHandle(request, response, authException); } }
From source file:org.jutge.joc.porra.controller.desktop.DesktopAccountController.java
private void validateLoginParams(final HttpSession session, final HttpServletRequest request) throws LoginException { final AuthenticationException authenticationException = (AuthenticationException) session .getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); if (authenticationException != null) { final Throwable cause = authenticationException.getCause(); if (cause instanceof LoginException) { final LoginException loginException = (LoginException) cause; throw loginException; }/* w w w .j a v a 2 s . c o m*/ } }
From source file:com.nec.harvest.controller.LoginController.java
/** * The REST handle login event for the given username and password * //from ww w .j av a2 s . c o m * @param request * A HttpServletRequest * @param model * Spring's model that can be used to render a view * @return A redirect URL */ @RequestMapping(value = "/login**") public String login(@RequestParam(value = "error", required = false) boolean error, @SessionAttribute(WebAttributes.AUTHENTICATION_EXCEPTION) AuthenticationException authException, final HttpServletRequest request, final Model model) { if (logger.isDebugEnabled()) { logger.debug("Rendering the loggin page..."); } // Get close confirm message when user click CLOSE application button on the login page model.addAttribute(Constants.CFM_CLOSE_APPLICATION_MESSAGE, getCloseAppMsg()); // if (error && authException != null) { logger.warn(authException.getMessage()); Message message; // ?????????? if (authException instanceof BadCredentialsException) { message = MessageHelper.get(MsgConstants.AF001_ENT_CHK_M01); } else { Throwable throwable = authException.getCause(); if (throwable instanceof HarvestAuthenticationException) { message = MessageHelper.get(MsgConstants.AF001_ENT_CHK_M01); } else if (throwable instanceof OrganizationNotFoundException) { message = MessageHelper.get(MsgConstants.AF001_ENT_CHK_M02); } else if (authException instanceof AuthenticationServiceException) { // NOTE: This case is authentication method not supported: GET logger.warn(authException.getMessage()); // This exception will be throw when end-user type directly or try to access // by URL: .../j_spring_security_check message = MessageHelper.get(MsgConstants.AF001_ENT_CHK_M01); } else { message = getSystemError(); if (logger.isDebugEnabled()) { logger.debug(authException.getMessage(), authException.getCause()); } // logger.error(authException.getMessage(), authException.getCause()); } } // model.addAttribute(ERROR, true); model.addAttribute(ERROR_MESSAGE, message); // Clear authentication exception from the SESSION request.getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, null); } return getViewName(); }