Examples of TenantManager


Examples of org.wso2.carbon.user.core.tenant.TenantManager

     *
     * @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: " +
                             tenantInfoBean.getAdmin();
                log.error(msg, e);
                throw new Exception(msg, e);
            }
        }

        try {
            tenantManager.updateTenant(tenant);
        } catch (UserStoreException e) {
            String msg = "Error in updating the tenant for tenant domain: " + tenantDomain + ".";
            log.error(msg, e);
            throw new Exception(msg, e);
        }
View Full Code Here

Examples of org.wso2.carbon.user.core.tenant.TenantManager

     * @param tenantInfoBean tenant domain details
     * @return true if successfully reset
     * @throws Exception if failed due to userStore or registry exceptions.
     */
    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);
View Full Code Here

Examples of org.wso2.carbon.user.core.tenant.TenantManager

     *
     * @param tenantDomain tenant domain
     * @throws Exception UserStoreException.
     */
    public void activateTenant(String tenantDomain) throws Exception {
        TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
        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);
        }

        try {
            tenantManager.activateTenant(tenantId);
        } catch (UserStoreException e) {
            String msg = "Error in activating the tenant for tenant domain: " + tenantDomain + ".";
            log.error(msg, e);
            throw new Exception(msg, e);
        }
View Full Code Here

Examples of org.wso2.carbon.user.core.tenant.TenantManager

     *
     * @param tenantDomain tenant domain
     * @throws Exception UserStoreException
     */
    public void deactivateTenant(String tenantDomain) throws Exception {
        TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
        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);
        }

        try {
            tenantManager.deactivateTenant(tenantId);
        } catch (UserStoreException e) {
            String msg =
                    "Error in deactivating the tenant for tenant domain: " + tenantDomain +
                    ".";
            log.error(msg, e);
View Full Code Here

Examples of org.wso2.carbon.user.core.tenant.TenantManager

    public static boolean resetPassword(TenantInfoBean tenantInfoBean) throws Exception {
        AdminManagementSubscriber adminMgtSubscriber = new AdminManagementSubscriber();
        String adminName = tenantInfoBean.getAdmin();
        String domainName = tenantInfoBean.getTenantDomain();

        TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
        int tenantId = tenantManager.getTenantId(domainName);

        if (tenantId < 1) {
            String msg = "Tenant with the domain " + domainName + " doesn't exist.";
            log.error(msg);
            return false; // tenant doesn't exist
        }

        Tenant tenant = (Tenant) tenantManager.getTenant(tenantId);
        String email = tenant.getEmail();

        String adminNameFromUserStore = ClaimsMgtUtil.getAdminUserNameFromTenantId(
                TenantMgtServiceComponent.getRealmService(), tenantId);
        // Admin Name is included in the email, in case if the user has
View Full Code Here

Examples of org.wso2.carbon.user.core.tenant.TenantManager

     *
     * @param tenantInfoBean tenant information
     * @throws Exception if retrieving the credentials or sending the mail failed.
     */
    public static void notifyResetPassword(TenantInfoBean tenantInfoBean) throws Exception {
        TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();

        int tenantId = tenantInfoBean.getTenantId();
        Tenant tenant = (Tenant) tenantManager.getTenant(tenantId);
        String firstName = ClaimsMgtUtil.getFirstName(TenantMgtServiceComponent.getRealmService(),
                                                      tenant, tenant.getId());

        // load the mail configuration
        Map<String, String> userParams = new HashMap<String, String>();
View Full Code Here

Examples of org.wso2.carbon.user.core.tenant.TenantManager

    private static Log log = LogFactory.getLog(ManagementPermissionsAdder.class);
    Tenant[] tenants;
    List<Integer> tenantIds;

    public ManagementPermissionsAdder() throws Exception {
        TenantManager tenantManager = Util.getRealmService().getTenantManager();
        tenants = tenantManager.getAllTenants();
        tenantIds = new ArrayList<Integer>();
        for (int i = 0; i < tenants.length; i++) {
            if (tenants[i].isActive()) {
                tenantIds.add(tenants[i].getId());
            }
View Full Code Here

Examples of org.wso2.carbon.user.core.tenant.TenantManager

        return values.toArray(new RequestStatistics[values.size()]);
    }

    public TenantUsage getTenantUsage(int tenantId, String yearMonth) throws Exception {
        //get the domain name
        TenantManager tenantManger = Util.getRealmService().getTenantManager();
        String domain = tenantManger.getDomain(tenantId);
        TenantUsage tenantUsage = new TenantUsage(tenantId, domain);

        //Get the startDate, endDate from yearMonth String
        Date date = CommonUtil.getDateFromMonthString(yearMonth);
        Calendar startDate = Calendar.getInstance();
View Full Code Here

Examples of org.wso2.carbon.user.core.tenant.TenantManager

            "/repository/components/org.wso2.carbon.bandwidth-use";
    private static final Log log = LogFactory.getLog(Alpha1.class);

    public void migrate() throws Exception {
        // changes to the data model for the statics.
        TenantManager tenantManager = Util.getRealmService().getTenantManager();
        SystemMeteringAgent meteringAgent = Util.getSystemMeteringAgent();

        //get super tenant governance registry
        UserRegistry superTenantGovernanceRegistry = Util.getSuperTenantGovernanceSystemRegistry();
        if (!superTenantGovernanceRegistry.resourceExists(OLD_BANDWIDTH_USE_STORE_PATH)) {
            return;
        }

        Tenant[] tenants = tenantManager.getAllTenants();
        // uses only the current year month 2010-july
        String yearMonth = CommonUtil.getCurrentMonthString();
        for (Tenant tenant : tenants) {
            int tenantId = tenant.getId();
            long incomingBw = getOldIncomingRegistryBandwidth(yearMonth, tenantId);
View Full Code Here

Examples of org.wso2.carbon.user.core.tenant.TenantManager

     * @param yearMonth
     * @return
     * @throws Exception
     */
    public TenantUsage[] retrieveTenantUsages(String yearMonth) throws Exception {
        TenantManager tenantManager = Util.getRealmService().getTenantManager();
        Tenant[] tenants = (Tenant[]) tenantManager.getAllTenants();
        List<TenantUsage> tenantUsages = new ArrayList<TenantUsage>();
        for (Tenant tenant : tenants) {
            if (tenant.isActive()) {
                TenantUsage tenantUsage = Util.getTenantUsageRetriever().getTenantUsage(
                        tenant.getId(), yearMonth);
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.