List of usage examples for org.springframework.security.openid OpenIDAuthenticationToken setAuthenticated
public void setAuthenticated(boolean authenticated)
From source file:net.triptech.buildulator.service.OpenIdAuthenticationFailureHandler.java
/** * Called when an authentication attempt fails. * * @param request - the request during which the authentication attempt occurred. * @param response - the response./* w w w. ja va 2 s . c o m*/ * @param exception - the exception which was thrown to reject the authentication * request. * @throws java.io.IOException * @throws javax.servlet.ServletException */ @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException authenticationException) throws IOException, ServletException { if (authenticationException instanceof DisabledException) { RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); redirectStrategy.sendRedirect(request, response, "/accountDisabled"); } if (isFailedDueToUserNotRegistered(authenticationException)) { OpenIDAuthenticationToken token = (OpenIDAuthenticationToken) authenticationException .getAuthentication(); Person person = Person.findByOpenIdIdentifier(token.getIdentityUrl()); if (person == null) { // The person does not exist, create person = createPerson(token); // Recreate OpenIDAuthentication token, transfer values from existing // token, and assign roles from retrieved user. Since grantedAuthorities // is unmodifiable list and no way to update the pre created token. OpenIDAuthenticationToken newToken = new OpenIDAuthenticationToken(person, person.getAuthorities(), token.getIdentityUrl(), token.getAttributes()); newToken.setAuthenticated(true); token.setDetails(person); SecurityContextHolder.getContext().setAuthentication(newToken); // Transfer any previous projects to the new user transferProjects(request, person); RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); redirectStrategy.sendRedirect(request, response, "/user"); } } }
From source file:net.triptech.metahive.service.OpenIdAuthenticationFailureHandler.java
/** * Called when an authentication attempt fails. * * @param request - the request during which the authentication attempt occurred. * @param response - the response./*w w w . j av a2s . c om*/ * @param exception - the exception which was thrown to reject the authentication * request. * @throws java.io.IOException * @throws javax.servlet.ServletException */ @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException authenticationException) throws IOException, ServletException { if (authenticationException instanceof DisabledException) { RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); redirectStrategy.sendRedirect(request, response, "/accountDisabled"); } if (isFailedDueToUserNotRegistered(authenticationException)) { OpenIDAuthenticationToken token = (OpenIDAuthenticationToken) authenticationException .getAuthentication(); String id = token.getIdentityUrl(); List<Person> people = Person.findPeopleByOpenIdIdentifier(id).getResultList(); Person person = people.size() == 0 ? null : people.get(0); if (person == null) { // The person does not exist, create person = createPerson(token); // Recreate OpenIDAuthentication token, transfer values from existing // token, and assign roles from retrieved user. Since grantedAuthorities // is unmodifiable list and no way to update the pre created token. OpenIDAuthenticationToken newToken = new OpenIDAuthenticationToken(person, person.getAuthorities(), token.getIdentityUrl(), token.getAttributes()); newToken.setAuthenticated(true); token.setDetails(person); SecurityContextHolder.getContext().setAuthentication(newToken); RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); redirectStrategy.sendRedirect(request, response, "/user"); } } }