Examples of UserStoreManager


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

        }
    }

    public FlaggedName[] getRolesOfUser(String userName) throws UserAdminException {
        try {
            UserStoreManager admin = realm.getUserStoreManager();
            String[] userroles = admin.getRoleListOfUser(userName);
            String[] allRoles = admin.getRoleNames();
            FlaggedName[] flaggedNames = new FlaggedName[allRoles.length];
            Arrays.sort(userroles);
            for (int i = 0; i < allRoles.length; i++) {
                String role = allRoles[i];
                FlaggedName fname = new FlaggedName();
View Full Code Here

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

                log.error("Security Alert! Carbon anonymous user is being manipulated");
                throw new UserAdminException("Invalid data");// obscure error
                                                             // message
            }

            UserStoreManager admin = realm.getUserStoreManager();
            String[] oldRoleList = admin.getRoleListOfUser(userName);
            Arrays.sort(roleList);
            Arrays.sort(oldRoleList);

            List<String> delRoles = new ArrayList<String>();
            List<String> addRoles = new ArrayList<String>();

            for (String name : roleList) {
                int oldindex = Arrays.binarySearch(oldRoleList, name);
                if (oldindex < 0) {
                    addRoles.add(name);
                }
            }

            for (String name : oldRoleList) {
                int newindex = Arrays.binarySearch(roleList, name);
                if (newindex < 0) {
                    if (realm.getRealmConfiguration().getEveryOneRoleName().equals(name)) {
                        log.error("Security Alert! Carbon everyone role is being manipulated");
                        throw new UserAdminException("Invalid data");// obscure
                                                                     // error
                                                                     // message
                    }
                    delRoles.add(name);
                }
            }

            admin.updateRoleListOfUser(userName, delRoles.toArray(new String[delRoles.size()]),
                    addRoles.toArray(new String[addRoles.size()]));
        } catch (UserStoreException e) {
            // previously logged so logging not needed
            throw new UserAdminException(e.getMessage(), e);
        } catch (Exception e) {
View Full Code Here

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

        try {
            BulkImportConfig config = new BulkImportConfig(inStream, fileName);
            if (defaultPassword != null && defaultPassword.trim().length() > 0) {
                config.setDefaultPassword(defaultPassword.trim());
            }
            UserStoreManager userStore = this.realm.getUserStoreManager();
            if (fileName.endsWith("csv")) {
                CSVUserBulkImport csvAdder = new CSVUserBulkImport(config);
                csvAdder.addUserList(userStore);
            } else if (fileName.endsWith("xls") || fileName.endsWith("xlsx")) {
                ExcelUserBulkImport excelAdder = new ExcelUserBulkImport(config);
View Full Code Here

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

    }

    public void changePasswordByUser(String oldPassword, String newPassword)
            throws UserAdminException {
        try {
            UserStoreManager userStore = this.realm.getUserStoreManager();
            HttpServletRequest request = (HttpServletRequest) MessageContext
                    .getCurrentMessageContext().getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
            HttpSession httpSession = request.getSession(false);
            String userName = (String) httpSession.getAttribute(ServerConstants.USER_LOGGED_IN);
            userStore.updateCredential(userName, newPassword, oldPassword);
        } catch (UserStoreException e) {
            // previously logged so logging not needed
            throw new UserAdminException(e.getMessage(), e);
        }
    }
View Full Code Here

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

            } 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);
            }
            if (authenticator.getTenantId() > 0) {
                userName = UserCoreUtil.getTenantLessUsername(userName);
            }
            if (!authenticator.authenticate(userName, password)) {
                String msg = "Attempted to authenticate invalid user.";
                log.warn(msg);
                throw new AuthorizationFailedException(msg);
            }
