List of usage examples for org.springframework.security.openid OpenIDAuthenticationStatus SUCCESS
OpenIDAuthenticationStatus SUCCESS
To view the source code for org.springframework.security.openid OpenIDAuthenticationStatus SUCCESS.
Click Source Link
From source file:net.firejack.platform.web.security.spring.openid.OpenIDAuthenticationManager.java
@Override protected Authentication doAuthentication(Authentication authentication) throws AuthenticationException { if (authentication instanceof OpenIDAuthenticationToken) { OpenIDAuthenticationToken token = (OpenIDAuthenticationToken) authentication; if (!OpenIDAuthenticationStatus.SUCCESS.equals(token.getStatus())) { String errorMessage = MessageResolver.messageFormatting("login.wrong.credentials", null); throw new BadCredentialsException(errorMessage); }/*from www . j a v a2s . c om*/ String email = findAttributeValueByName(SupportedOpenIDAttribute.EMAIL, token.getAttributes()); if (StringUtils.isBlank(email)) { String errorMessage = MessageResolver.messageFormatting("login.wrong.credentials", null); throw new BadCredentialsException(errorMessage); } HttpSession session = ((SessionContainerWebAuthenticationDetails) token.getDetails()).getSession(); if (authenticator != null) { AuthenticatorFactory authenticatorFactory = AuthenticatorFactory.getInstance(); Map<SupportedOpenIDAttribute, String> attributeValues = findAttributeValues(token.getAttributes()); OpenIDAuthenticationSource openIDAuthenticationSource = (OpenIDAuthenticationSource) authenticatorFactory .provideOpenIDAuthenticationSource(email, attributeValues); IAuthenticationDetails authenticationDetails = authenticator .authenticate(openIDAuthenticationSource); if (authenticationDetails != null) { return generateDefaultToken(authenticationDetails, session); } } } String errorMessage = MessageResolver.messageFormatting("login.authentication.failure", null); throw new BadCredentialsException(errorMessage); }
From source file:grails.plugin.springsecurity.openid.OpenIdAuthenticationFailureHandler.java
protected boolean isSuccessfulLoginUnknownUser(AuthenticationException exception) { if (!(exception instanceof UsernameNotFoundException)) { return false; }/*www.java 2 s . com*/ Authentication authentication = exception.getAuthentication(); if (!(authentication instanceof OpenIDAuthenticationToken)) { return false; } return OpenIDAuthenticationStatus.SUCCESS.equals(((OpenIDAuthenticationToken) authentication).getStatus()); }
From source file:net.triptech.buildulator.service.OpenIdAuthenticationFailureHandler.java
/** * Checks if is failed due to user not registered. * * @param authenticationException the authentication exception * @return true, if is failed due to user not registered *//*from ww w . j a va 2 s . c o m*/ private boolean isFailedDueToUserNotRegistered(AuthenticationException authenticationException) { return null != authenticationException && authenticationException instanceof UsernameNotFoundException && authenticationException.getAuthentication() instanceof OpenIDAuthenticationToken && ((OpenIDAuthenticationToken) authenticationException.getAuthentication()).getStatus() .equals(OpenIDAuthenticationStatus.SUCCESS); }
From source file:org.mitre.provenance.openid.OpenId4JavaProxyConsumer.java
public OpenIDAuthenticationToken endConsumption(HttpServletRequest request) throws OpenIDConsumerException { // extract the parameters from the authentication response // (which comes in as a HTTP request from the OpenID provider) ParameterList openidResp = new ParameterList(request.getParameterMap()); // retrieve the previously stored discovery information DiscoveryInformation discovered = (DiscoveryInformation) request.getSession() .getAttribute(DISCOVERY_INFO_KEY); if (discovered == null) { throw new OpenIDConsumerException( "DiscoveryInformation is not available. Possible causes are lost session or replay attack"); }//ww w . j ava2s .c o m List<OpenIDAttribute> attributesToFetch = (List<OpenIDAttribute>) request.getSession() .getAttribute(ATTRIBUTE_LIST_KEY); request.getSession().removeAttribute(DISCOVERY_INFO_KEY); request.getSession().removeAttribute(ATTRIBUTE_LIST_KEY); // extract the receiving URL from the HTTP request StringBuffer receivingURL = request.getRequestURL(); String queryString = request.getQueryString(); if (StringUtils.hasLength(queryString)) { receivingURL.append("?").append(request.getQueryString()); } // verify the response VerificationResult verification; try { verification = consumerManager.verify(receivingURL.toString(), openidResp, discovered); } catch (MessageException e) { throw new OpenIDConsumerException("Error verifying openid response", e); } catch (DiscoveryException e) { throw new OpenIDConsumerException("Error verifying openid response", e); } catch (AssociationException e) { throw new OpenIDConsumerException("Error verifying openid response", e); } // examine the verification result and extract the verified identifier Identifier verified = verification.getVerifiedId(); if (verified == null) { Identifier id = discovered.getClaimedIdentifier(); return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE, id == null ? "Unknown" : id.getIdentifier(), "Verification status message: [" + verification.getStatusMsg() + "]", Collections.<OpenIDAttribute>emptyList()); } List<OpenIDAttribute> attributes = fetchAxAttributes(verification.getAuthResponse(), attributesToFetch); return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS, verified.getIdentifier(), "some message", attributes); }
From source file:org.apache.rave.portal.web.controller.handler.OpenIDAuthenticationFailureHandler.java
@Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { if (exception instanceof UsernameNotFoundException && exception.getAuthentication() instanceof OpenIDAuthenticationToken && ((OpenIDAuthenticationToken) exception.getAuthentication()).getStatus() .equals(OpenIDAuthenticationStatus.SUCCESS)) { OpenIDAuthenticationToken token = (OpenIDAuthenticationToken) exception.getAuthentication(); String url = token.getIdentityUrl(); User user = createTemporaryUser(token, url); request.getSession(true).setAttribute(ModelKeys.NEW_USER, user); DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); log.info("Redirecting to new user account creation page"); super.setRedirectStrategy(redirectStrategy); redirectStrategy.sendRedirect(request, response, "/" + ViewNames.CREATE_ACCOUNT_PAGE); return;//from w w w . j a v a 2 s .c om } else { super.onAuthenticationFailure(request, response, exception); } }