Package org.wso2.carbon.user.core

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


    }

    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");
        authMan.authorizeUser("sunil", "wall", "read");

        assertTrue(authMan.isUserAuthorized("saman", "wall", "write"));
View Full Code Here


        assertFalse(authMan.isUserAuthorized("sunil", "wall", "read"));
        assertFalse(authMan.isRoleAuthorized("roley", "table", "write"));
    }

    public void doClaimStuff() throws Exception {
        UserStoreManager usWriter = realm.getUserStoreManager();
        String[] allClaims = { ClaimTestUtil.CLAIM_URI1, ClaimTestUtil.CLAIM_URI2,
                ClaimTestUtil.CLAIM_URI3 };

        // add default
        usWriter.setUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, "claim1default", null);
        String value = usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, null);
        assertEquals("claim1default", value);

        // update default
        usWriter.setUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, "dimzi lee", null);
        value = usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, null);
        assertEquals("dimzi lee", value);

        // multiple additions
        Map<String, String> map = new HashMap<String, String>();
        map.put(ClaimTestUtil.CLAIM_URI1, "lee");
        map.put(ClaimTestUtil.CLAIM_URI3, "muthu");

        usWriter.setUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI2, "claim2default", null);
        usWriter.setUserClaimValues("dimuthu", map, ClaimTestUtil.HOME_PROFILE_NAME);
        usWriter.setUserClaimValue("dimuthu", UserCoreConstants.PROFILE_CONFIGURATION,
                ClaimTestUtil.HOME_PROFILE_NAME, ClaimTestUtil.HOME_PROFILE_NAME);

        Map<String, String> obtained = usWriter.getUserClaimValues("dimuthu", allClaims,
                ClaimTestUtil.HOME_PROFILE_NAME);

        assertNull(obtained.get(ClaimTestUtil.CLAIM_URI1)); // hidden
        assertEquals("claim2default", obtained.get(ClaimTestUtil.CLAIM_URI2)); // overridden
        assertEquals("muthu", obtained.get(ClaimTestUtil.CLAIM_URI3)); // normal

        // update
        map.put(ClaimTestUtil.CLAIM_URI3, "muthulee");
        usWriter.setUserClaimValues("dimuthu", map, ClaimTestUtil.HOME_PROFILE_NAME);
        value = usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI3,
                ClaimTestUtil.HOME_PROFILE_NAME);
        assertEquals("muthulee", value);

        // delete
        usWriter.deleteUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, null);
        value = usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, null);
        assertNull(value);

        usWriter.deleteUserClaimValues("dimuthu", allClaims, ClaimTestUtil.HOME_PROFILE_NAME);
        obtained = usWriter.getUserClaimValues("dimuthu", allClaims,
                ClaimTestUtil.HOME_PROFILE_NAME);
        assertNull(obtained.get(ClaimTestUtil.CLAIM_URI2)); // overridden

    }
