Package org.springframework.security

Examples of org.springframework.security.GrantedAuthorityImpl


        TestingAuthenticationToken auth = new TestingAuthenticationToken(
                username,
                username,
                new GrantedAuthority[] {
                        new GrantedAuthorityImpl("ROLE_TELLER"),
                        new GrantedAuthorityImpl("ROLE_PERMISSION_LIST") });

        SecurityContext secureContext = new SecurityContextImpl();
        secureContext.setAuthentication(auth);
        SecurityContextHolder.setContext(secureContext);
View Full Code Here


        TestingAuthenticationToken auth = new TestingAuthenticationToken(
                username,
                username,
                new GrantedAuthority[] {
                        new GrantedAuthorityImpl("ROLE_TELLER"),
                        new GrantedAuthorityImpl("ROLE_PERMISSION_LIST") });

        SecurityContext secureContext = new SecurityContextImpl();
        secureContext.setAuthentication(auth);
        SecurityContextHolder.setContext(secureContext);
View Full Code Here

      this.account = account;
      List<String> roles = account.getRoleList();

      grantedAuthorities = new GrantedAuthority[roles.size()];
      for (int i = 0; i < roles.size(); i++) {
        grantedAuthorities[i] = new GrantedAuthorityImpl(roles.get(i));
      }
    }
  }
View Full Code Here

    rule.setAttributes(attributes);
    return rule;
  }

  private Authentication getAuthentication() {
    GrantedAuthority[] authorities = { new GrantedAuthorityImpl("ROLE_1"), new GrantedAuthorityImpl("ROLE_2"),
        new GrantedAuthorityImpl("ROLE_3") };
    return new UsernamePasswordAuthenticationToken("test", "", authorities);
  }
View Full Code Here

            // Remove the role's whitespace characters without depending on JDK 1.4+
            // Includes space, tab, new line, carriage return and form feed.
            String role = authority.trim(); // trim, don't use spaces, as per SEC-378
            role = StringUtils.deleteAny(role, "\t\n\r\f");

            requiredAuthorities.add(new GrantedAuthorityImpl(role));
        }

        return requiredAuthorities;
    }
View Full Code Here

    private Authentication createAuthenticationToken(String username, String password, String... roles) {
        Authentication authToken;
        if (roles != null && roles.length > 0) {
            GrantedAuthority[] authorities = new GrantedAuthority[roles.length];
            for (int i = 0; i < roles.length; i++) {
                authorities[i] = new GrantedAuthorityImpl(roles[i]);
            }
            authToken = new UsernamePasswordAuthenticationToken(username, password, authorities);
        } else {
            authToken = new UsernamePasswordAuthenticationToken(username, password);
        }
View Full Code Here

    /**
     * Construct a token with the given id, password, and role
     */
    public static Authentication makeAuthentication( String user, String password, String role ) {
        return new TestingAuthenticationToken( user, password,
            new GrantedAuthority[] { new GrantedAuthorityImpl( role ) } );
    }
View Full Code Here

        controller.addControlledObject( a1 );
        assertFalse( "Object should not be authorized", a1.isAuthorized() );

        // Now set the authentication token so that it contains one of these roles
        Authentication auth = new TestingAuthenticationToken( "USER1", "FOO",
            new GrantedAuthority[] { new GrantedAuthorityImpl( "ROLE_1" ) } );
        controller.setAuthenticationToken( auth );

        assertTrue( "Object should be authorized", a1.isAuthorized() );
        assertEquals( "Object should be updated", a1.getAuthCount(), 2 );

        // Now to a token that does not contain one of the roles
        auth = new TestingAuthenticationToken( "USER1", "FOO", new GrantedAuthority[] { new GrantedAuthorityImpl(
            "ROLE_NOTFOUND" ) } );
        controller.setAuthenticationToken( auth );

        assertFalse( "Object should not be authorized", a1.isAuthorized() );
        assertEquals( "Object should be updated", a1.getAuthCount(), 3 );
View Full Code Here

    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
        User account = userService.getAccountByNickname(username);
        Account user = userService.getEmployeeByNickName(username);
        List<GrantedAuthority> grantedAuthority = new ArrayList<GrantedAuthority>();
        for (UserRoles role : user.getAssociatedRoles()) {
            grantedAuthority.add(new GrantedAuthorityImpl(role.toString()));
        }

        account.setGrantedAuthoritys((GrantedAuthority[]) grantedAuthority.toArray(new GrantedAuthority[grantedAuthority.size()]));
        return account;
    }
View Full Code Here

    private GrantedAuthority[] makeGrantedAuthorities(AppUser user) {
        GrantedAuthority[] result = new GrantedAuthority[user.getRoles().size()];
        int i = 0;
        for (String role : user.getRoles()) {
            result[i++] = new GrantedAuthorityImpl(role);
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.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.