Package org.wso2.carbon.user.core.tenant

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


    }

    public static Customer getCurrentCustomer(UserRegistry userRegistry) throws Exception {
        int currentTenantId = userRegistry.getTenantId();
        TenantManager tenantManger = getRealmService().getTenantManager();
        Tenant currentTenant = (Tenant) tenantManger.getTenant(currentTenantId);
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
        List<Customer> customers = billingEngine.getCustomersWithName(currentTenant.getDomain());
        if (customers == null || customers.size() == 0) {
            return null;
        }
        return customers.get(0);
    }
View Full Code Here


    public static Customer getCurrentBillingCustomer(int tenantId) throws RegistryException {
        // get the host name of the current domain
        if (tenantId == MultitenantConstants.SUPER_TENANT_ID) {
            return null;
        }
        Tenant tenant;
        try {
            tenant = (Tenant) realmService.getTenantManager().getTenant(tenantId);
        } catch (org.wso2.carbon.user.api.UserStoreException e) {
            String msg = "Error in getting the realm Information.";
            log.error(msg, e);
            throw new RegistryException(msg, e);
        }
        if (tenant == null) {
            return null;
        }
        String customerName = tenant.getDomain();

        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
        Customer customer;
        try {
View Full Code Here

                log.error(msg, e);
                // not throwing the exception in finally more up.
            }
        }
        // persists the tenant.
        Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
        TenantPersistor persistor = TenantMgtServiceComponent.getTenantPersistor();
        persistor.persistTenant(tenant, true, tenantInfoBean.getSuccessKey(), tenantInfoBean.getOriginatedService());
        TenantMgtUtil.addClaimsToUserStoreManager(tenant);

        // For the registration validation - mail for the tenant email address
        TenantMgtUtil.sendEmail(tenant, tenantInfoBean.getOriginatedService());

        // Notifies the super admin about the new tenant creation
        TenantMgtUtil.notifyTenantCreationToSuperAdmin(
                tenantInfoBean.getTenantDomain(), tenantInfoBean.getAdmin(),
                tenantInfoBean.getEmail());

        //adding the subscription entry
        try{
            boolean subscriptionAdded = TenantMgtUtil.addUsagePlan(tenantInfoBean);
            if(subscriptionAdded){
                log.debug("Subscription added successfully for the tenant: " + tenantInfoBean.getTenantDomain());
            }else{
                log.error("Could not add the subscription for tenant: " + tenantInfoBean.getTenantDomain());
            }
        }catch(Exception e){
            log.error("Error occurred while adding the subscription for tenant: " +
                    tenantInfoBean.getTenantDomain() + " " + e.getMessage(), e);
        }

        return TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
    }
View Full Code Here

    public static void notifyTenantCreation(String domainName, String adminName, String email) {
        TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
        String firstName = "";
        try {
            int tenantId = tenantManager.getTenantId(domainName);
            Tenant tenant = (Tenant) tenantManager.getTenant(tenantId);
            firstName = ClaimsMgtUtil.getFirstName(TenantMgtServiceComponent.getRealmService(),
                                                   tenant, tenantId);
        } catch (Exception e) {
            String msg = "Unable to get the tenant with the tenant domain";
            log.error(msg, e);
View Full Code Here

        TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
        String firstName = "";
        String lastName = "";
        try {
            int tenantId = tenantManager.getTenantId(domainName);
            Tenant tenant = (Tenant) tenantManager.getTenant(tenantId);
            firstName = ClaimsMgtUtil.getFirstName(TenantMgtServiceComponent.getRealmService(),
                                                   tenant, tenantId);
            lastName = ClaimsMgtUtil.getLastName(TenantMgtServiceComponent.getRealmService(),
                                                 tenant, tenantId);
View Full Code Here

     *
     * @param tenantInfoBean input
     * @return tenant
     */
    public static Tenant initializeTenant(TenantInfoBean tenantInfoBean) {
        Tenant tenant = new Tenant();
        tenant.setDomain(tenantInfoBean.getTenantDomain());
        tenant.setEmail(tenantInfoBean.getEmail());
        tenant.setAdminName(tenantInfoBean.getAdmin());

        // we are duplicating the params stored in the claims here as well; they
        // are in Tenant class
        // to make it work with LDAP; but they do not make it to the databases.
        tenant.setAdminFirstName(tenantInfoBean.getFirstname());
        tenant.setAdminLastName(tenantInfoBean.getLastname());

        tenant.setAdminPassword(tenantInfoBean.getAdminPassword());

        // sets created date.
        Calendar createdDateCal = tenantInfoBean.getCreatedDate();
        long createdDate;
        if (createdDateCal != null) {
            createdDate = createdDateCal.getTimeInMillis();
        } else {
            createdDate = System.currentTimeMillis();
        }
        tenant.setCreatedDate(new Date(createdDate));

        if (log.isDebugEnabled()) {
            log.debug("Tenant object Initialized from the TenantInfoBean");
        }
        return tenant;
View Full Code Here

        if (userRegistry.getTenantId() != 0) {
            log.error("Security Alert! Non super tenant trying to create a tenant.");
            throw new Exception("Invalid data."); // obscure error message.
        }
        Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
        TenantPersistor persistor = TenantMgtServiceComponent.getTenantPersistor();
        // not validating the domain ownership, since created by super tenant
        persistor.persistTenant(tenant, false, tenantInfoBean.getSuccessKey(),
                                tenantInfoBean.getOriginatedService());
        TenantMgtUtil.addClaimsToUserStoreManager(tenant);
        // For the registration validation - mail for the tenant email address
        TenantMgtUtil.sendEmail(tenant, tenantInfoBean.getOriginatedService());

        // Notifies the super admin about the new tenant creation
        TenantMgtUtil.notifyTenantCreationToSuperAdmin(
                tenantInfoBean.getTenantDomain(),tenantInfoBean.getAdmin(),
                tenantInfoBean.getEmail());

        //adding the subscription entry
        try{
            boolean subscriptionAdded = TenantMgtUtil.addUsagePlan(tenantInfoBean);
            if(subscriptionAdded){
                log.debug("Subscription added successfully for the tenant: " + tenantInfoBean.getTenantDomain());
            }else{
                log.error("Could not add the subscription for tenant: " + tenantInfoBean.getTenantDomain());
            }
        }catch(Exception e){
            log.error("Error occurred while adding the subscription for tenant: " +
                    tenantInfoBean.getTenantDomain() + " " + e.getMessage(), e);   
        }


        return TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
    }
View Full Code Here

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

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

            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
        // forgotten that.
View Full Code Here

TOP

Related Classes of org.wso2.carbon.user.core.tenant.Tenant

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.