View Full Code Here

                .getProfileTestData(),0);
    }

    public void doUserStuff() throws Exception {

        UserStoreManager admin = realm.getUserStoreManager();

        Map<String, String> userProps = new HashMap<String, String>();
        userProps.put(ClaimTestUtil.CLAIM_URI1, "1claim1Value");
        userProps.put(ClaimTestUtil.CLAIM_URI2, "2claim2Value");

        Permission[] permisions = new Permission[2];
        permisions[0] = new Permission("high security", "read");
        permisions[1] = new Permission("low security", "write");


        //add USER
        admin.addUser("dimuthu", "credential", null, null, null, false);
        try{
          admin.addUser(null, null, null, null, null, false);
          TestCase.assertTrue(false);
        }catch(Exception ex){
          //expected error
        }
        try{
          admin.addUser("dimuthu", null, null, null, null, false);
          TestCase.assertTrue(false);
        }catch(Exception ex){
          //expected error
        }
        try{
          admin.addUser(null, "credential", null, null, null, false);
          TestCase.assertTrue(false);
        }catch(Exception ex){
          //expected error
        }
        try{
          admin.addUser(" ", "credential", null, null, null, false);
          TestCase.assertTrue(false);
        }catch(Exception ex){
          //expected error
        }
        try{
          admin.addUser("dimuthu", "credential", null, null, null, false);
          fail("Exception at adding the same user again");
        }catch(Exception ex){
          //expected error
        }


        // add ROLE
        admin.addRole("role1", new String[] { "dimuthu" }, permisions);//dimuthu added to the role
        try{
          admin.addRole(null, null, null);
          fail("Exception at defining a roll with No information");
        }catch(Exception ex){
          //expected error
        }
        try{
          admin.addRole(null, new String[] { "dimuthu" }, permisions);
            fail("Exception at adding user to a non specified role");
        }catch(Exception ex){
          //expected error
        }
        try{
          admin.addRole("role1", new String[] { "isuru" }, permisions);
          fail("Exception at adding a non existing user to the role");
        }catch(Exception ex){                                     
          //expected error
        }


        //add USER to a ROLE
        admin.addUser("vajira", "credential", new String[] { "role1" }, userProps, null, false);
        try{
          admin.addUser("Bence", "credential", new String[] { "rolexxx" }, userProps, null, false);
          fail("Exception at adding user to a Non-existing role");
        }catch(Exception ex){
          //expected user
        }
        try{
          admin.addUser(null, "credential", new String[] { "role1" }, userProps, null, false);
          fail("Exception at adding user to a role with no user name");
        }catch(Exception ex){
          //expected user
        }
        try{
          admin.addUser("vajira", "credential", new String[] { "role1" }, userProps, null, false);
          fail("Exception at adding same user to the same roll");
        }catch(Exception ex){
          //expected user
        }

       
        //Authenticate USER
        assertTrue(admin.authenticate("dimuthu", "credential"));
        assertFalse(admin.authenticate(null, "credential"));
        assertFalse(admin.authenticate("dimuthu",null));
        try{
          admin.authenticate("dimuthu", 123);
          fail("Exception at when Object credential is not an instance of String");
        }catch(Exception ex){
          //expected user
        }

        //update by ADMIN
        admin.updateCredentialByAdmin("dimuthu", "topsecret");
        assertTrue(admin.authenticate("dimuthu", "topsecret"));

        //isExistingUser
        assertTrue(admin.isExistingUser("dimuthu"));
        assertFalse(admin.isExistingUser("muhaha"));

       
        // update by USER
        admin.updateCredential("dimuthu", "password", "topsecret");
        //assertTrue(admin.authenticate("dimuthu", "password")); //TO DO
        assertFalse(admin.authenticate("dimuthu", "credential"));
        try{
          admin.updateCredential("dimuthu", "password", "xxx");
          TestCase.assertTrue(false);
        }catch(Exception ex){
          //expected exception
        }
       
        String[] names = admin.listUsers("*", 100);
        assertEquals(3, names.length);
       
        String[] names1 = admin.listUsers("*", 0);
        assertEquals(0, names1.length);
       
        String[] names2 = admin.listUsers("*", 2);
        assertEquals(2, names2.length);
       
        String[] names3 = admin.listUsers("di?uthu", 100);
        assertEquals(1, names3.length);

        String[] names4 = admin.listUsers("is?ru", 100);
        assertEquals(0, names4.length);
      
        String[] roleNames = admin.getRoleNames();
        assertEquals(4, roleNames.length);


        // delete
        admin.deleteUser("vajira");
        assertFalse(admin.isExistingUser("vajira"));
        assertFalse(admin.authenticate("vajira", "credential"));


        //delete ROLE
        admin.addUser("vajira", "credential", new String[] { "role1" }, userProps, null, false);
        assertTrue(admin.isExistingUser("vajira"));
        admin.deleteRole("role1");

       
        //add role
        admin.addRole("role1", new String[] { "dimuthu" }, permisions);
       
    }
