Package org.wso2.carbon.user.core

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


            } 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

     * @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

     *             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

    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

                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

    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

                    }
                }
                if (!username.equals(registry.getUserName()) && !isAdmin) {
                    return false;   
                }
                UserStoreManager reader = realm.getUserStoreManager();
                return (reader.getUserClaimValue(username,
                        UserCoreConstants.ClaimTypeURIs.EMAIL_ADDRESS,
                        UserCoreConstants.DEFAULT_PROFILE)) != null;
            }
        } catch (UserStoreException ignore) {
            return false;
View Full Code Here

        try {
            Map<String, String> claimsMap = new HashMap<String, String>();
            claimsMap.put(UserCoreConstants.ClaimTypeURIs.GIVEN_NAME,
                          accountInfoBean.getFirstname());
            claimsMap.put(UserCoreConstants.ClaimTypeURIs.SURNAME, accountInfoBean.getLastname());
            UserStoreManager userStoreManager =
                    (UserStoreManager) realmService.getTenantUserRealm(tenantId)
                            .getUserStoreManager();
            userStoreManager.setUserClaimValues(
                    ClaimsMgtUtil.getAdminUserNameFromTenantId(realmService, tenantId),
                    claimsMap, UserCoreConstants.DEFAULT_PROFILE);
            log.info("FirstName: " + accountInfoBean.getFirstname() +
                     " has been updated to the tenant admin " +
                     ClaimsMgtUtil.getAdminUserNameFromTenantId(realmService, tenantId) + " of " +
View Full Code Here

            String msg = "Error in creating Realm for tenant, tenant domain: " + tenant.getDomain();
            log.error(msg, e);
            throw new Exception(msg, e);
        }

        UserStoreManager userStoreManager;
        try {
            userStoreManager = userRealm.getUserStoreManager();

            return userStoreManager;
        } catch (UserStoreException e) {
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.