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


*/
public class AuthorityTest {

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

    }
View Full Code Here

         
            String role = iterator.next().getAuthority();
           
            final Iterator<GrantedAuthority> grantedIterator = granted.iterator();
            while ( grantedIterator.hasNext()) {
                GrantedAuthority authority = (GrantedAuthority) grantedIterator.next();

                if (authority.getAuthority().equals(role)) {
                    target.add(authority);
                    break;
                }
            }
        }
View Full Code Here

        if (obj instanceof String) {
                return obj.equals(this.getAuthority());
            }

            if (obj instanceof GrantedAuthority) {
                final GrantedAuthority attr = (GrantedAuthority) obj;
                return this.getAuthority().equals(attr.getAuthority());
            }

            return false;
      }
View Full Code Here

  @Override
  public Collection<? extends GrantedAuthority> getAuthorities() {
    ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    if (!CollectionUtils.isEmpty(getRoles())) {
      for (final String role : getRoles()) {
        authorities.add(new GrantedAuthority(){
          public String getAuthority() {
            return role;
          }
        });
      }
View Full Code Here

         
            String role = iterator.next().getAuthority();
           
            final Iterator<? extends GrantedAuthority> grantedIterator = granted.iterator();
            while ( grantedIterator.hasNext()) {
                GrantedAuthority authority = (GrantedAuthority) grantedIterator.next();

                if (authority.getAuthority().equals(role)) {
                    target.add(authority);
                    break;
                }
            }
        }
View Full Code Here

        if (obj instanceof String) {
                return obj.equals(this.getAuthority());
            }

            if (obj instanceof GrantedAuthority) {
                final GrantedAuthority attr = (GrantedAuthority) obj;
                return this.getAuthority().equals(attr.getAuthority());
            }

            return false;
      }
View Full Code Here

            throw new UserNotActivatedException("User " + lowercaseLogin + " was not activated");
        }

        Collection<GrantedAuthority> grantedAuthorities = new ArrayList<>();
        for (Authority authority : userFromDatabase.getAuthorities()) {
            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(authority.getName());
            grantedAuthorities.add(grantedAuthority);
        }

        return new org.springframework.security.core.userdetails.User(lowercaseLogin, userFromDatabase.getPassword(),
                grantedAuthorities);
View Full Code Here

    private SecurityRole getRole(Collection<? extends GrantedAuthority> authorities) {
        LOGGER.debug("Getting role from authorities: {}", authorities);

        Iterator<? extends GrantedAuthority> authority = authorities.iterator();
        GrantedAuthority a = authority.next();

        return SecurityRole.valueOf(a.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

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.