View Full Code Here

        realm.init(realmConfig, ClaimTestUtil.getClaimTestData(), ClaimTestUtil
                .getProfileTestData(),0);
    }

    public void dorolestuff() throws Exception{
        UserStoreManager admin = realm.getUserStoreManager();
        Map<String, String> getClaims = new HashMap<String, String>();
        getClaims.put(ClaimTestUtil.CLAIM_URI1, "1claim1Value");
        getClaims.put(ClaimTestUtil.CLAIM_URI2, "2claim2Value");

        Permission[] permisions = new Permission[2];
        permisions[0] = new Permission("high security", "read");
        permisions[1] = new Permission("low security", "write");
        assertEquals("high security",permisions[0].getResourceId());
        assertEquals("write",permisions[1].getAction());

        admin.addUser("dimuthu", "pass1", null, null, null, false);
        admin.addUser("isuru","pass2",null,null,null, false);
        admin.addUser("ajith","pass3",null,null,null, false);
        admin.addUser("Kalpa","pass4",null,null,null, false);
        admin.addUser("Lahiru","pass5",null,null,null, false);

        admin.addRole("role1", new String[] { "dimuthu" }, permisions);
        admin.addRole("role2", new String[] { "isuru","ajith" }, permisions);
        admin.addRole("role3", new String[] { "Kalpa" }, permisions);
        admin.addRole("role4", new String[] { "Lahiru" }, permisions);
    }
View Full Code Here

        admin.addRole("role1", new String[] { "dimuthu" }, permisions);
       
    }
   
    public void doUserRoleStuff() throws Exception {
           UserStoreManager admin = realm.getUserStoreManager();

           InputStream inStream = this.getClass().getClassLoader().getResource(JDBCRealmTest.
                                  JDBC_TEST_USERMGT_XML).openStream();
           RealmConfigXMLProcessor realmConfigProcessor = new RealmConfigXMLProcessor();
           RealmConfiguration realmConfig = realmConfigProcessor.buildRealmConfiguration(inStream);

           admin.addRole("role2", null, null);
           admin.addRole("role3", null, null);
           admin.addRole("role4", null, null);
           assertEquals(7, admin.getRoleNames().length);//admin,everyone,role1,role2,role3,role4

           //Test delete role method
           assertTrue(admin.isExistingRole("role3"));
           admin.deleteRole("role3");
           admin.deleteRole("role4");
           assertFalse(admin.isExistingRole("role3"));
           admin.addRole("role3", null, null);
           admin.addRole("role4", null, null);


           //add users
           admin.addUser("saman", "pass1", null, null, null, false);
           admin.addUser("amara", "pass2", null, null, null, false);
           admin.addUser("sunil", "pass3", null, null, null, false);

           //update the ROLE list of USERS
           admin.updateRoleListOfUser("saman", null, new String[] { "role2" });
           admin.updateRoleListOfUser("saman", new String[] { "role2" }, new String[] { "role4",
                   "role3" });
            try{
               admin.updateRoleListOfUser(null, null, new String[] { "role2" });
               fail("Exceptions at missing user name");
            }catch(Exception ex){
                    //expected user
            }

           // Renaming Role
           admin.updateRoleName("role4", "role5");
          

           String[] rolesOfSaman = admin.getRoleListOfUser("saman");
           assertEquals(3, rolesOfSaman.length);
          
           String[] rolesOfisuru = admin.getRoleListOfUser("isuru");
           assertEquals(0, rolesOfisuru.length);
         
           admin.updateUserListOfRole("role2", new String[] { "saman" }, null);
           admin.updateUserListOfRole("role3", null, new String[] { "amara", "sunil" });

           String[] userOfRole5 = admin.getUserListOfRole("role5");
           assertEquals(1, userOfRole5.length);

           String[] userOfRole4 = admin.getUserListOfRole("role4");
           assertEquals(0, userOfRole4.length);

           try {
            admin.updateUserListOfRole("rolexx", null, new String[] { "amara", "sunil" });
            TestCase.assertTrue(false);
           } catch (Exception e) {
            // exptected error in negative testing
           }
           try {
             admin.updateUserListOfRole("role2", null, new String[] { "d" });
             TestCase.assertTrue(false);
           } catch (Exception e) {
            // exptected error in negative testing
           }

           try {
               admin.updateRoleListOfUser("saman", new String[] { "x" }, new String[] { "y" });
               TestCase.assertTrue(false);
           } catch (Exception e) {
               // exptected error in negative testing
           }

           try {
               admin.updateUserListOfRole (realmConfig.getAdminRoleName(),null,
                                           new String[] {realmConfig.getAdminUserName()});
               TestCase.assertTrue(false);
           } catch (Exception e) {
               // exptected error in negative testing
           }

           try {
               admin.updateRoleListOfUser(realmConfig.getAdminUserName(),new String[]{realmConfig.
                                          getAdminRoleName()},null);
               TestCase.assertTrue(false);
           } catch (Exception e) {
               // exptected error in negative testing
           }

           try {
               admin.updateUserListOfRole(realmConfig.getEveryOneRoleName(),new String[] {"saman"},
                                          null);
               TestCase.assertTrue(false);
           } catch (Exception e) {
               // exptected error in negative testing
           }

           try {
               admin.updateRoleListOfUser("sunil",new String[]{realmConfig.getEveryOneRoleName()},
                                          null);
               TestCase.assertTrue(false);
           } catch (Exception e) {
               // exptected error in negative testing
           }

           try {
               admin.updateRoleName("role2", "role5");
               TestCase.assertTrue(false);
           } catch (Exception e) {
               // exptected error in negative testing
           }
View Full Code Here

       }

    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");
