Package org.springframework.security.core

Examples of org.springframework.security.core.GrantedAuthority


        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


        this.secret = secret;
        this.dn = dn;

        //TODO need to use this business
        final ArrayList<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
        list.add(new GrantedAuthority() {
            public String getAuthority() {
                return "ROLE_USER";
            }
        });
        this.authorities = Collections.unmodifiableList(list);
View Full Code Here

        assertTrue(authToken.isAuthenticated());
        Collection<? extends GrantedAuthority> authorities = userDetails.getAuthorities();
        Iterator<? extends GrantedAuthority> it = authorities.iterator();
        int matchCount = 0;
        while (it.hasNext()) {
            GrantedAuthority authority = it.next();
            if (authority.getAuthority().equals("ROLE_USER") || authority.getAuthority().equals("ROLE_ADMIN")) {
                matchCount++;
            }
        }
        assertEquals(2, matchCount);
    }
View Full Code Here

    @Test
    public void testUserDefaultAuthority() {
        JCUser user =  new JCUser("username", "email@mail.com", "pass");

        GrantedAuthority expectedAuthority = new GrantedAuthorityImpl("ROLE_USER");
        assertTrue(user.getAuthorities().contains(expectedAuthority));
    }
View Full Code Here

    @Autowired(required = true)
    private UserService userService;

    @Before
    public void setup() {
        GrantedAuthority grantedAuthority = new GrantedAuthority() {
            @Override
            public String getAuthority() {
                return UserRole.ROLE_ADMIN.toString();
            }
        };
View Full Code Here

    }

    private void setAdminRole(User user) {
        Role role = roleService.getRoleByAuthority(UserRole.ROLE_ADMIN.toString());
        user.getRoles().add(role);
        GrantedAuthority grantedAuthority = new GrantedAuthority() {
            @Override
            public String getAuthority() {
                return UserRole.ROLE_ADMIN.toString();
            }
        };
View Full Code Here

    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        github.priyatam.springrest.domain.User user = persistenceHelper.findByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException("user not found");
        }
        GrantedAuthority authority = new SimpleGrantedAuthority(user.getRole());
        return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), Collections.singleton(authority));
    }
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

        UsernamePasswordAuthenticationToken targetUserRequest;

        // grant an additional authority that contains the original Authentication object
        // which will be used to 'exit' from the current switched user.
        Authentication currentAuth = SecurityContextHolder.getContext().getAuthentication();
        GrantedAuthority switchAuthority = new SwitchUserGrantedAuthority(ROLE_PREVIOUS_ADMINISTRATOR, currentAuth);

        // get the original authorities
        Collection<GrantedAuthority> orig = targetUser.getAuthorities();

        // Allow subclasses to change the authorities to be granted
View Full Code Here

  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user = userRepository.findByUsername(username);
    if(user == null) {
      throw new UsernameNotFoundException("user not found");
    }
    GrantedAuthority authority = new SimpleGrantedAuthority(user.getRole());
    return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), Collections.singleton(authority));
  }
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.