Package org.springframework.security.core.authority

Examples of org.springframework.security.core.authority.GrantedAuthorityImpl


    //校验结果
    assertEquals(user.getLoginName(), operator.getUsername());
    assertEquals(new ShaPasswordEncoder().encodePassword("admin", null), operator.getPassword());
    assertEquals(2, operator.getAuthorities().size());
    assertEquals(new GrantedAuthorityImpl("ROLE_admin"), operator.getAuthorities().iterator().next());
    assertNotNull(operator.getLoginTime());
  }
View Full Code Here


   * 获得用户所有角色的权限.
   */
  private Set<GrantedAuthority> obtainGrantedAuthorities(User user) {
    Set<GrantedAuthority> authSet = Sets.newHashSet();
    for (Role role : user.getRoleList()) {
      authSet.add(new GrantedAuthorityImpl("ROLE_" + role.getName()));
    }
    return authSet;
  }
View Full Code Here

    Account account = loadAccountByUserName("admin");
    if (account == null) {
      account = createNewAdminUser("admin", "", "admin");
    }
    GrantedAuthority[] auths = new GrantedAuthority[1];
    auths[0] = new GrantedAuthorityImpl("ROLE_ADMIN");
    ApplicationUser user = new ApplicationUser(new Long(account.getId()),
        account.getUserName(), account.getPassword(), true, true, true,
        true, auths);
    Authentication auth = new TestingAuthenticationToken(user, "ignored",
        auths);
View Full Code Here

        ex.printStackTrace();
      }
      
      int count = 0;
      for (Role r : account.getRoles()){
        auths[count++] = new GrantedAuthorityImpl(r.getRole());
      }


      //create application user
      ApplicationUser user = null;
View Full Code Here

  public void setCredentials() {
    Account account = getAccountService().loadAccountByUserName(BATCH_USER_NAME);

    GrantedAuthority[] auths = new GrantedAuthority[1];
    auths[0] = new GrantedAuthorityImpl("ROLE_USER");

    ApplicationUser user = new ApplicationUser(new Long(account.getId()), account.getUserName(), account.getPassword(), true, true, true, true,
        auths);

    Authentication auth = new TestingAuthenticationToken(user, "ignored", auths);
View Full Code Here

  @Before
  public void createAccount() {
    Account account = accountService.createNewBatchUser("test", "", "");
    GrantedAuthority[] auths = new GrantedAuthority[1];
    auths[0] = new GrantedAuthorityImpl("ROLE_USER");
    ApplicationUser user = new ApplicationUser(new Long(account.getId()),
        account.getUserName(), account.getPassword(), true, true, true,
        true, auths);
    Authentication auth = new TestingAuthenticationToken(user, "ignored",
        auths);
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

   */

  @Override
  public Collection<GrantedAuthority> getAuthorities() {
    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(2);
    authList.add(new GrantedAuthorityImpl("ROLE_USER"));
    if (admin) {
      authList.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
    }
    return authList;
  }
View Full Code Here

    {

      if ("admin".equals(username))
      {
        authorities = new GrantedAuthority[2];
        authorities[0] = new GrantedAuthorityImpl("ROLE_ADMIN");
        authorities[1] = new GrantedAuthorityImpl("ROLE_USER");
      }
      else
      {
        authorities = new GrantedAuthority[1];
        authorities[0] = new GrantedAuthorityImpl("ROLE_USER");
      }
      // the subject returned in AcegiLoginContext knows how to
      // convert these names to principals
    }
    return authorities;
View Full Code Here

    private Authentication createAuthenticationToken(String username, String password, String... roles) {
        Authentication authToken;
        if (roles != null && roles.length > 0) {
            List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(roles.length);
            for (String role : roles) {
                authorities.add(new GrantedAuthorityImpl(role));
            }
            authToken = new UsernamePasswordAuthenticationToken(username, password, authorities);
        } else {
            authToken = new UsernamePasswordAuthenticationToken(username, password);
        }
View Full Code Here

TOP

Related Classes of org.springframework.security.core.authority.GrantedAuthorityImpl

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.