View Full Code Here

        assertFalse(authMan.isUserAuthorized("sunil", "wall", "read"));
        assertFalse(authMan.isRoleAuthorized("roley", "table", "write"));
    }

public void doClaimStuff() throws Exception {
        UserStoreManager usWriter = realm.getUserStoreManager();
        String[] allClaims = { ClaimTestUtil.CLAIM_URI1, ClaimTestUtil.CLAIM_URI2,
                ClaimTestUtil.CLAIM_URI3 };

        // add DEFAULT
        usWriter.setUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, "claim1default", null);
        try{
            usWriter.setUserClaimValue(null, ClaimTestUtil.CLAIM_URI1, "claim1default", null);
            fail("Exception at set claim values to null users");
        }catch(Exception e){
            //expected exception
        }
        try{
            usWriter.setUserClaimValue("isuru", null, "claim1default", null);
            fail("Exception at set claim values to null claimURI");
        }catch(Exception e){
            //expected exception
        }
        try{
            usWriter.setUserClaimValue("isuru", ClaimTestUtil.CLAIM_URI1, null, null);
            fail("Exception at set claim values to null claimValue");
        }catch(Exception e){
            //expected exception
        }

        String value = usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, null);
        assertEquals("claim1default",value);
        //Non existing user
        String value1 = usWriter.getUserClaimValue("isuru", ClaimTestUtil.CLAIM_URI1, null);
        assertEquals(null, value1);
        // update default
        usWriter.setUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, "dimzi lee", null);
        value = usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, null);
        assertEquals("dimzi lee", value);

        // multiple additions
        Map<String, String> map = new HashMap<String, String>();
        map.put(ClaimTestUtil.CLAIM_URI1, "lee");
        map.put(ClaimTestUtil.CLAIM_URI3, "muthu");

        usWriter.setUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI2, "claim2default", null);
        assertEquals("dimzi lee",usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1,null));
        assertEquals("claim2default",usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI2,null));
        assertNull(usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI3,null));

        usWriter.setUserClaimValues("dimuthu", map, ClaimTestUtil.HOME_PROFILE_NAME);
        assertEquals("lee",usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1,ClaimTestUtil.HOME_PROFILE_NAME));
        assertNull(usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI2,ClaimTestUtil.HOME_PROFILE_NAME));
        assertEquals("muthu",usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI3,ClaimTestUtil.HOME_PROFILE_NAME));

        usWriter.setUserClaimValue("dimuthu", UserCoreConstants.PROFILE_CONFIGURATION,
                ClaimTestUtil.HOME_PROFILE_NAME, ClaimTestUtil.HOME_PROFILE_NAME);
        Map<String, String> obtained = usWriter.getUserClaimValues("dimuthu", allClaims,
                ClaimTestUtil.HOME_PROFILE_NAME);
        assertNull(obtained.get(ClaimTestUtil.CLAIM_URI1)); // hidden
        assertEquals("claim2default", obtained.get(ClaimTestUtil.CLAIM_URI2)); // overridden
        assertEquals("muthu", obtained.get(ClaimTestUtil.CLAIM_URI3)); // normal

        //UPDATE
        map.put(ClaimTestUtil.CLAIM_URI3, "muthulee");
        usWriter.setUserClaimValues("dimuthu", map, ClaimTestUtil.HOME_PROFILE_NAME);
        value = usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI3,
                ClaimTestUtil.HOME_PROFILE_NAME);
        assertEquals("muthulee", value);

        //DELETE
        usWriter.deleteUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, null);
        value = usWriter.getUserClaimValue("dimuthu", ClaimTestUtil.CLAIM_URI1, null);
        assertNull(value);
        try{
             usWriter.deleteUserClaimValue("dimuthu", null, null);
             fail("Exception at null Claim URI");
        }catch(Exception e){
            //expected exception
        }
        try{
            usWriter.deleteUserClaimValue(null,ClaimTestUtil.CLAIM_URI1, null);
            fail("Exception at giving null user name to delete user claim values");
        }catch(Exception e){
            //expected exception
        }

        usWriter.deleteUserClaimValues("dimuthu", allClaims, ClaimTestUtil.HOME_PROFILE_NAME);
        obtained = usWriter.getUserClaimValues("dimuthu", allClaims,
                ClaimTestUtil.HOME_PROFILE_NAME);
        assertNull(obtained.get(ClaimTestUtil.CLAIM_URI2)); // overridden
        assertNull(obtained.get(ClaimTestUtil.CLAIM_URI3));

         //UserStoreManager admin = realm.getUserStoreManager();
