Package org.wso2.carbon.user.core

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


     * @throws RegistryException if the operation failed.
     */
    public static void copyAuthorizations(String sourcePath, String targetPath)
            throws RegistryException {

        UserRealm userRealm = CurrentSession.getUserRealm();
        try {
            if (sourcePath != null && targetPath != null) {
                clearAuthorizations(targetPath);
                if (RegistryUtils.getParentPath(sourcePath).equals(
                        RegistryUtils.getParentPath(targetPath))) {
                    String[] actions = {ActionConstants.GET, ActionConstants.PUT,
                            ActionConstants.DELETE, AccessControlConstants.AUTHORIZE};
                    for (String action : actions) {
                        // Authorize required roles
                        String[] roles = userRealm.getAuthorizationManager().
                                getAllowedRolesForResource(sourcePath, action);
                        if (roles != null && roles.length > 0) {
                            for (String role : roles) {
                                if (!userRealm.getAuthorizationManager().isRoleAuthorized(
                                        role, targetPath, action)) {
                                    userRealm.getAuthorizationManager().authorizeRole(role,
                                            targetPath, action);
                                }
                            }
                        }
                        // Deny required roles
                        roles = userRealm.getAuthorizationManager().getDeniedRolesForResource(
                                sourcePath, action);
                        if (roles != null && roles.length > 0) {
                            for (String role : roles) {
                                if (userRealm.getAuthorizationManager().isRoleAuthorized(
                                        role, targetPath, action)) {
                                    userRealm.getAuthorizationManager().denyRole(role,
                                            targetPath, action);
                                }
                            }
                        }
                    }
View Full Code Here


        // get the realm config to retrieve admin username, password
        RealmConfiguration realmConfig = ctx.getRealmService().getBootstrapRealmConfiguration();
       
        UserRegistry adminRegistry = embeddedRegistryService.
                getUserRegistry(realmConfig.getAdminUserName(), realmConfig.getAdminPassword());
        UserRealm adminRealm = adminRegistry.getUserRealm();

        adminRealm.getUserStoreManager().addUser("foo", "cce123", null, null, null);
        adminRealm.getUserStoreManager();

        adminRealm.getAuthorizationManager().
                authorizeUser("foo", RegistryConstants.ROOT_PATH, ActionConstants.PUT);
        adminRealm.getUserStoreManager().addUser("bar", "swe123", null, null, null);

        UserRegistry fooRegistry = embeddedRegistryService.getUserRegistry("foo", "cce123");
        UserRegistry barRegistry = embeddedRegistryService.getUserRegistry("bar", "swe123");

        String r1Content = "R1";
View Full Code Here

        } catch (ResourceNotFoundException e) {
            notExist = true;
        }
        assertTrue("The /test should be null in the second registry", notExist);

        UserRealm userRealm1 = registry1.getUserRealm();
        try {
            userRealm1.getUserStoreManager().addUser("don1", "password", null, null, null);
        } catch (UserStoreException e) {
            throw new RegistryException("Error in adding a user", e);
        }

        Registry registry3 = embeddedRegistryService.getUserRegistry("don1", "password", 0);
View Full Code Here

                embeddedRegistryService.getUserRegistry(realmConfig.getAdminUserName(), 0);

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

     */
    public static void updateRoleUIPermission(String roleName, String[] rawPermissions)
            throws UserAdminException {
        try {
            String[] optimizedList = UserCoreUtil.optimizePermissions(rawPermissions);
            UserRealm realm = AdminServicesUtil.getUserRealm();
            AuthorizationManager authMan = realm.getAuthorizationManager();
            authMan.clearRoleActionOnAllResources(roleName, UserMgtConstants.EXECUTE_ACTION);
            for (String path : optimizedList) {
                authMan.authorizeRole(roleName, path, UserMgtConstants.EXECUTE_ACTION);
            }
        } catch (UserStoreException e) {
View Full Code Here

            }

            // realm is taken from the registry rather than realm service to fix
            // chrooted issues
            UserRealm realm = registry.getUserRealm();
            String adminRole = realm.getRealmConfiguration().getAdminRoleName();
            AuthorizationManager authMan = realm.getAuthorizationManager();
            if (!authMan.isRoleAuthorized(adminRole, CarbonConstants.UI_PERMISSION_COLLECTION,
                    UserMgtConstants.EXECUTE_ACTION)) {
                authMan.authorizeRole(adminRole, CarbonConstants.UI_PERMISSION_COLLECTION,
                        UserMgtConstants.EXECUTE_ACTION);
            }
View Full Code Here

    public UserRealm getCachedUserRealm(int tenantId) throws UserStoreException {
        return userRealmMap.get(Integer.valueOf(tenantId));
    }

    public UserRealm getUserRealm(RealmConfiguration tenantRealmConfig) throws UserStoreException {
        UserRealm userRealm = null;
        int tenantId = tenantRealmConfig.getTenantId();
        userRealm = userRealmMap.get(Integer.valueOf(tenantId));
        if (userRealm == null && tenantId == 0) {
            userRealm = bootstrapRealm;
        }

        if (tenantId != 0) {
            MultiTenantRealmConfigBuilder realmConfigBuilder = getMultiTenantRealmConfigBuilder();
            if (realmConfigBuilder != null) {
                tenantRealmConfig = realmConfigBuilder.getRealmConfigForTenantToCreateRealm(
                        bootstrapRealmConfig, tenantRealmConfig, tenantId);
            }
        }

        if (userRealm == null) {
            synchronized (this) {
                userRealm = initializeRealm(tenantRealmConfig, tenantId);
                userRealmMap.put(Integer.valueOf(tenantId), userRealm);
            }
        } else {
            long existingRealmPersistedTime = -1L;
            long newRealmConfigPersistedTime = -1L;
            if (userRealm.getRealmConfiguration().getPersistedTimestamp() != null) {
                existingRealmPersistedTime = userRealm.getRealmConfiguration()
                        .getPersistedTimestamp().getTime();
            }
            if (tenantRealmConfig.getPersistedTimestamp() != null) {
                newRealmConfigPersistedTime = tenantRealmConfig.getPersistedTimestamp().getTime();
            }
View Full Code Here

    @SuppressWarnings("unchecked")
    public UserRealm initializeRealm(RealmConfiguration realmConfig, int tenantId)
            throws UserStoreException {
        ClaimBuilder.setBundleContext(bc);
        ProfileConfigurationBuilder.setBundleContext(bc);
        UserRealm userRealm = null;
        try {
            Class clazz = Class.forName(realmConfig.getRealmClassName());
            userRealm = (UserRealm) clazz.newInstance();
            userRealm.init(realmConfig, properties, tenantId);
        } catch (Exception e) {
            String msg = "Cannot initialize the realm.";
            log.error(msg, e);
            throw new UserStoreException(msg, e);
        }
View Full Code Here

    private static void loadData() {
        synchronized (loadlock) {
            if (isEmailUserName == null) {
                try {
                    if (realmService != null) {
                        UserRealm realm = (UserRealm)realmService.getBootstrapRealm();
                        RealmConfiguration realmConfig = realm.getRealmConfiguration();

                        if (isCrossTenantUniqueUserName == null) {
                            String isUnique = realmConfig
                                    .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USERNAME_UNIQUE);
                            if ("true".equals(isUnique)) {
View Full Code Here

                // the tenant is not active.
                String msg = "The tenant is not active. tenant id: " + tenantId + ".";
                log.error(msg);
                throw new RegistryException(msg);
            }
            UserRealm userRealm;
            try {
                userRealm = (UserRealm)realmService.getTenantUserRealm(tenantId);
            } catch (Exception e) {
                String msg = "Failed in getting the user realm for the tenant id: " + tenantId;
                log.error(msg);
                throw new RegistryException(msg, e);
            }
            UserStoreManager authenticator;
            try {
                authenticator = userRealm.getUserStoreManager();
            } catch (Exception e) {
                String msg = "Failed in getting the user realm for the tenant id: " + tenantId;
                log.error(msg);
                throw new RegistryException(msg, e);
            }
View Full Code Here

TOP

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

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.