Search in sources :

Example 6 with TenantOrgRestRep

use of com.emc.storageos.model.tenant.TenantOrgRestRep in project coprhd-controller by CoprHD.

the class VCenters method getVcenterTenantOptions.

public static void getVcenterTenantOptions(String id) {
    List<TenantOrgRestRep> vCenterTenantOptions = new ArrayList<TenantOrgRestRep>();
    if (StringUtils.isBlank(id) || id.equalsIgnoreCase("null")) {
        renderJSON(vCenterTenantOptions);
        return;
    }
    List<ACLEntry> vcenterAcls = VCenterUtils.getAcl(uri(id));
    if (CollectionUtils.isEmpty(vcenterAcls)) {
        renderJSON(vCenterTenantOptions);
        return;
    }
    addNoneTenantOption(id, vCenterTenantOptions);
    Iterator<ACLEntry> aclEntryIterator = vcenterAcls.iterator();
    while (aclEntryIterator.hasNext()) {
        ACLEntry aclEntry = aclEntryIterator.next();
        if (aclEntry == null) {
            continue;
        }
        TenantOrgRestRep tenantOrgRestRep = TenantUtils.getTenant(aclEntry.getTenant());
        if (tenantOrgRestRep != null) {
            vCenterTenantOptions.add(tenantOrgRestRep);
        }
    }
    renderJSON(vCenterTenantOptions);
}
Also used : ACLEntry(com.emc.storageos.model.auth.ACLEntry) ArrayList(java.util.ArrayList) TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep)

Example 7 with TenantOrgRestRep

use of com.emc.storageos.model.tenant.TenantOrgRestRep in project coprhd-controller by CoprHD.

the class TenantUtils method findRootTenant.

public static TenantOrgRestRep findRootTenant() {
    URI userTenantId = getViprClient().getUserTenantId();
    TenantOrgRestRep currentTenant = getViprClient().tenants().get(userTenantId);
    while (currentTenant.getParentTenant() != null) {
        currentTenant = getViprClient().tenants().get(currentTenant.getParentTenant());
    }
    return currentTenant;
}
Also used : TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep) URI(java.net.URI)

Example 8 with TenantOrgRestRep

use of com.emc.storageos.model.tenant.TenantOrgRestRep in project coprhd-controller by CoprHD.

the class TenantsCall method call.

@Override
public List<TenantOrgRestRep> call() {
    List<TenantOrgRestRep> tenants = Lists.newArrayList();
    TenantOrgRestRep rootTenant = findRootTenant();
    tenants.add(rootTenant);
    tenants.addAll(getSubTenants(id(rootTenant)));
    return tenants;
}
Also used : TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep)

Example 9 with TenantOrgRestRep

use of com.emc.storageos.model.tenant.TenantOrgRestRep in project coprhd-controller by CoprHD.

the class MarshallUtil method convertTenantUserMappingToString.

/**
 * leveraging TenantOrgRestRep's JAXB representation, converts given tenant's user-mapping to a string.
 *
 * @param tenant
 * @return
 * @throws Exception
 */
public static String convertTenantUserMappingToString(TenantOrg tenant) throws Exception {
    TenantOrgRestRep response = new TenantOrgRestRep();
    if (tenant.getUserMappings() != null) {
        for (AbstractChangeTrackingSet<String> userMappingSet : tenant.getUserMappings().values()) {
            for (String existingMapping : userMappingSet) {
                response.getUserMappings().add(BasePermissionsHelper.UserMapping.toParam(BasePermissionsHelper.UserMapping.fromString(existingMapping)));
            }
        }
    }
    StringWriter writer = new StringWriter();
    JAXBContext jaxbContext = JAXBContext.newInstance(TenantOrgRestRep.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.marshal(response, writer);
    return writer.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep) JAXBContext(javax.xml.bind.JAXBContext)

Example 10 with TenantOrgRestRep

use of com.emc.storageos.model.tenant.TenantOrgRestRep in project coprhd-controller by CoprHD.

the class MarshallUtil method convertStringToUserMappingList.

/**
 * leveraging TenantOrgRestRep's JAXB representation, converting its string to List of UserMapping object.
 *
 * @param strUserMappings
 * @return
 */
public static List<BasePermissionsHelper.UserMapping> convertStringToUserMappingList(String strUserMappings) {
    List<BasePermissionsHelper.UserMapping> userMappingList = null;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(TenantOrgRestRep.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        TenantOrgRestRep response = (TenantOrgRestRep) unmarshaller.unmarshal(new StringReader(strUserMappings));
        userMappingList = BasePermissionsHelper.UserMapping.fromParamList(response.getUserMappings());
    } catch (JAXBException e) {
        log.error("An error occurred when converting string {} to list. Cause: {}", strUserMappings, e);
    }
    return userMappingList;
}
Also used : JAXBException(javax.xml.bind.JAXBException) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

TenantOrgRestRep (com.emc.storageos.model.tenant.TenantOrgRestRep)22 TenantCreateParam (com.emc.storageos.model.tenant.TenantCreateParam)5 URI (java.net.URI)5 ProjectParam (com.emc.storageos.model.project.ProjectParam)4 UserMappingAttributeParam (com.emc.storageos.model.tenant.UserMappingAttributeParam)3 UserMappingParam (com.emc.storageos.model.tenant.UserMappingParam)3 ProjectElement (com.emc.storageos.model.project.ProjectElement)2 TenantResponse (com.emc.storageos.model.tenant.TenantResponse)2 UserInfo (com.emc.storageos.model.user.UserInfo)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 WebResource (com.sun.jersey.api.client.WebResource)2 ArrayList (java.util.ArrayList)2 JAXBContext (javax.xml.bind.JAXBContext)2 ACLEntry (com.emc.storageos.model.auth.ACLEntry)1 AuthnUpdateParam (com.emc.storageos.model.auth.AuthnUpdateParam)1 RoleAssignmentChanges (com.emc.storageos.model.auth.RoleAssignmentChanges)1 RoleAssignmentEntry (com.emc.storageos.model.auth.RoleAssignmentEntry)1 RoleAssignments (com.emc.storageos.model.auth.RoleAssignments)1 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)1