View Full Code Here

                .getProfileTestData(), 0);
        assertTrue(realm.getUserStoreManager().isExistingRole("adminx"));
    }
   
    public void doRoleStuff() throws Exception {
        UserStoreManager admin = realm.getUserStoreManager();

        admin.addRole("role2", null, null);
        admin.addRole("role3", null, null);
        admin.addRole("role4", null, null);
        try{
           admin.addRole(null, null, null);
           fail("Exception at Null role name");
        }catch(Exception e){
            //caught Exception
        }

        admin.updateRoleListOfUser("saman", null, new String[] { "role2" });
        admin.updateRoleListOfUser("saman", new String[] { "role2" }, new String[] { "role4",
                "role3" });
        try{
           admin.updateRoleListOfUser(null, null, new String[] { "role2" });
           fail("Exceptions at missing user name");
        }catch(Exception ex){
           //expected user
        }

        assertEquals(3, admin.getRoleListOfUser("saman").length);

        // negative
        admin.updateUserListOfRole("role2", new String[] { "saman" }, null);
        admin.updateUserListOfRole("role3", null, new String[] { "amara", "sunil" });
        try {
            admin.updateUserListOfRole(null, null, new String[] { "d" });
            fail("Exception thrown at null Roll name failed");
        }catch (Exception e) {
         // exptected error in negative testing
        }
        try {
            admin.updateUserListOfRole("rolexx", null, new String[] { "amara", "sunil" });
            fail("Exception thrown at invalid Roll names failed");
        } catch (Exception e) {
            // exptected error in negative testing
        }
        try{
            admin.updateRoleListOfUser("saman", new String[] { "x" }, new String[] { "y" });
            fail("Exception thrown at invalid Roll names failed");
         } catch (Exception e) {
            // exptected error in negative testing
         }

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

        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");
View Full Code Here

        realm.init(realmConfig, ClaimTestUtil.getClaimTestData(), ClaimTestUtil
                .getProfileTestData(), 0);
    }

    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

TOP

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

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.