View Full Code Here

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

     * @throws Exception
     *             UserStoreException
     */
    private void updateTenantAdminPassword(UserRealm userRealm, Tenant tenant) throws Exception {
        try {
            UserStoreManager userStoreManager = userRealm.getUserStoreManager();
            if (!userStoreManager.isReadOnly()) {
                userStoreManager.updateCredentialByAdmin(tenant.getAdminName(),
                                                         tenant.getAdminPassword());
                if (log.isDebugEnabled()) {
                    log.debug("Successfully set the password for the tenant.");
                }
            }
View Full Code Here

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

     *             exception in getting the user store manager
     */
    public static String getClaimfromUserStoreManager(RealmService realmService, Tenant tenant,
                                                      int tenantId, String claim)
                                                                                 throws UserStoreException {
        UserStoreManager userStoreManager = null;
        String claimValue = "";
        try {
          if (realmService.getTenantUserRealm(tenantId) != null) {
             userStoreManager = (UserStoreManager) realmService.getTenantUserRealm(tenantId)
                 .getUserStoreManager();
          }
          
        } catch (Exception e) {
            String msg = "Error retrieving the user store manager for the tenant";
            log.error(msg, e);
            throw new UserStoreException(msg, e);
        }
        try {
          if(userStoreManager != null) {
             claimValue =
                     userStoreManager.getUserClaimValue(
                                                        getAdminUserNameFromTenantId(realmService,
                                                                                     tenantId),
                                                        claim,
                                                        UserCoreConstants.DEFAULT_PROFILE);
          }
View Full Code Here

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

    UserRealm realm;
    public UserMgtAction(RegistryService registryService) throws RegistryException {
        realm = registryService.getUserRealm(0);
    }
    public void execute() throws Exception {
        UserStoreManager userStoreManager = realm.getUserStoreManager();
        if (!userStoreManager.isExistingUser("tracker")) {
            userStoreManager.addUser("tracker", "tracker123", null, null, null, false);
            Permission[] permisions = new Permission[] { new Permission("high security", "read")};
            userStoreManager.addRole("tracker_role", new String[] {"tracker"}, permisions);
        }
        userStoreManager.updateCredentialByAdmin("tracker", "tracker123");
        // do some authorizations
        AuthorizationManager authManager = realm.getAuthorizationManager();
        authManager.authorizeRole("tracker_role", "tracker_obj", "read");
    }
View Full Code Here

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

                String username = endpoint.substring(7);
                if (Utils.getRegistryService() != null) {
                    UserRegistry registry = Utils.getRegistryService().getConfigSystemRegistry();
                    if (registry != null && registry.getUserRealm() != null &&
                            registry.getUserRealm().getUserStoreManager() != null) {
                        UserStoreManager reader = registry.getUserRealm().getUserStoreManager();
                        email = "mailto:" + reader.getUserClaimValue(username,
                                UserCoreConstants.ClaimTypeURIs.EMAIL_ADDRESS,
                                UserCoreConstants.DEFAULT_PROFILE);
                    }
                }
            } catch (Exception e) {
                log.error("Failed Sending Notification to: " + endpoint);
                return;
            }
            log.debug("Sending Notification to: " + email);
            publishEvent(event, subscription, email, true);
        } else if (endpoint.toLowerCase().startsWith("role://")) {
            List<String> emails = new LinkedList<String>();
            try {
                String roleName = endpoint.substring(7);
                if (Utils.getRegistryService() != null) {
                    UserRegistry registry = Utils.getRegistryService().getConfigSystemRegistry();
                    if (registry != null && registry.getUserRealm() != null &&
                            registry.getUserRealm().getUserStoreManager() != null) {
                        UserStoreManager reader = registry.getUserRealm().getUserStoreManager();
                        for (String username : reader.getUserListOfRole(roleName)) {
                            String temp = reader.getUserClaimValue(username,
                                    UserCoreConstants.ClaimTypeURIs.EMAIL_ADDRESS,
                                    UserCoreConstants.DEFAULT_PROFILE);
                            if (temp != null && temp.length() > 0) {
                                emails.add("mailto:" + temp);
                            }
View Full Code Here

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

    private static final Log log = LogFactory.getLog(ActivityBeanPopulator.class);

    public static ActivityBean populate(UserRegistry userRegistry, String userName, String resourcePath, String fromDate,
                                        String toDate, String filter, String pageStr) throws Exception{
        UserRealm realm = userRegistry.getUserRealm();
        UserStoreManager reader = realm.getUserStoreManager();
        String[] roles = reader.getRoleListOfUser(userRegistry.getUserName());
        List list = Arrays.asList(roles);
        ActivityBean activityBean = new ActivityBean();

        if (resourcePath != null && resourcePath.equals("")) {
            resourcePath = null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.