Examples of GrantedAuthorityImpl


Examples of org.springframework.security.GrantedAuthorityImpl

        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

Examples of org.springframework.security.GrantedAuthorityImpl

    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

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

          @Override
          public Collection<? extends GrantedAuthority> getAuthorities() {
            // this is to test differences between implementations of GrantedAuthority,
            // see the containsAll method in ifRole
            Collection<GrantedAuthorityImpl> auth = new ArrayList<GrantedAuthorityImpl>();
            auth.add(new GrantedAuthorityImpl("GROUP1"));
            return  auth;
          }
        };
      }
    });
View Full Code Here

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

    public void testAuthorizeExtendsGrantedAuthorityImpl() throws JspException {
        authorizeTag.setIfAnyGranted(null);
        authorizeTag.setIfNotGranted(null);
        authorizeTag.setIfAllGranted("ROLE_TEST");
        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        authorities.add(new GrantedAuthorityImpl("ROLE_TEST") {});
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", authorities));
        assertEquals("Expected to be authorized", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
    }
View Full Code Here

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

    public void testAuthorizeUsingGrantedAuthorityImpl() throws JspException {
        authorizeTag.setIfAnyGranted(null);
        authorizeTag.setIfNotGranted(null);
        authorizeTag.setIfAllGranted("ROLE_TEST");
        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        authorities.add(new GrantedAuthorityImpl("ROLE_TEST"));
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", authorities));
        assertEquals("Expected to be authorized", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
    }
View Full Code Here

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

    public void testNotAuthorizeUsingGrantedAuthorityImpl() throws JspException {
        authorizeTag.setIfAnyGranted(null);
        authorizeTag.setIfNotGranted(null);
        authorizeTag.setIfAllGranted("ROLE_ADMIN");
        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        authorities.add(new GrantedAuthorityImpl("ROLE_TEST"));
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", authorities));
        assertEquals("Expected to not be authorized", Tag.SKIP_BODY, authorizeTag.doStartTag());
    }
View Full Code Here

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

    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 (int i = 0; i < roles.length; i++) {
                authorities.add(new GrantedAuthorityImpl(roles[i]));
            }
            authToken = new UsernamePasswordAuthenticationToken(username, password, authorities);
        } else {
            authToken = new UsernamePasswordAuthenticationToken(username, password);
        }
View Full Code Here

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

        cz.muni.fi.pa165.library.backend.User user = userDAO.findUserByEmail(email);
        List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(2);
        String pass;
        if (user != null){
            pass = user.getPassword();
            authList.add(new GrantedAuthorityImpl("ROLE_LIBRARIAN"));
            authList.add(new GrantedAuthorityImpl("ROLE_READER"));
        }else{
            Reader reader = readerDAO.findReaderByEmail(email);
            if (reader == null){throw new UsernameNotFoundException("Username Not Found");}
            pass = reader.getPassword();
            authList.add(new GrantedAuthorityImpl("ROLE_READER"));   
        }
         return new User(email, pass, true, true, true, true, authList);


       
View Full Code Here

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

 
    protected List<GrantedAuthority> loadUserAuthorities(String username) {
      List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
     
     
      GrantedAuthority authority = new GrantedAuthorityImpl("ROLE_USER");
     
      authorities.add(authority);
     
      return authorities;
//        return getJdbcTemplate().query(authoritiesByUsernameQuery, new String[] {username}, new RowMapper<GrantedAuthority>() {
View Full Code Here

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

        final Collection<GrantedAuthority> requiredAuthorities = new ArrayList<GrantedAuthority>();
        final String[] roles = authorizationsString.split(",");

        for (int i = 0; i < roles.length; i++) {
            String role = roles[i].trim();
            requiredAuthorities.add(new GrantedAuthorityImpl(role));
        }

        return requiredAuthorities;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.