Package org.wso2.carbon.user.core

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


            claimsMap.put(UserCoreConstants.ClaimTypeURIs.GIVEN_NAME, tenant.getAdminFirstName());
            claimsMap.put(UserCoreConstants.ClaimTypeURIs.SURNAME, tenant.getAdminLastName());

            // can be extended to store other user information.
            UserStoreManager userStoreManager =
                    (UserStoreManager) TenantMgtServiceComponent.getRealmService().
                            getTenantUserRealm(tenant.getId()).getUserStoreManager();
            userStoreManager.setUserClaimValues(tenant.getAdminName(), claimsMap,
                                                UserCoreConstants.DEFAULT_PROFILE);

        } catch (Exception e) {
            String msg = "Error in adding claims to the user.";
            log.error(msg, e);
View Full Code Here


     * @param tenantInfoBean tenant information
     * @throws Exception UserStoreException
     */
    public void updateTenant(TenantInfoBean tenantInfoBean) throws Exception {
        TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
        UserStoreManager userStoreManager;

        // filling the non-set admin and admin password first
        UserRegistry configSystemRegistry = TenantMgtServiceComponent.getConfigSystemRegistry(
                tenantInfoBean.getTenantId());

        String tenantDomain = tenantInfoBean.getTenantDomain();

        int tenantId;
        try {
            tenantId = tenantManager.getTenantId(tenantDomain);
        } catch (UserStoreException e) {
            String msg = "Error in retrieving the tenant id for the tenant domain: " + tenantDomain
                         + ".";
            log.error(msg, e);
            throw new Exception(msg, e);
        }

        boolean updatePassword = false;
        boolean isPasswordChanged = false;
        if (tenantInfoBean.getAdminPassword() != null
            && !tenantInfoBean.getAdminPassword().equals("")) {
            updatePassword = true;
        }

        Tenant tenant;
        try {
            tenant = (Tenant) tenantManager.getTenant(tenantId);
        } catch (UserStoreException e) {
            String msg = "Error in retrieving the tenant id for the tenant domain: " +
                         tenantDomain + ".";
            log.error(msg, e);
            throw new Exception(msg, e);
        }

        // filling the first and last name values
        if (tenantInfoBean.getFirstname() != null &&
            !tenantInfoBean.getFirstname().trim().equals("")) {
            try {
                CommonUtil.validateName(tenantInfoBean.getFirstname(), "First Name");
            } catch (Exception e) {
                String msg = "Invalid first name is provided.";
                log.error(msg, e);
                throw new Exception(msg, e);
            }
        }
        if (tenantInfoBean.getLastname() != null &&
            !tenantInfoBean.getLastname().trim().equals("")) {
            try {
                CommonUtil.validateName(tenantInfoBean.getLastname(), "Last Name");
            } catch (Exception e) {
                String msg = "Invalid last name is provided.";
                log.error(msg, e);
                throw new Exception(msg, e);
            }
        }
        Map<String, String> claimsMap = new HashMap<String, String>(); // map of claims
        claimsMap.put(UserCoreConstants.ClaimTypeURIs.GIVEN_NAME, tenantInfoBean.getFirstname());
        claimsMap.put(UserCoreConstants.ClaimTypeURIs.SURNAME, tenantInfoBean.getLastname());

        userStoreManager = TenantMgtUtil.getUserStoreManager(tenant, tenant.getId());
        userStoreManager.setUserClaimValues(tenantInfoBean.getAdmin(), claimsMap,
                                            UserCoreConstants.DEFAULT_PROFILE);

        // filling the email value
        if (tenantInfoBean.getEmail() != null && !tenantInfoBean.getEmail().equals("")) {
            // validate the email
            try {
                CommonUtil.validateEmail(tenantInfoBean.getEmail());
            } catch (Exception e) {
                String msg = "Invalid email is provided.";
                log.error(msg, e);
                throw new Exception(msg, e);
            }
            tenant.setEmail(tenantInfoBean.getEmail());
        }

        UserRealm userRealm = configSystemRegistry.getUserRealm();
        try {
            userStoreManager = userRealm.getUserStoreManager();
        } catch (UserStoreException e) {
            String msg = "Error in getting the user store manager for tenant, tenant domain: " +
                         tenantDomain + ".";
            log.error(msg, e);
            throw new Exception(msg, e);
        }

        if (!userStoreManager.isReadOnly() && updatePassword) {
            // now we will update the tenant admin with the admin given
            // password.
            try {
                userStoreManager.updateCredentialByAdmin(tenantInfoBean.getAdmin(),
                                                         tenantInfoBean.getAdminPassword());
                isPasswordChanged = true;
            } catch (UserStoreException e) {
                String msg = "Error in changing the tenant admin password, tenant domain: " +
                             tenantInfoBean.getTenantDomain() + ". " + e.getMessage() + " for: " +
View Full Code Here

     */
    public boolean updateTenantPassword(TenantInfoBean tenantInfoBean) throws Exception {
        TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
        String tenantDomain = tenantInfoBean.getTenantDomain();

        UserStoreManager userStoreManager;

        int tenantId;
        try {
            tenantId = tenantManager.getTenantId(tenantDomain);
            if ((tenantId < 1) || (tenantId == MultitenantConstants.SUPER_TENANT_ID)) {
                // double checking for preventing password updates for super tenant.
                String msg = "Only the existing tenants can update the password";
                log.error(msg);
                throw new Exception(msg);
            }
        } catch (UserStoreException e) {
            String msg = "Error in retrieving the tenant id for the tenant domain: " +
                         tenantDomain + ".";
            log.error(msg);
            throw new Exception(msg, e);
        }

        // filling the non-set admin and admin password first
        UserRegistry configSystemRegistry = TenantMgtServiceComponent.
                getConfigSystemRegistry(tenantId);

        boolean updatePassword = false;
        if (tenantInfoBean.getAdminPassword() != null
            && !tenantInfoBean.getAdminPassword().equals("")) {
            updatePassword = true;
        }

        UserRealm userRealm = configSystemRegistry.getUserRealm();
        try {
            userStoreManager = userRealm.getUserStoreManager();
        } catch (UserStoreException e) {
            String msg = "Error in getting the user store manager for tenant, tenant domain: " +
                         tenantDomain + ".";
            log.error(msg, e);
            throw new Exception(msg, e);
        }

        if (!userStoreManager.isReadOnly() && updatePassword) {
            // now we will update the tenant admin with the admin given password.
            try {
                String adminName = ClaimsMgtUtil.getAdminUserNameFromTenantId(
                        TenantMgtServiceComponent.getRealmService(), tenantId);
                String password = tenantInfoBean.getAdminPassword();

                userStoreManager.updateCredentialByAdmin(adminName, password);
                log.info("Password reset by the admin for domain: " + tenantDomain);
                return true;
            } catch (UserStoreException e) {
                String msg = "Error in changing the tenant admin password, tenant domain: " +
                             tenantInfoBean.getTenantDomain() + ".";
View Full Code Here

            if(realm == null){
                log.warn("Realm creation failed. Tenant may be inactive or invalid.");
                return false;
            }
           
            UserStoreManager userStoreManager = realm.getUserStoreManager();

//            //update the permission tree before authentication
//            String tenantDomain = MultitenantUtils.getTenantDomain(username);
//            int tenantId = SAMLSSOUtil.getRealmService().getTenantManager().getTenantId(tenantDomain);
//            PermissionUpdateUtil.updatePermissionTree(tenantId);

            // Check the authentication
            isAuthenticated = userStoreManager.authenticate(UserCoreUtil.getTenantLessUsername(username), password);
            if(!isAuthenticated){
                if (log.isDebugEnabled()) {
                    log.debug("user authentication failed due to invalid credentials.");
                }
                return false;
View Full Code Here

        }
    }

    private OpenIDClaimDTO[] getClaimValues(String openId, String profileId,
            List<String> requiredClaims) throws Exception {
        UserStoreManager userStore = null;
        Map<String, String> claimValues = null;
        OpenIDClaimDTO[] claims = null;
        OpenIDClaimDTO dto = null;
        IdentityClaimManager claimManager = null;
        Claim[] claimData = null;
        String[] claimArray = new String[requiredClaims.size()];
        String userName = null;
        String domainName = null;
        String tenatUser = null;

        userName = OpenIDUtil.getUserName(openId);
        domainName = TenantUtils.getDomainNameFromOpenId(openId);

        tenatUser = userName;

        if (userName.contains("@")) {
            tenatUser = userName.substring(0, userName.indexOf("@"));
        }

        userStore = IdentityTenantUtil.getRealm(domainName, userName).getUserStoreManager();

        claimValues = userStore.getUserClaimValues(tenatUser, requiredClaims.toArray(claimArray),
                profileId);

        claims = new OpenIDClaimDTO[claimValues.size()];
        int i = 0;
        claimManager = IdentityClaimManager.getInstance();
View Full Code Here

        // Perform authentication
        //
        String username = aCredentials[0];
        String password = aCredentials[1];

        UserStoreManager authenticator;
        try {
            authenticator = userRealm.getUserStoreManager();
        } catch (UserStoreException e) {
            String msg = "Cannot get authenticator from Realm";
            log.error(msg, e);
            throw new SecurityException(msg, e);
        }

        try {
            if(authenticator.authenticate(username, password)){
                return new Subject(true,
                                   Collections.singleton(new JMXPrincipal(username)),
                                   Collections.EMPTY_SET,
                                   Collections.EMPTY_SET);
            } else {
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);

        admin.updateRoleListOfUser("saman", null, new String[] { "role2" });
        admin.updateRoleListOfUser("saman", new String[] { "role2" }, new String[] { "role4",
                "role3" });

        String[] rolesOfSaman = admin.getRoleListOfUser("saman");
        assertEquals(3, rolesOfSaman.length);

        // negative
        admin.updateUserListOfRole("role2", new String[] { "saman" }, null);
        admin.updateUserListOfRole("role3", null, new String[] { "amara", "sunil" });

        // negative
        try {
            //wrong roles
            admin.updateRoleListOfUser("saman", new String[] { "x" }, new String[] { "y" });
            TestCase.assertTrue(false);
        } 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");
        authMan.authorizeUser("sunil", "wall", "read");

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

        roles = jdbcAuthnManager.getAllowedRolesForResource("/permission/admin", "ui.execute");
        assertEquals(roles.length,1);
    }

    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
        admin.addUser("dimuthu", "credential", null, null, null, false);
        admin.addRole("role1", new String[] { "dimuthu" }, permisions);
        admin.addUser("vajira", "credential", new String[] { "role1" }, userProps, null, false);
        int id = admin.getUserId("dimuthu");
        int tenatId = admin.getTenantId("dimuthu");
       
        // authenticate
        assertTrue(admin.authenticate("dimuthu", "credential"));

        admin.updateCredentialByAdmin("dimuthu", "topsecret");
        assertTrue(admin.authenticate("dimuthu", "topsecret"));

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

        // update
        admin.updateCredential("dimuthu", "password", "topsecret");
        assertFalse(admin.authenticate("dimuthu", "credential"));
        assertTrue(admin.authenticate("dimuthu", "password"));

        String[] names = admin.listUsers("*", 100);
        assertEquals(3, names.length);

        String[] roleNames = admin.getRoleNames();
        assertEquals(4, roleNames.length);

        // delete
        admin.deleteUser("vajira");
        assertFalse(admin.authenticate("vajira", "credential"));
        admin.addUser("vajira", "credential", new String[] { "role1" }, userProps, null, false);
        admin.deleteRole("role1");
        admin.addRole("role1", new String[] { "dimuthu" }, permisions);
    }
View Full Code Here

        admin.deleteRole("role1");
        admin.addRole("role1", new String[] { "dimuthu" }, permisions);
    }

    public void doUserRoleStuff() throws Exception {
        UserStoreManager admin = realm.getUserStoreManager();

        admin.addRole("role2", null, null);
        admin.addRole("role3", null, null);
        admin.addRole("role4", null, null);
        admin.addUser("saman", "pass1", null, null, null, false);
        admin.addUser("amara", "pass2", null, null, null, false);
        admin.addUser("sunil", "pass3", null, null, null, false);

        admin.updateRoleListOfUser("saman", null, new String[] { "role2" });
        admin.updateRoleListOfUser("saman", new String[] { "role2" }, new String[] { "role4",
                "role3" });

        String[] rolesOfSaman = admin.getRoleListOfUser("saman");
        assertEquals(3, rolesOfSaman.length);

        // negative
        admin.updateUserListOfRole("role2", new String[] { "saman" }, null);
        admin.updateUserListOfRole("role3", null, new String[] { "amara", "sunil" });

        String[] users = admin.getUserListOfRole("role3");
        assertEquals(3, users.length);

        // negative
        try {
            admin.updateRoleListOfUser("saman", new String[] { "x" }, new String[] { "y" });
            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
        }
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.