Package org.wso2.carbon.user.core

Examples of org.wso2.carbon.user.core.AuthorizationManager


                    throw new AxisFault("System failed to authorize.",
                            ServerConstants.AUTHORIZATION_FAULT_CODE);
                }

                resourceId = resourceId.trim();
                AuthorizationManager authMan = realm.getAuthorizationManager();
                if (!isAuthorized(authMan, username, resourceId, action)) {
                    log.error("Access Denied. Failed authorization attempt to access service '"
                            + serviceName + "' operation '" + opName + "' by '" + username + "'");
                    AxisFault afault = new AxisFault("Access Denied.");
                    afault.setFaultCode(ServerConstants.AUTHORIZATION_FAULT_CODE);
View Full Code Here


        admin.addRole("role4", new String[] { "Lahiru" }, permisions);
    }

    public void doAuthorizationstuff() throws Exception{

        AuthorizationManager authMan = realm.getAuthorizationManager();

        //Role Authorization
        authMan.authorizeRole("role1", "/s", "read");
        assertTrue(authMan.isRoleAuthorized("role1", "/s", "read"));
        assertTrue(authMan.isRoleAuthorized("role1", "/s/t/u/v", "read"));
        assertTrue(authMan.isUserAuthorized("dimuthu","/s", "read"));
        assertTrue(authMan.isUserAuthorized("dimuthu","/s/t/u/v", "read"));

        authMan.denyRole("role1", "/s/t/u", "read");
        assertFalse(authMan.isRoleAuthorized("role1", "/s/t/u", "read"));
        assertFalse(authMan.isRoleAuthorized("role1", "s/t/u/v/w", "read"));
        assertFalse(authMan.isUserAuthorized("dimuthu","s/t/u/v/w", "read"));
        assertTrue(authMan.isRoleAuthorized("role1", "/s/t", "read"));
        assertTrue(authMan.isUserAuthorized("dimuthu","/s/t", "read"));

        authMan.authorizeRole("role1", "/s/t/u/v/w/x", "read");
        assertTrue(authMan.isRoleAuthorized("role1", "/s/t/u/v/w/x/y", "read"));
        assertTrue(authMan.isRoleAuthorized("role1", "/s/t", "read"));
        assertFalse(authMan.isRoleAuthorized("role1", "/s/t/u/v/w", "read"));

      
    }
View Full Code Here

        //wrong users - must pass because we don't know the external users.
        admin.updateUserListOfRole("role2", null, new String[] { "d" });
    }

    public void doAuthorizationStuff() throws Exception {
        AuthorizationManager authMan = realm.getAuthorizationManager();
        UserStoreManager usWriter = realm.getUserStoreManager();

        usWriter.addRole("rolex", new String[] { "saman", "amara" }, null);
        usWriter.addRole("roley", null, null);
        authMan.authorizeRole("rolex", "wall", "write");
        authMan.authorizeRole("roley", "table", "write");
        try {
          authMan.authorizeRole(null, "wall", "write");
          fail("Exception at authorizing a role with Null role");
        } catch (Exception e) {
          // caught exception
        }
        try {
          authMan.authorizeRole("rollee", null, "write");
          fail("Exception at authorizing a role with Null resourceID");
        } catch (Exception e) {
          // caught exception
        }
        try {
          authMan.authorizeRole("rollee","wall",null);
          fail("Exception at authorizing a role with Null action");
        } catch (Exception e) {
          // caught exception
        }
        try {
          authMan.authorizeRole("rolleex","wall","run");
          fail("Exception at authorizing a role with Invalid action");
        } catch (Exception e) {
          // caught exception
        }

        authMan.authorizeUser("sunil", "wall", "read");
        try {
          authMan.authorizeUser(null, "wall", "read");
          fail("Exception at authorizing a user with Null name");
        } catch (Exception e) {
          //caught exception
        }
        try {
          authMan.authorizeUser("isuru", null, "read");
          fail("Exception at authorizing a user with Null resourceID");
        } catch (Exception e) {
          //caught exception
        }
        try {
          authMan.authorizeUser("isuru","wall",null);
          fail("Exception at authorizing a user with Null action");
        } catch (Exception e) {
          //caught exception
        }
        try {
          authMan.authorizeUser("isuru","wall","run");
          fail("Exception at authorizing a user with Invalid action");
        } catch (Exception e) {
          //caught exception
        }

        assertTrue(authMan.isUserAuthorized("saman", "wall", "write"));
        assertTrue(authMan.isUserAuthorized("sunil", "wall", "read"));
        assertTrue(authMan.isRoleAuthorized("roley", "table", "write"));
        assertFalse(authMan.isRoleAuthorized("roley", "chair", "write"));
        assertFalse(authMan.isUserAuthorized("saman", "wall", "read"));
        assertFalse(authMan.isUserAuthorized("sunil", "wall", "write"));
        assertFalse(authMan.isUserAuthorized("isuru", "wall", "write"));
        try {
          boolean b=authMan.isUserAuthorized("isuru", "wall", "run");
          fail("Exception at check authorization of a user with Invalid action");
        } catch (Exception e) {
          //caught exception
        }

        authMan.clearUserAuthorization("sunil", "wall", "read");
        try{
            authMan.clearUserAuthorization("isuru", "wall", "run");
            fail("Exception at clear user authorization");
        }catch(Exception e){

        }
        try{
            authMan.clearUserAuthorization(null, "wall", "read");
            fail("Exception at clear user authorization");
        }catch(Exception e){

        }
        try{
            authMan.clearUserAuthorization("isuru", null, "read");
            fail("Exception at clear user authorization");
        }catch(Exception e){

        }
        try{
            authMan.clearUserAuthorization("isuru","wall", null);
            fail("Exception at clear user authorization");
        }catch(Exception e){

        }

        authMan.clearRoleAuthorization("roley", "table", "write");
        try{
            authMan.clearRoleAuthorization(null, "table", "write");
            fail("Exception at clear role authorization");
        }catch(Exception e){
            //caught exception
        }
        try{
            authMan.clearRoleAuthorization("roleee", null, "write");
            fail("Exception at clear role authorization");
        }catch(Exception e){
           //caught exception
        }
        try{
            authMan.clearRoleAuthorization("roleee", "table", null);
            fail("Exception at clear role authorization");
        }catch(Exception e){
           //caught exception
        }
        //authMan.isRoleAuthorized("roley", "table", "write");
       
        authMan.clearResourceAuthorizations("wall");
        try{
            authMan.clearResourceAuthorizations(null);
            fail("Exception at clear Resource Authorizations");
        }catch(Exception e){

        }

        assertFalse(authMan.isUserAuthorized("saman", "wall", "write"));
        assertFalse(authMan.isUserAuthorized("sunil", "wall", "read"));
        assertFalse(authMan.isRoleAuthorized("roley", "table", "write"));
    }
