Pages

Subscribe:

Ads 468x60px

Tuesday, August 11, 2015

[WSO2] Adding tenants using Admin Services - Sample Code

Adding tenants using admin services is straight forward. You have to use two admin services.

1. AuthenticationAdminService
2. TenantMgtAdminService

The  AuthenticationAdminService is used to authenticate the user and get the session. Below is a sample code for adding a tenant

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class TenantMgtAdmin {
    private static final String AS_URL = "https://localhost:9443/services/";

    public static void addTenant(String cookie) throws Exception {

        TenantMgtAdminServiceStub tenantMgtStub = null;
        String tenantMgtEndpoint = AS_URL + "TenantMgtAdminService";

        tenantMgtStub = new TenantMgtAdminServiceStub(tenantMgtEndpoint);
        Options option = tenantMgtStub._getServiceClient().getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

        String value = tenantMgtStub.addTenant(getTenantBean());

        System.out.println("Returned Value ::" + value);
    }

    private static TenantInfoBean getTenantBean() {

        TenantInfoBean bean = new TenantInfoBean();
        bean.setActive(true);
        bean.setAdmin("sample");
        bean.setAdminPassword("sample");
        bean.setEmail("sample@sample.com");
        bean.setFirstname("FirstName");
        bean.setLastname("LastName");
        bean.setTenantDomain("sample.com");
        return bean;
    }

The github url for the project. https://github.com/arunasujith/tenant-sample

No comments:

Post a Comment