Package org.springframework.security.core

Examples of org.springframework.security.core.GrantedAuthority


                .overridingErrorMessage( "Expected <1> granted authority but found <%d>",
                        authorities.size()
                )
                .isEqualTo(1);

        GrantedAuthority authority = authorities.iterator().next();

        Assertions.assertThat(authority.getAuthority())
                .overridingErrorMessage( "Expected authority to be <ROLE_USER> but was <%s>",
                        authority.getAuthority()
                )
                .isEqualTo(Role.ROLE_USER.name());

        return this;
    }
View Full Code Here


    List<Role> roles = roleDao.getRolesByCoUser(usuario.getId());
    Collection<GrantedAuthority> collection = new HashSet<GrantedAuthority>();
   
    for (int i=0; i<roles.size();i++) {
      Role role = roles.get(i);
      GrantedAuthority autoridad = new GrantedAuthorityImpl(role.getName());
      collection.add(autoridad);
    }
   
    UsernamePasswordAuthenticationToken result = new
    UsernamePasswordAuthenticationToken(usuario, password, collection);
View Full Code Here

    @PostConstruct
    public void init() {
        if (userGrantedAuthorities.size() == 0) { // to prevent a bug that makes this bean initialized twice
            //Roles for "normal" users
            GrantedAuthority roleUser = new SimpleGrantedAuthority("ROLE_USER");
            userGrantedAuthorities.add(roleUser);

            //Roles for "admin" users, configured in tatami.properties
            GrantedAuthority roleAdmin = new SimpleGrantedAuthority("ROLE_ADMIN");
            adminGrantedAuthorities.add(roleUser);
            adminGrantedAuthorities.add(roleAdmin);

            String adminUsersList = env.getProperty("tatami.admin.users");
            String[] adminUsersArray = adminUsersList.split(",");
View Full Code Here

    private SearchService searchService;

    @Test
    public void resetElasticSearch() throws InterruptedException {
        // The user needs to have the admin role
        GrantedAuthority adminAuthority = new SimpleGrantedAuthority("ROLE_ADMIN");
        Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
        grantedAuthorities.add(adminAuthority);

        org.springframework.security.core.userdetails.User userDetails =
                new org.springframework.security.core.userdetails.User("tatami@ippon.fr", "", grantedAuthorities);
View Full Code Here

*/
public class AuthorityTest {

    @Test
    public void testAuthority() throws Exception {
        GrantedAuthority grantedAuthority = new Authority();
        ((Authority) grantedAuthority).setAuthority("user");
        assertEquals("user", grantedAuthority.getAuthority());

    }
View Full Code Here

        replay(userRepository);

        service.setAuthenticatedUser(USER_ID);
        assertThat((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(),
                is(sameInstance(authUser)));
        final GrantedAuthority grantedAuthority =
                SecurityContextHolder.getContext().getAuthentication().getAuthorities().iterator().next();
        assertEquals("has authority admin", "admin", grantedAuthority.getAuthority());
        verify(userRepository);
    }
View Full Code Here

  {
    Authentication existingAuthentication = SecurityContextHolder.getContext().getAuthentication();
    Set<String> unconnectedProviders = new HashSet<String>();
    for (String registeredProviderId : connectionFactoryLocator.registeredProviderIds())
    {
      GrantedAuthority providerAuthority = userAuthoritiesService.getProviderAuthority(registeredProviderId);
      if (existingAuthentication == null || !existingAuthentication.getAuthorities().contains(providerAuthority))
      {
        unconnectedProviders.add(registeredProviderId);
      }
    }
View Full Code Here

        .getAuthentication();
   
    Collection<? extends GrantedAuthority> existingAuthorities = authentication
        .getAuthorities();
   
    GrantedAuthority newAuthority = userAuthoritiesService
        .getProviderAuthority(connection.getKey());
   
    if (!existingAuthorities.contains(newAuthority)) {
     
      Authentication newAuthentication = authenticationFactory
View Full Code Here

        Authentication auth = SecurityContextHolder.getContext()
                .getAuthentication();
        if (auth == null) {
            return false;
        }
        GrantedAuthority anonymous = new SimpleGrantedAuthority(
                "ROLE_ANONYMOUS");
        return !auth.getAuthorities().contains(anonymous);
    }
View Full Code Here

        replay(userRepository);

        service.setAuthenticatedUser(USER_ID);
        assertThat((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(),
                is(sameInstance(authUser)));
        final GrantedAuthority grantedAuthority =
                SecurityContextHolder.getContext().getAuthentication().getAuthorities().iterator().next();
        assertEquals("has authority admin", "admin", grantedAuthority.getAuthority());
        verify(userRepository);
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.core.GrantedAuthority

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.