View Full Code Here

    public void checkPermission() throws Exception {
        UserStoreManager usManager = realm.getUserStoreManager();
        usManager.addRole("role1", null, null);
        usManager.addUser("user1", "pass1", new String[] { "role1" }, null, null, false);
       
        AuthorizationManager authManager = realm.getAuthorizationManager();
        authManager.authorizeUser("dish", "/r1/", "read");
        authManager.denyUser("dish", "/r1/r2", "read");
        assertFalse(authManager.isUserAuthorized("dish", "/x1/x2", "read"));

        authManager.authorizeRole("role1", "/x1", "read");
        authManager.denyRole("role1", "/x1/x2", "read");
        assertFalse(authManager.isRoleAuthorized("role1", "/x1/x2", "read"));

        assertTrue(authManager.isRoleAuthorized("role1", "/x1", "read"));
        usManager.updateRoleName("role1", "role2");
        assertTrue(authManager.isRoleAuthorized("role2", "/x1", "read"));
        assertFalse(authManager.isRoleAuthorized("role1", "/x1", "read"));

        assertFalse(authManager.isUserAuthorized("user1", "/x1/x2", "read"));
        assertTrue(authManager.isUserAuthorized("user1", "/x1", "read"));
       
        usManager.addRole("bizdevrole", null, null);
        usManager.addUser("bizuser", "pass2", new String[] { "bizdevrole", "everyone" }, null, null, false);
       
        authManager.authorizeRole("everyone", "/", "read");
        authManager.denyRole("everyone", "/wso2/bizzness", "read");
        authManager.authorizeRole("bizdevrole", "/wso2/bizzness", "read");
        assertTrue(authManager.isUserAuthorized("bizuser", "/wso2/bizzness", "read"));
    }
