Package org.apache.shiro.subject

Examples of org.apache.shiro.subject.PrincipalCollection


   
    @Test
    public void testRealmWithRolePermissionResolver()
    {  
        Principal principal = new UsernamePrincipal("rolePermResolver");
        PrincipalCollection pCollection = new SimplePrincipalCollection(principal, "testRealmWithRolePermissionResolver");
       
        AuthorizingRealm realm = new AllowAllRealm();
        realm.setRolePermissionResolver( new RolePermissionResolver()
        {
            public Collection<Permission> resolvePermissionsInRole( String roleString )
View Full Code Here


            put(PRINCIPALS, principals);
        }
    }

    public PrincipalCollection resolvePrincipals() {
        PrincipalCollection principals = getPrincipals();

        if (CollectionUtils.isEmpty(principals)) {
            //check to see if they were just authenticated:
            AuthenticationInfo info = getAuthenticationInfo();
            if (info != null) {
View Full Code Here

    @SuppressWarnings("serial")
    @Test
    public void testMergeWithImmutablePrincipalCollection() {
        SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
        // Make a quick test fixture that does *not* implement MutablePrincipalCollection
        PrincipalCollection principalCollection = new PrincipalCollection() {
      @SuppressWarnings("unchecked")
      public List asList() { return null;}
      @SuppressWarnings("unchecked")
      public Set asSet() {return null;}
      public <T> Collection<T> byType(Class<T> type) {return null;}
View Full Code Here

    @Test
    public void testHasRole() throws InterruptedException {
        setUpForReadConfigurationTest();
        executeTest(new Runnable() {
            public void run() {
                PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1");
                assertTrue("principal doesn't have role when it should",
                        realm.hasRole(principalCollection, "role2"));
                assertTrue("principal doesn't have all roles when it should",
                        realm.hasAllRoles(principalCollection, Arrays.asList(new String[]{"role1", "role2"})));
            }
View Full Code Here

    @Test
    public void testCheckRole() throws InterruptedException {
        setUpForReadConfigurationTest();
        executeTest(new Runnable() {
            public void run() {
                PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1");
                try {
                    realm.checkRoles(principalCollection, new String[]{"role1", "role2"});
                } catch (AuthorizationException ae) {
                    fail("principal doesn't have all roles when it should");
                }
View Full Code Here

    @Test
    public void testCheckPermission() throws InterruptedException {
        setUpForReadConfigurationTest();
        executeTest(new Runnable() {
            public void run() {
                PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1");
                try {
                    realm.checkPermission(principalCollection, "role1_permission1");
                    realm.checkPermissions(principalCollection, new String[]{"role1_permission1", "role2_permission2"});
                } catch (AuthorizationException ae) {
                    fail("principal doesn't have permission when it should");
View Full Code Here

    @Test
    public void testIsPermitted() throws InterruptedException {
        setUpForReadConfigurationTest();
        executeTest(new Runnable() {
            public void run() {
                PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1");
                assertTrue("permission not permitted when it should be", realm.isPermitted(principalCollection, "role1_permission1"));
                assertTrue("permission not permitted when it should be",
                        realm.isPermittedAll(principalCollection, new String[]{"role1_permission1", "role2_permission2"}));
            }
        });
View Full Code Here

                return null;
            }
        };

        Principal principal = new UsernamePrincipal("blah");
        PrincipalCollection pCollection = new SimplePrincipalCollection(principal, "nullAuthzRealm");
        List<Permission> permList = new ArrayList<Permission>();
        permList.add(new WildcardPermission("stringPerm1"));
        permList.add(new WildcardPermission("stringPerm2"));
        List<String> roleList = new ArrayList<String>();
        roleList.add("role1");
View Full Code Here

   
    @Test
    public void testRealmWithRolePermissionResolver()
    {  
        Principal principal = new UsernamePrincipal("rolePermResolver");
        PrincipalCollection pCollection = new SimplePrincipalCollection(principal, "testRealmWithRolePermissionResolver");
       
        AuthorizingRealm realm = new AllowAllRealm();
        realm.setRolePermissionResolver( new RolePermissionResolver()
        {
            public Collection<Permission> resolvePermissionsInRole( String roleString )
View Full Code Here

    public void login(AuthenticationToken token) throws AuthenticationException {
        clearRunAsIdentities();
        Subject subject = securityManager.login(this, token);

        PrincipalCollection principals;

        String host = null;

        if (subject instanceof DelegatingSubject) {
            DelegatingSubject delegating = (DelegatingSubject) subject;
            //we have to do this in case there are assumed identities - we don't want to lose the 'real' principals:
            principals = delegating.principals;
            host = delegating.host;
        } else {
            principals = subject.getPrincipals();
        }

        if (principals == null || principals.isEmpty()) {
            String msg = "Principals returned from securityManager.login( token ) returned a null or " +
                    "empty value.  This value must be non null and populated with one or more elements.";
            throw new IllegalStateException(msg);
        }
        this.principals = principals;
View Full Code Here

TOP

Related Classes of org.apache.shiro.subject.PrincipalCollection

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.