Package org.springframework.security.userdetails

Examples of org.springframework.security.userdetails.UserDetails


    userRoleDao.setUserRoles( mainTenant_1, USER_2, new String[] { ROLE_1, ROLE_2, ROLE_3 } );

    UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
    userDetailsService.setUserRoleDao( userRoleDao );
    userDetailsService.setDefaultRole( tenantAuthenticatedRoleName );
    UserDetails userFromService = userDetailsService.loadUserByUsername( USER_2 );

    assertTrue( userFromService.getUsername().equals( USER_2 ) );
    assertTrue( userFromService.getPassword() != null );
    assertTrue( userFromService.isEnabled() == true );
    assertTrue( userFromService.getAuthorities().length == 4 );

    assertTrue( userFromService.getAuthorities()[0].getAuthority().equals( ROLE_0 )
        || userFromService.getAuthorities()[0].getAuthority().equals( ROLE_3 )
        || userFromService.getAuthorities()[0].getAuthority().equals( ROLE_2 )
        || userFromService.getAuthorities()[0].getAuthority().equals( ROLE_1 ) );
    assertTrue( userFromService.getAuthorities()[1].getAuthority().equals( ROLE_0 )
        || userFromService.getAuthorities()[1].getAuthority().equals( ROLE_3 )
        || userFromService.getAuthorities()[1].getAuthority().equals( ROLE_2 )
        || userFromService.getAuthorities()[1].getAuthority().equals( ROLE_1 ) );
    assertTrue( userFromService.getAuthorities()[2].getAuthority().equals( ROLE_0 )
        || userFromService.getAuthorities()[2].getAuthority().equals( ROLE_3 )
        || userFromService.getAuthorities()[2].getAuthority().equals( ROLE_2 )
        || userFromService.getAuthorities()[2].getAuthority().equals( ROLE_1 ) );
    assertTrue( userFromService.getAuthorities()[3].getAuthority().equals( ROLE_0 )
        || userFromService.getAuthorities()[3].getAuthority().equals( ROLE_3 )
        || userFromService.getAuthorities()[3].getAuthority().equals( ROLE_2 )
        || userFromService.getAuthorities()[3].getAuthority().equals( ROLE_1 ) );

    cleanupUserAndRoles( mainTenant_1 );
  }
View Full Code Here


        Object userObj = auth.getPrincipal();
        if (userObj instanceof String) {
            return (String) userObj;
        } else if (userObj instanceof UserDetails) {
            UserDetails userDetails = (UserDetails) userObj;
            return userDetails.getUsername();
        }else {
            User user = (User) userObj;
            return user.getUsername();
        }
    }
View Full Code Here

  }

  @Override
  public GrantedAuthority[] getAuthoritiesForUser(String username) {
   
   UserDetails userDetails = userDetailsService.loadUserByUsername(username);
   return userDetails.getAuthorities();
  }
View Full Code Here

        try {
            FederationRequest wfReq = (FederationRequest)authentication.getCredentials();
            FederationProcessor wfProc = new FederationProcessorImpl();
            FederationResponse wfRes = wfProc.processRequest(wfReq, federationConfig.getFederationContext());

            final UserDetails userDetails = loadUserByFederationResponse(wfRes);
            userDetailsChecker.check(userDetails);
            return new FederationAuthenticationToken(userDetails, authentication.getCredentials(),
                    userDetails.getAuthorities(), userDetails, wfRes);
        } catch (Exception e) {
            LOG.error("Failed to validate SignIn request", e);
            throw new BadCredentialsException(e.getMessage(), e);
        }
    }
View Full Code Here

    UserDetailsServiceLocal userDetailsService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
        try {
            UserDetails user = userDetailsService.loadUserByUsername(username);
            if (user == null) {
                throw new UsernameNotFoundException(username);
            }
            return user;
        }
View Full Code Here

        List<User> users = dao.getUsers();
        assertEquals(3, users.size());
    }
   
    public void testLoadUser() throws Exception {
        UserDetails admin = dao.loadUserByUsername("admin");
        assertEquals("admin", admin.getUsername());
        assertEquals("gs", admin.getPassword());
        assertEquals(1, admin.getAuthorities().length);
        assertEquals("ROLE_ADMINISTRATOR", admin.getAuthorities()[0].getAuthority());
    }
View Full Code Here

    }
   
    public void testSetUser() throws Exception {
        dao.setUser(new User("wfs", "pwd", true, true, true, true,
                new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_WFS_ALL"), new GrantedAuthorityImpl("ROLE_WMS_ALL")}));
        UserDetails user = dao.loadUserByUsername("wfs");
        assertEquals("wfs", user.getUsername());
        assertEquals("pwd", user.getPassword());
        assertEquals(2, user.getAuthorities().length);
        // ok... order dependent... making one non order dep takes too much time...
        assertEquals("ROLE_WFS_ALL", user.getAuthorities()[0].getAuthority());
        assertEquals("ROLE_WMS_ALL", user.getAuthorities()[1].getAuthority());
    }
View Full Code Here

   
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException,
            DataAccessException {
        checkUserMap();

        UserDetails user = userMap.get(username);
        if (user == null)
            throw new UsernameNotFoundException("Could not find user: " + username);

        return user;
    }
View Full Code Here

       
        tester.assertErrorMessages(new String[0]);
        tester.assertRenderedPage(UserPage.class);
       
        dao.reload();
        UserDetails user = dao.loadUserByUsername("user");
        assertEquals("pwd", user.getPassword());
        assertEquals(1, user.getAuthorities().length);
    }
View Full Code Here

  private void syncChanges() throws IOException, ConfigurationException{
    Properties prop = new Properties();

    Iterator it = myDetailStorage.values().iterator();
    while (it.hasNext()){
      UserDetails details = (UserDetails)it.next();
      String key = details.getUsername();
      String value = details.getPassword();
      for (int i = 0; i < details.getAuthorities().length; i++){
  value+= "," + details.getAuthorities()[i].getAuthority();
      }
      if (!details.isEnabled()){
  value+=",disabled";
      }
      prop.setProperty(key, value);
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.userdetails.UserDetails

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.