Search in sources :

Example 1 with TenantInfoBean

use of org.wso2.carbon.stratos.common.beans.TenantInfoBean in project carbon-business-process by wso2.

the class BPSUserIdentityManager method getTenantIdFromUserId.

private int getTenantIdFromUserId(String userId) throws Exception {
    String[] userNameTokens = userId.split("@");
    int tenantId = BPMNConstants.SUPER_TENANT_ID;
    if (userNameTokens.length > 1) {
        TenantInfoBean tenantInfoBean = tenantMgtAdminService.getTenant(userNameTokens[userNameTokens.length - 1]);
        if (tenantInfoBean != null) {
            tenantId = tenantInfoBean.getTenantId();
        } else {
            throw new Exception("Error retrieving tenant id from userId :" + userId);
        }
    }
    return tenantId;
}
Also used : TenantInfoBean(org.wso2.carbon.stratos.common.beans.TenantInfoBean) UserStoreException(org.wso2.carbon.user.api.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BPMNAuthenticationException(org.wso2.carbon.bpmn.core.exception.BPMNAuthenticationException)

Example 2 with TenantInfoBean

use of org.wso2.carbon.stratos.common.beans.TenantInfoBean in project carbon-business-process by wso2.

the class BPSUserIdentityManager method findGroupsByUser.

@Override
public List<Group> findGroupsByUser(String userId) {
    List<Group> groups = new ArrayList<Group>();
    try {
        String[] userNameTokens = userId.split("@");
        int tenantId = BPMNConstants.SUPER_TENANT_ID;
        if (userNameTokens.length > 1) {
            TenantInfoBean tenantInfoBean = tenantMgtAdminService.getTenant(userNameTokens[userNameTokens.length - 1]);
            if (tenantInfoBean != null) {
                tenantId = tenantInfoBean.getTenantId();
            } else {
                log.error("Could not retrieve tenant ID for tenant domain : " + userNameTokens[userNameTokens.length - 1]);
                return new ArrayList<Group>();
            }
        }
        String[] roles = registryService.getUserRealm(tenantId).getUserStoreManager().getRoleListOfUser(userId);
        for (String role : roles) {
            Group group = new GroupEntity(role);
            groups.add(group);
        }
    } catch (UserStoreException e) {
        String msg = "Failed to get roles of the user: " + userId + ". Returning an empty roles list.";
        log.error(msg, e);
    } catch (Exception e) {
        log.error("error retrieving user tenant info", e);
    }
    return groups;
}
Also used : Group(org.activiti.engine.identity.Group) GroupEntity(org.activiti.engine.impl.persistence.entity.GroupEntity) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) TenantInfoBean(org.wso2.carbon.stratos.common.beans.TenantInfoBean) UserStoreException(org.wso2.carbon.user.api.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BPMNAuthenticationException(org.wso2.carbon.bpmn.core.exception.BPMNAuthenticationException)

Aggregations

ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 BPMNAuthenticationException (org.wso2.carbon.bpmn.core.exception.BPMNAuthenticationException)2 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)2 TenantInfoBean (org.wso2.carbon.stratos.common.beans.TenantInfoBean)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 ArrayList (java.util.ArrayList)1 Group (org.activiti.engine.identity.Group)1 GroupEntity (org.activiti.engine.impl.persistence.entity.GroupEntity)1