Package org.springframework.security.openid

Examples of org.springframework.security.openid.OpenIDAuthenticationToken


    
     @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

        userService.add(user);
        Set<String> openIdIdentifiers = new HashSet<String>();
        openIdIdentifiers.add("oldOpenIdIdentifier");
        user.setOpenIdIdentifiers(openIdIdentifiers);

        OpenIDAuthenticationToken token = mock(OpenIDAuthenticationToken.class);
        when(token.getName()).thenReturn("newOpenIdIdentifier");
        List<OpenIDAttribute> attributes = new ArrayList<OpenIDAttribute>();
        List<String> attributeValues = new ArrayList<String>();
        attributeValues.add(user.getEmail());
        OpenIDAttribute attribute = new OpenIDAttribute("email", "", attributeValues);
        attributes.add(attribute);
        when(token.getAttributes()).thenReturn(attributes);

        UserDetails userDetails = userDetailsService.loadUserDetails(token);
        assertNotNull(userDetails);
        assertTrue(userDetails.getUsername().equals(user.getEmail()));
    }
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 String getActivationMessage() {
    /*check if the email can be retrieved from openID attributes
     *  if it it belongs to a registered user, send the activation email in a separate thread
     */
    OpenIDAuthenticationToken token = (OpenIDAuthenticationToken)SecurityContextHolder.getContext().getAuthentication();
    // get the email attribute
    String email = null;
    if (token == null) {
      log.error("OpenIDAuthenticationToken is null");
      return "Email address was not found in response " + MartinlawConstants.OPENID_ERROR_MSG_INDICATOR;
    } else {
      List<OpenIDAttribute> attributes = token.getAttributes();
      for (OpenIDAttribute attr: attributes) {
        if (StringUtils.contains(attr.getName(), "email")) {
          email = attr.getValues().get(0);
          break;
        }
      }
    }
   
    if (email == null) {
      log.error("Email attribute was not found in attributes");
      return "Email address was not found in response " + MartinlawConstants.OPENID_ERROR_MSG_INDICATOR;
    } else {
      EntityContract entity = getEntityInfoService().getEntityByEmail(email);
     
      if (entity == null) {
        return "Email address '" + email + "' is not associated with an existing user"
             + MartinlawConstants.OPENID_ERROR_MSG_INDICATOR;
      } else if (!hasEmploymentAffiliation(entity)) {
        return "You are not affiliated as a staff :(";
      } else if (!entity.isActive()) {
        return "Your account is not active :(";
      } else {
        if (emailSetupOk()) {
          String fromAddr = getParameterService().getParameterValueAsString(
              KewApiConstants.KEW_NAMESPACE, "Mailer", KewApiConstants.EMAIL_REMINDER_FROM_ADDRESS);
          createAndEmailActivation(email, token.getIdentityUrl(), entity, fromAddr);
          return entity.getDefaultName().getFirstName() +
            ", an activation email has been sent to '" + email + "' from address '" + fromAddr 
            + "'. If none comes to your inbox or spam folder after a few minutes, please contact support";
        } else {
          return "An activation email could not be sent to '" + email +
View Full Code Here

    List<String> values = new ArrayList<String>(1);
    final String emailFromOpenId = "clerk3@localhost";
    values.add(emailFromOpenId);
    List<OpenIDAttribute> attributes = new ArrayList<OpenIDAttribute>();
   
    OpenIDAuthenticationToken token = new OpenIDAuthenticationToken(null, "url", "msg", attributes);
    context.setAuthentication(token);
    SecurityContextHolder.setContext(context);
   
    BusinessObjectService boSvc = mock(BusinessObjectService.class);
    successHandler.setBusinessObjectService(boSvc);
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.