Package org.springframework.security.openid

Examples of org.springframework.security.openid.OpenIDAuthenticationToken


    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");
View Full Code Here


     public void loadUserDetails_valid() {
       final User authUser=new UserImpl(USER_ID,USER_NAME);
        authUser.setOpenId(OPENID_VALID);
        expect(userRepository.getByOpenId(OPENID_VALID)).andReturn(authUser).anyTimes();
        replay(userRepository);
         OpenIDAuthenticationToken postAuthToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS,OPENID_VALID,
             "Some message", new ArrayList<OpenIDAttribute>());
         UserDetails result = service.loadUserDetails(postAuthToken);
         assertThat((User)result, is(sameInstance(authUser)));
         verify(userRepository);
     }
View Full Code Here

    
     @Test(expected = UsernameNotFoundException.class)
     public void loadUserDetails_invalid_exception() {
         expect(userRepository.getByOpenId(OPENID_INVALID)).andReturn(null);
         replay(userRepository);
         OpenIDAuthenticationToken postAuthToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS,OPENID_INVALID,
             "Some message", new ArrayList<OpenIDAttribute>());
         service.loadUserDetails(postAuthToken);
         verify(userRepository);
     }
View Full Code Here

    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");
View Full Code Here

     public void loadUserDetails_valid() {
       final User authUser=new UserImpl(USER_ID,USER_NAME);
        authUser.setOpenId(OPENID_VALID);
        expect(userRepository.getByOpenId(OPENID_VALID)).andReturn(authUser).anyTimes();
        replay(userRepository);
         OpenIDAuthenticationToken postAuthToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS,OPENID_VALID,
             "Some message", new ArrayList<OpenIDAttribute>());
         UserDetails result = service.loadUserDetails(postAuthToken);
         assertThat((User)result, is(sameInstance(authUser)));
         verify(userRepository);
     }
View Full Code Here

    
     @Test(expected = UsernameNotFoundException.class)
     public void loadUserDetails_invalid_exception() {
         expect(userRepository.getByOpenId(OPENID_INVALID)).andReturn(null);
         replay(userRepository);
         OpenIDAuthenticationToken postAuthToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS,OPENID_INVALID,
             "Some message", new ArrayList<OpenIDAttribute>());
         service.loadUserDetails(postAuthToken);
         verify(userRepository);
     }
View Full Code Here

    @Before
    public void setup() {       
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        handler = new OpenIDAuthenticationFailureHandler();
        postAuthToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS,NON_REGISTERED_OPENID_USER,
            MESSAGE, new ArrayList<OpenIDAttribute>());
        authException = new UsernameNotFoundException("");
}
View Full Code Here

    if (log.isDebugEnabled()) {
      log.debug("Supplied OpenID identity is " + identity);
    }

    try {
      OpenIDAuthenticationToken token = consumer.endConsumption(request);

      String verifiedId = (String) token.getPrincipal();
      ConnectionData data = new ConnectionData(connectionFactory.getProviderId(), verifiedId, null, null, null,
          null, null, null, null);

      return new SocialAuthenticationToken(connectionFactory.createConnection(data), obtainAccountData(token));
    } catch (OpenIDConsumerException oice) {
View Full Code Here

      }

    } else {

      try {
        OpenIDAuthenticationToken token = openIDConsumer.endConsumption(request);
        if (token.getStatus() == OpenIDAuthenticationStatus.SUCCESS) {
          // Check that the OpenID isn't already mapped
          String openId = token.getIdentityUrl();
          if (securityRealm.getUserForOpenId(openId) != null) {
            validationContext.addError("The OpenID supplied is already mapped to a user.");
          } else {
            // Add it
            securityRealm.addOpenIdToUser(userDetails, openId);
            return new RedirectView(blog.getUrl() + "/editUserPreferences.secureaction");
          }
        } else {
          validationContext.addError(StringUtils.transformHTML(token.getMessage()));
        }

      } catch (OpenIDConsumerException oice) {
        log.error("Error in consumer", oice);
        validationContext.addError("Error adding OpenID " + oice.getMessage());
View Full Code Here

     public void loadUserDetails_valid() {
       final User authUser=new UserImpl(USER_ID,USER_NAME);
        authUser.setOpenId(OPENID_VALID);
        expect(userRepository.getByOpenId(OPENID_VALID)).andReturn(authUser).anyTimes();
        replay(userRepository);
         OpenIDAuthenticationToken postAuthToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS,OPENID_VALID,
             "Some message", new ArrayList<OpenIDAttribute>());
         UserDetails result = service.loadUserDetails(postAuthToken);
         assertThat((User)result, is(sameInstance(authUser)));
         verify(userRepository);
     }
View Full Code Here

TOP

Related Classes of org.springframework.security.openid.OpenIDAuthenticationToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.