Examples of OpenIDAuthenticationToken


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

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

Examples of org.springframework.security.openid.OpenIDAuthenticationToken

        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

Examples of org.springframework.security.openid.OpenIDAuthenticationToken

     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

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

Examples of org.springframework.security.openid.OpenIDAuthenticationToken

 
  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

Examples of org.springframework.security.openid.OpenIDAuthenticationToken

    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

Examples of org.springframework.security.providers.openid.OpenIDAuthenticationToken

    private String claimedIdentityFieldName = DEFAULT_CLAIMED_IDENTITY_FIELD;
    private static Log log = LogFactory.getLog(CustomOpenIDAuthenticationProcessingFilter.class);

    @Override
    public Authentication attemptAuthentication(HttpServletRequest req) throws AuthenticationException {
        OpenIDAuthenticationToken auth = null;

        // Processing standard OpenId user authentication   
        auth = (OpenIDAuthenticationToken) super.attemptAuthentication(req);

        if (auth.getAuthorities()[0].getAuthority().equals("openidLogin")) {

            /* TODO: when Spring Security 2.1 is released, we can uncomment
             * this code, which will allow us to pre-populate the new user
             * registration form with information from the OpenID Provider.
             *
 
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.