View Full Code Here

        authManager.authorizeRole("bizdevrole", "/wso2/bizzness", "read");
        assertTrue(authManager.isUserAuthorized("bizuser", "/wso2/bizzness", "read"));
    }
   
    public void checkRepeatingPermission() throws Exception {
        AuthorizationManager authManager = realm.getAuthorizationManager();
        UserStoreManager usAdmin = realm.getUserStoreManager();
        usAdmin.addRole("everyone", null, null);
        usAdmin.addUser("sameera", "password", new String[] { "everyone", "bizzrole" }, null, null, false);
        usAdmin.addUser("dimuthug", "password", new String[] { "everyone" }, null, null, false);

        authManager.authorizeRole("everyone", "/", "read");
        authManager.authorizeRole("everyone", "/top", "read");
        //authManager.authorizeRole("everyone", "/top/wso2", "read");
        authManager.denyRole("everyone", "/top/wso2/bizzness", "read");
        authManager.authorizeRole("bizzrole", "/top/wso2/bizzness", "read");

        assertEquals(1, authManager.getAllowedRolesForResource("/top/wso2/bizzness", "read").length);
        assertEquals(1, authManager.getDeniedRolesForResource("/top/wso2/bizzness", "read").length);
        assertFalse(authManager.isRoleAuthorized("everyone", "/top/wso2/bizzness", "read"));
        assertFalse(authManager.isUserAuthorized("dimuthu", "/top/wso2/bizzness", "read"));
    }
View Full Code Here

    private void copyUIPermissions(int tenantId) throws Exception {
        try {
            UserRealm realm = (UserRealm) TenantMgtCoreServiceComponent.
                    getRealmService().getTenantUserRealm(tenantId);
            String adminRole = realm.getRealmConfiguration().getAdminRoleName();
            AuthorizationManager authMan = realm.getAuthorizationManager();
            // Authorize the admin role, if not authorized yet.
            if (!authMan.isRoleAuthorized(adminRole,
                                          CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION,
                                          UserMgtConstants.EXECUTE_ACTION)) {
                authMan.authorizeRole(adminRole, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION,
                                      UserMgtConstants.EXECUTE_ACTION);
            }
        } catch (UserStoreException e) {
            String msg = "Error in authorizing the admin role.";
            log.error(msg, e);
View Full Code Here

        if (userRealm == null) {
            return;
        }

        try {
            AuthorizationManager accessControlAdmin = userRealm.getAuthorizationManager();
            String everyoneRole = CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME;

            accessControlAdmin.authorizeRole(everyoneRole, path, ActionConstants.GET);
            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.PUT);
            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.DELETE);
            accessControlAdmin.denyRole(everyoneRole, path, AccessControlConstants.AUTHORIZE);

        } catch (UserStoreException e) {
            String msg = "Could not set authorizations for the " + path + ".";
            log.error(msg, e);
            throw new RegistryException(msg);
View Full Code Here

        if (userRealm == null) {
            return;
        }

        try {
            AuthorizationManager accessControlAdmin = userRealm.getAuthorizationManager();
            RealmConfiguration realmConfig;
            try {
                realmConfig = userRealm.getRealmConfiguration();
            } catch (UserStoreException e) {
                String msg = "Failed to retrieve realm configuration.";
                log.error(msg, e);
                throw new RegistryException(msg, e);
            }

            String everyoneRole = realmConfig.getEveryOneRoleName();

            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.GET);
            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.PUT);
            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.DELETE);
            accessControlAdmin.denyRole(everyoneRole, path, AccessControlConstants.AUTHORIZE);

        } catch (UserStoreException e) {
            String msg = "Could not clear authorizations for the " + path + ".";
            log.error(msg, e);
            throw new RegistryException(msg);
View Full Code Here

        if (userRealm == null) {
            return;
        }

        try {
            AuthorizationManager accessControlAdmin = userRealm.getAuthorizationManager();
            String everyoneRole = CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME;

            accessControlAdmin.authorizeRole(everyoneRole, path, ActionConstants.GET);
            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.PUT);
            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.DELETE);
            accessControlAdmin.denyRole(everyoneRole, path, AccessControlConstants.AUTHORIZE);

        } catch (UserStoreException e) {
            String msg = "Could not set authorizations for the " + path + ".";
            log.error(msg, e);
            throw new RegistryException(msg);
View Full Code Here

        if (userRealm == null) {
            return;
        }

        try {
            AuthorizationManager accessControlAdmin = userRealm.getAuthorizationManager();
            RealmConfiguration realmConfig;
            try {
                realmConfig = userRealm.getRealmConfiguration();
            } catch (UserStoreException e) {
                String msg = "Failed to retrieve realm configuration.";
                log.error(msg, e);
                throw new RegistryException(msg, e);
            }

            String everyoneRole = realmConfig.getEveryOneRoleName();

            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.GET);
            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.PUT);
            accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.DELETE);
            accessControlAdmin.denyRole(everyoneRole, path, AccessControlConstants.AUTHORIZE);

        } catch (UserStoreException e) {
            String msg = "Could not clear authorizations for the " + path + ".";
            log.error(msg, e);
            throw new RegistryException(msg);
View Full Code Here

TOP

Related Classes of org.wso2.carbon.user.core.AuthorizationManager

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.