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

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


        if (realmService == null) {
            String msg = "Error in getting the tenant manager. The realm service is not available.";
            log.error(msg);
            throw new RegistryException(msg);
        }
        TenantManager tenantManager = realmService.getTenantManager();
        try {
            return tenantManager.getTenantId(domain);
        } catch (org.wso2.carbon.user.api.UserStoreException e) {
            String msg = "Error in getting the tenant manager.";
            log.error(msg, e);
            throw new RegistryException(msg, e);
        }
View Full Code Here


    // Test adding tenants
    private void addTenants() throws RegistryException,
            org.wso2.carbon.user.api.UserStoreException, FileNotFoundException {
        RealmService realmService = ctx.getRealmService();
        TenantManager tenantManager = realmService.getTenantManager();

        String userMgtXML = getUserManagementConfigurationPath();

        RealmConfigXMLProcessor processor = new RealmConfigXMLProcessor();
        RealmConfiguration realmConfig = processor.buildRealmConfiguration(new FileInputStream(
                userMgtXML));

        Tenant tenant = new Tenant();
        tenant.setDomain("wso2.org");
        tenant.setRealmConfig(realmConfig);
        int tenantId = tenantManager.addTenant(tenant);
        Tenant tenant2 = (Tenant) tenantManager.getTenant(tenantId);

        // checking if the everything is stored.
        assertEquals("tenant domain should be equal.", tenant.getDomain(), tenant2.getDomain());

        Tenant tenant3 = new Tenant();
        tenant3.setDomain("abc.org");
        tenant3.setRealmConfig(realmConfig);
        tenantManager.addTenant(tenant3);


        Tenant[] tenants = (Tenant[]) tenantManager.getAllTenants();

        // check the get all tenants
        assertEquals("tenants length should be 2", tenants.length, 2);
        assertTrue("tenants should contain wso2.org",
                (tenants[0].getDomain() + tenants[1].getDomain()).contains("wso2.org"));
        assertTrue("tenants should contain abc.org",
                (tenants[0].getDomain() + tenants[1].getDomain()).contains("abc.org"));

        // if the domain exists
        assertTrue("wso2.org should exist", tenantManager.getTenantId("wso2.org") > 0);
        assertTrue("pqr.org should not exists", tenantManager.getTenantId("pqr.org") < 0);

        int tenantId4 = tenantManager.getTenantId("wso2.org");
        assertEquals("tenant domain should be wso2.org", "wso2.org",
                tenantManager.getDomain(tenantId4));

        // check the update
        Tenant tenant4 = (Tenant) tenantManager.getTenant(tenantId4);
        tenant4.setDomain("WSO2.com");
        tenantManager.updateTenant(tenant4);

        // checking the updated values
        Tenant tenant5 = (Tenant) tenantManager.getTenant(tenantId4);
        assertEquals("tenant domain should be equal.", tenant5.getDomain(), "WSO2.com");

        Tenant[] tenants2 = (Tenant[]) tenantManager.getAllTenants();
        // check the updated values get all tenants
        assertEquals("tenants length should be 2", tenants.length, 2);
        assertTrue("tenants should contain WSO2.com",
                (tenants2[0].getDomain() + tenants2[1].getDomain()).contains("WSO2.com"));
        assertTrue("tenants should contain abc.org",
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    private TenantManager initializeTenantManger(TenantMgtConfiguration tenantMgtConfiguration)
            throws Exception {
        TenantManager tenantManager = null;
        // read the tenant manager from tenant-mgt.xml
        //String className = configElement.getAttribute(new QName("class")).getAttributeValue();
        String className = tenantMgtConfiguration.getTenantManagerClass();
        Class clazz = Class.forName(className);
View Full Code Here

     * @throws Exception
     *             UserStoreException
     */
    private int addTenant(Tenant tenant) throws Exception {
        int tenantId;
        TenantManager tenantManager = TenantMgtCoreServiceComponent.getTenantManager();
        try {
            tenantId = tenantManager.addTenant(tenant);
            if (log.isDebugEnabled()) {
                log.debug("Tenant is successfully added: " + tenant.getDomain());
            }
        } catch (UserStoreException e) {
            String msg = "Error in adding tenant with domain: " + tenant.getDomain();
View Full Code Here

     * @throws Exception
     *             if unable to get the tenant id or if a tenant with same
     *             domain exists.
     */
    public static boolean isDomainNameAvailable(Tenant tenant) throws Exception {
        TenantManager tenantManager = TenantMgtCoreServiceComponent.getTenantManager();
        String tenantDomain = tenant.getDomain();
   
        // The registry reserved words are checked first.
        if (tenantDomain.equals("atom") || tenantDomain.equals("registry")
                || tenantDomain.equals("resource")) {
            String msg = "You can not use a registry reserved word:" + tenantDomain +
                         ":as a tenant domain. Please choose a different one.";
            log.error(msg);
            throw new Exception(msg);
        }
   
        int tenantId;
        try {
            tenantId = tenantManager.getTenantId(tenantDomain);
        } catch (UserStoreException e) {
            String msg = "Error in getting the tenant id for the given domain  " +
                         tenant.getDomain() + ".";
            log.error(msg);
            throw new Exception(msg, e);
View Full Code Here

        this.realmService = realmService;
    }
   
    @Override
    public void run() {
        TenantManager tenantManager = realmService.getTenantManager();
        Tenant[] tenants;
        try {
            tenants = (Tenant[]) tenantManager.getAllTenants();
            for (Tenant tenant : tenants) {
                //Run Daily generator
                RegistryUsageSummaryGenerator generator = new RegistryUsageSummaryGenerator(
                        tenant, BAMCalendar.DAY_OF_MONTH, client);
                try{
View Full Code Here

import org.wso2.carbon.common.constants.StratosConstants;
import org.wso2.carbon.redirector.servlet.util.Util;

public class RedirectorServletService {
    public String validateTenant(String tenantDomain) throws Exception {
        TenantManager tenantManager = Util.getTenantManager();
        int tenantId = tenantManager.getTenantId(tenantDomain);
        if (tenantId <= 0) {
            return StratosConstants.INVALID_TENANT;
        } else if (Util.getActivationService() != null &&
                !Util.getActivationService().isActive(tenantId)) {
            return StratosConstants.INACTIVE_TENANT;
View Full Code Here

    }

    private Customer getCurrentCustomer(UserRegistry userRegistry,
                                        BillingEngine billingEngine) throws Exception {
        int currentTenantId = userRegistry.getTenantId();
        TenantManager tenantManger = Util.getRealmService().getTenantManager();
        Tenant currentTenant = (Tenant) tenantManger.getTenant(currentTenantId);

        List<Customer> customers = billingEngine.getCustomersWithName(currentTenant.getDomain());
        if (customers == null || customers.isEmpty()) {
            return null;
        }
View Full Code Here

                    mailParameters.put("transaction-id", payment.getDescription());
                    mailParameters.put("amount", payment.getAmount().toString());
                    mailParameters.put("invoice-id", String.valueOf(payment.getInvoice().getId()));

                    try{
                        TenantManager tenantManager = Util.getRealmService().getTenantManager();
                        Tenant tenant = (Tenant) tenantManager.getTenant(customer.getId());
                        String customerName =
                                ClaimsMgtUtil.getFirstName(Util.getRealmService(), tenant, customer.getId());
                        if(customerName!=null){
                            mailParameters.put("customer-name", customerName);
                        }else{
View Full Code Here

    return isValidPattern(LoggingConstants.RegexPatterns.LOG_HEADER_PATTERN, line);
  }

  public int getTenantIdForDomain(String tenantDomain) throws LogViewerException {
    int tenantId;
    TenantManager tenantManager = LoggingServiceComponent.getTenantManager();
    if (tenantDomain == null || tenantDomain.equals("")) {
      tenantId = 0;
    } else {

      try {
        tenantId = tenantManager.getTenantId(tenantDomain);
      } catch (UserStoreException e) {
        throw new LogViewerException("Cannot find tenant id for the given tenant domain.");
      }
    }
    return tenantId;
View Full Code Here

TOP

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

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.