Package org.wso2.carbon.user.core

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


    }
    /**
     * This overrides the base class functionality to suit the OpenID related functionality.
     */
    protected void populateClaimValues(RahasData rahasData) throws IdentityProviderException {
        UserStoreManager connector = null;
        Iterator<RequestedClaimData> iterator = null;
        List<String> list = null;
        OpenIDRequestedClaimData requestedClaimData = null;
        String userId = null;
        Map<String, String> mapValues = null;
        String claimVal = null;

        // Get the user id.
       userId = getUserIdentifier();

        try {
            connector = IdentityTenantUtil.getRealm(null, userId).getUserStoreManager();
        } catch (Exception e) {
            throw new IdentityProviderException(e.getMessage(), e);
        }

        // Get the column names for the URIs
        iterator = requestedClaims.values().iterator();
        list = new ArrayList<String>();

        // First we need to figure-out which attributed we need to retrieve from
        // the user store.
        while (iterator.hasNext()) {
            requestedClaimData = (OpenIDRequestedClaimData) iterator.next();
            if (requestedClaimData != null
                    && !requestedClaimData.getUri().equals(IdentityConstants.CLAIM_PPID)
                    && !requestedClaimData.getUri().equals(IdentityConstants.CLAIM_OPENID)) {
                list.add(requestedClaimData.getUri());
            }
        }

        String[] claimValues = new String[list.size()];
        // Get the claims values corresponding to the user from the user store.
        try {
            mapValues = connector.getUserClaimValues(userId, list.toArray(claimValues), null);
        } catch (Exception e) {
            throw new IdentityProviderException(e.getMessage(), e);
        }
        iterator = requestedClaims.values().iterator();

View Full Code Here


    public boolean isAddUserEnabled() throws Exception {
      
        UserRealm userRealm = IdentityTenantUtil.getRealm(null, null);
        if (userRealm != null) {
            UserStoreManager userStoreManager = userRealm.getUserStoreManager();
            if (userStoreManager != null) {
                return !userStoreManager.isReadOnly();
            }
        }

        return false;
View Full Code Here

        return fieldDTO;
    }

    private void addUser(String userName, String password, Map<String, String> claimList,
            String profileName, UserRealm realm) throws IdentityException {
        UserStoreManager admin = null;
        Permission permission = null;
        try {
            admin = realm.getUserStoreManager();
            if (!admin.isExistingRole(IdentityConstants.IDENTITY_DEFAULT_ROLE)) {
                permission = new Permission("/permission/admin/login", UserMgtConstants.EXECUTE_ACTION);
                admin.addRole(IdentityConstants.IDENTITY_DEFAULT_ROLE, null,
                        new Permission[]{permission});
            }
            admin.addUser(userName, password,
                    new String[]{IdentityConstants.IDENTITY_DEFAULT_ROLE}, claimList, profileName);
        } catch (UserStoreException e) {
            throw new IdentityException("Error occurred while adding user : " + userName, e);
        }
    }
View Full Code Here

        }
    }

    protected void populateClaimValues(String userIdentifier, SAMLAttributeCallback callback)
            throws IdentityProviderException {
        UserStoreManager connector = null;
        RahasData rahasData = null;

        if (log.isDebugEnabled()) {
            log.debug("Populating claim values");
        }

        if (requestedClaims.isEmpty()) {
            return;
        }

        try {
            connector = IdentityTenantUtil.getRealm(null, userIdentifier).getUserStoreManager();
        } catch (Exception e) {
            log.error("Error while instantiating IdentityUserStore", e);
            throw new IdentityProviderException("Error while instantiating IdentityUserStore", e);
        }

        // get the column names for the URIs
        Iterator<RequestedClaimData> ite = requestedClaims.values().iterator();
        List<String> claimList = new ArrayList<String>();
        rahasData = callback.getData();

        while (ite.hasNext()) {
            RequestedClaimData claim = (RequestedClaimData) ite.next();
            if (claim != null && !claim.getUri().equals(IdentityConstants.CLAIM_PPID)) {
                claimList.add(claim.getUri());
            }
        }

        String[] claimArray = new String[claimList.size()];
        String userId = userIdentifier;
        Map<String, String> mapValues = null;

        try {
            mapValues = connector.getUserClaimValues(userId, claimList.toArray(claimArray), null);
            ite = requestedClaims.values().iterator();
            while (ite.hasNext()) {
                SAMLAttribute attribute = null;
                Attribute saml2Attribute = null;
                RequestedClaimData claimData = ite.next();
View Full Code Here

        log.info("Information card details stored for card id : "
                + card.getInformationCardReference().getCardId());
    }

    private boolean isValidClaim(String user, Claim claim) throws IdentityProviderException {
        UserStoreManager userStore = null;

        if (IdentityConstants.CLAIM_PPID.equals(claim.getClaimUri())) {
            claim.setDisplayTag(IdentityConstants.PPID_DISPLAY_VALUE);
            return true;
        }

        try {
            userStore = AdminServicesUtil.getUserRealm().getUserStoreManager();
            if (userStore.getUserClaimValue(user, claim.getClaimUri(), null) != null) {
                return true;
            }
        } catch (Exception e) {
            throw new IdentityProviderException(e.getMessage(), e);
        }
View Full Code Here

     */
    public OpenIDUserProfileDTO[] getUserProfiles(String openId, OpenIDParameterDTO[] requredClaims)
            throws Exception {
        String userName = null;
        UserRealm realm = null;
        UserStoreManager reader = null;
        String tenatUser = null;
        String domainName = null;

        try {
            userName = OpenIDUtil.getUserName(openId);
            tenatUser = UserCoreUtil.getTenantLessUsername(userName);

            domainName = TenantUtils.getDomainNameFromOpenId(openId);

            realm = IdentityTenantUtil.getRealm(domainName, userName);
            reader = realm.getUserStoreManager();
            String[] profileNames = reader.getProfileNames(tenatUser);
            OpenIDUserProfileDTO[] profileDtoSet = new OpenIDUserProfileDTO[profileNames.length];

            ParameterList paramList = null;
            AuthRequest authReq = null;
            List<String> claimList = null;
View Full Code Here

     * @return
     * @throws Exception
     */
    private OpenIDClaimDTO[] getOpenIDClaimValues(String openId, String profileId,
            List<String> claimList) 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[claimList.size()];
        String userName = null;
        String domainName = null;
        String tenatUser;
        UserRealm realm = null;

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

        realm = IdentityTenantUtil.getRealm(domainName, userName);
        userStore = realm.getUserStoreManager();
        claimValues = userStore.getUserClaimValues(tenatUser, claimList.toArray(claimArray),
                profileId);

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

     */
    public static boolean hasAdminAuthorizations(String userName, UserRealm userRealm)
            throws RegistryException {

        try {
            UserStoreManager userStoreReader = userRealm.getUserStoreManager();

            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 systemUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;

            if (systemUser.equals(userName)) {
                return true;
            }

            String adminUser = realmConfig.getAdminUserName();
            if (adminUser.equals(userName)) {
                return true;
            }

            String[] roles = userStoreReader.getRoleListOfUser(userName);
            String adminRoleName = realmConfig.getAdminRoleName();
            if (containsString(adminRoleName, roles)) {
                return true;
            }

View Full Code Here

        Resource r = registry1.newResource();
        registry1.put("/test2", r);

        UserRealm userRealm1 = registry1.getUserRealm();
        UserStoreManager userStoreManager1;
        try {
            userStoreManager1 = userRealm1.getUserStoreManager();
        } catch (UserStoreException e) {
            throw new RegistryException("Error in retrieving UserStoreManager.");
        }
        AuthorizationManager authorizationManager1;
        try {
            authorizationManager1 = userRealm1.getAuthorizationManager();
        } catch (UserStoreException e) {
            throw new RegistryException("Error in retrieving AuthorizationManager.");
        }

        // adding some users
        try {
            userStoreManager1.addUser("user1t0", "password", null, null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding user user1t0.");
        }
        try {
            userStoreManager1.addUser("user2t0", "password", null, null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding user user2t0.");
        }
        try {
            userStoreManager1.addUser("user3t0", "password", null, null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding user user3t0.");
        }

        // adding more users we are going to add roles with
        try {
            userStoreManager1.addUser("user4t0", "password", null, null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding user user4t0.");
        }
        try {
            userStoreManager1.addUser("user5t0", "password", null, null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding user user5t0.");
        }
        try {
            userStoreManager1.addUser("user6t0", "password", null, null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding user user6t0.");
        }

        // adding some roles
        try {
            userStoreManager1.addRole("role1t0", null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding role role1t0.");
        }
        try {
            userStoreManager1.addRole("role2t0", null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding role role2t0.");
        }
        try {
            userStoreManager1.addRole("role3t0", null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding role role3t0.");
        }
//
//        // now assign authorizations to first set of users.
//        try {
//            authorizationManager1.authorizeUser("user1t0", "/test2", ActionConstants.PUT);
//        } catch (UserStoreException e) {
//            throw new RegistryException("Error in authorizing user1t0.");
//        }
//        try {
//            authorizationManager1.authorizeUser("user2t0", "/test2", ActionConstants.DELETE);
//        } catch (UserStoreException e) {
//            throw new RegistryException("Error in authorizing user2t0.");
//        }
//        try {
//            authorizationManager1.authorizeUser("user2t0", "/test2", "authorize");
//        } catch (UserStoreException e) {
//            throw new RegistryException("Error in authorizing user3t0.");
//        }

        // then assign roles to the second set of users.
        try {
            userStoreManager1.updateRoleListOfUser("user4t0", null, new String[]{"role1t0"});
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding user user4t0 to role1t0 role.");
        }
        try {
            userStoreManager1.updateRoleListOfUser("user5t0", null, new String[]{"role2t0"});
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding user user5t0 to role2t0 role.");
        }
        try {
            userStoreManager1.updateRoleListOfUser("user6t0", null, new String[]{"role3t0"});
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding user user6t0 to role3t0 role.");
        }

        // now giving authorizations to the role.
        try {
            authorizationManager1.authorizeRole("role1t0", "/test2", ActionConstants.PUT);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in authorizing role1t0.");
        }
        try {
            authorizationManager1.authorizeRole("role2t0", "/test2", ActionConstants.DELETE);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in authorizing role2t0.");
        }
        try {
            authorizationManager1.authorizeRole("role3t0", "/test2", "authorize");
        } catch (UserStoreException e) {
            throw new RegistryException("Error in authorizing role3t0.");
        }

        // secondly we will check the user store from tenant 1 and verify no overlaps with tenant 0
        UserRegistry registry2 =
                embeddedRegistryService.getUserRegistry(realmConfig.getAdminUserName(), 1);

        UserRealm userRealm2 = registry2.getUserRealm();
        UserStoreManager userStoreManager2;
        try {
            userStoreManager2 = userRealm2.getUserStoreManager();
        } catch (UserStoreException e) {
            throw new RegistryException("Error in retrieving UserStoreManager.");
        }
        AuthorizationManager authorizationManager2;
        try {
            authorizationManager2 = userRealm2.getAuthorizationManager();
        } catch (UserStoreException e) {
            throw new RegistryException("Error in retrieving AuthorizationManager.");
        }

        String[] users;
        try {
            users = userStoreManager2.listUsers("*", 10);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in retrieving UserStoreManager.");
        }
        // check the existence of the user
        assertFalse("UserStore for tenant1 should not have user1t0",
                Arrays.binarySearch(users, "user1t0") >= 0);
        assertFalse("UserStore for tenant1 should not have user2t0",
                Arrays.binarySearch(users, "user2t0") >= 0);
        assertFalse("UserStore for tenant1 should not have user3t0",
                Arrays.binarySearch(users, "user3t0") >= 0);
        assertFalse("UserStore for tenant1 should not have user4t0",
                Arrays.binarySearch(users, "user4t0") >= 0);
        assertFalse("UserStore for tenant1 should not have user5t0",
                Arrays.binarySearch(users, "user5t0") >= 0);
        assertFalse("UserStore for tenant1 should not have user6t0",
                Arrays.binarySearch(users, "user6t0") >= 0);

        // check the existence of the role
        assertFalse("UserStore for tenant1 should not have role1t0",
                Arrays.binarySearch(users, "role1t0") >= 0);
        assertFalse("UserStore for tenant1 should not have role2t0",
                Arrays.binarySearch(users, "role2t0") >= 0);
        assertFalse("UserStore for tenant1 should not have role3t0",
                Arrays.binarySearch(users, "role3t0") >= 0);

        // check the user authorizations
        assertFalse("UserStore for tenant1 should not have user1t0",
                Arrays.binarySearch(users, "user1t0") >= 0);
        assertFalse("UserStore for tenant1 should not have user2t0",
                Arrays.binarySearch(users, "user2t0") >= 0);
        assertFalse("UserStore for tenant1 should not have user3t0",
                Arrays.binarySearch(users, "user3t0") >= 0);

        // check the authorization of the users.
        try {
            assertFalse("UserStore for tenant1 should not have authorizations for user1t0",
                    authorizationManager2
                            .isUserAuthorized("user1t0", "/test2", ActionConstants.PUT));
            assertFalse("UserStore for tenant1 should not have authorizations for user2t0",
                    authorizationManager2
                            .isUserAuthorized("user2t0", "/test2", ActionConstants.DELETE));
            assertFalse("UserStore for tenant1 should not have authorizations for user3t0",
                    authorizationManager2.isUserAuthorized("user3t0", "/test2", "authorize"));
        } catch (UserStoreException e) {
            throw new RegistryException("Error in checking authorizations.");
        }

        // check the user is added to the role
        try {
            assertFalse("UserStore for tenant1 should not have user4t0 user in role role1t0",
                    Arrays.binarySearch(userStoreManager2.getRoleListOfUser("user5t0"),
                            "role1t0") >= 0);
            assertFalse("UserStore for tenant1 should not have user5t0 user in role role2t0",
                    Arrays.binarySearch(userStoreManager2.getRoleListOfUser("user5t0"),
                            "role2t0") >= 0);
            assertFalse("UserStore for tenant1 should not have user6t0 user in role role3t0",
                    Arrays.binarySearch(userStoreManager2.getRoleListOfUser("user6t0"),
                            "role3t0") >= 0);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in checking authorizations.");
        }
    }
View Full Code Here

        // first we will fill the user store for tenant 0
        RealmConfiguration realmConfig = ctx.getRealmService().getBootstrapRealmConfiguration();
        UserRegistry userRegistry1 =
                embeddedRegistryService.getUserRegistry(realmConfig.getAdminUserName(), 1);

        UserStoreManager userStoreManager = userRegistry1.getUserRealm().getUserStoreManager();

        Map<String, String> claimMap = new HashMap<String, String>();
        claimMap.put("http://wso2.org/claims/givenname", "admin123");
        claimMap.put("http://wso2.org/claims/emailaddress", "admin@wso2.org");

        userStoreManager.setUserClaimValues("admin", claimMap, "home-profile");


        Map<String, String> obtained = userStoreManager.getUserClaimValues("admin", new String[]{
                "http://wso2.org/claims/givenname", "http://wso2.org/claims/emailaddress"},
                "home-profile");
        assertEquals("The email should be same",
                obtained.get("http://wso2.org/claims/emailaddress"), "admin@wso2.org");
        assertEquals("The name should be same", obtained.get("http://wso2.org/claims/givenname"),
                "admin123");

        userStoreManager.addUser("another-admin", "another-admin123", null, null, null);

        // we will check another user in the same tenant have access to the claims
        UserRegistry userRegistry2 = embeddedRegistryService.getUserRegistry("another-admin", 1);
        UserStoreManager userStoreManager2 = userRegistry2.getUserRealm().getUserStoreManager();

        Map<String, String> userRegistryObtained =
                userStoreManager2.getUserClaimValues("admin", new String[]{
                        "http://wso2.org/claims/givenname", "http://wso2.org/claims/emailaddress"},
                        "home-profile");
        assertEquals("The email should be same",
                userRegistryObtained.get("http://wso2.org/claims/emailaddress"), "admin@wso2.org");
        assertEquals("The name should be same",
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.