Search in sources :

Example 1 with UserInfo

use of models.security.UserInfo in project coprhd-controller by CoprHD.

the class Tenants method listJson.

public static void listJson() {
    List<TenantsDataTable.Tenant> tenants = Lists.newArrayList();
    List<TenantOrgRestRep> subtenants;
    UserInfo user = Security.getUserInfo();
    String source = Models.currentSource();
    if (Security.isRootTenantAdmin() || Security.isSecurityAdmin()) {
        TenantOrgRestRep rootTenant = TenantUtils.findRootTenant();
        if (source.equals(TenantSource.getTenantSource(rootTenant.getUserMappings())) || source.equals(TenantSource.TENANTS_SOURCE_ALL)) {
            tenants.add(new TenantsDataTable.Tenant(rootTenant, ((Security.isRootTenantAdmin() || Security.isSecurityAdmin()))));
        }
        subtenants = TenantUtils.getSubTenants(rootTenant.getId());
    } else if (Security.isHomeTenantAdmin()) {
        TenantOrgRestRep userTenant = TenantUtils.getUserTenant();
        if (source.equals(TenantSource.getTenantSource(userTenant.getUserMappings())) || source.equals(TenantSource.TENANTS_SOURCE_ALL)) {
            tenants.add(new TenantsDataTable.Tenant(userTenant, true));
        }
        subtenants = getViprClient().tenants().getByIds(user.getSubTenants());
    } else {
        subtenants = getViprClient().tenants().getByIds(user.getSubTenants());
    }
    for (TenantOrgRestRep tenant : subtenants) {
        boolean admin = Security.isRootTenantAdmin() || user.hasSubTenantRole(tenant.getId().toString(), Security.TENANT_ADMIN) || Security.isSecurityAdmin();
        if (admin && (source.equals(TenantSource.getTenantSource(tenant.getUserMappings())) || source.equals(TenantSource.TENANTS_SOURCE_ALL))) {
            tenants.add(new TenantsDataTable.Tenant(tenant, admin));
        }
    }
    renderJSON(DataTablesSupport.createJSON(tenants, params));
}
Also used : TenantsDataTable(models.datatable.TenantsDataTable) OpenStackTenantsDataTable(models.datatable.OpenStackTenantsDataTable) UserInfo(models.security.UserInfo)

Example 2 with UserInfo

use of models.security.UserInfo in project coprhd-controller by CoprHD.

the class Common method addCommonRenderArgs.

@Before(priority = 5)
public static void addCommonRenderArgs() {
    // Set cache control. We don't want caching of our dynamic pages
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
    response.setHeader("Pragma", "no-cache");
    UserInfo userInfo = Security.getUserInfo();
    angularRenderArgs().put(USER, userInfo);
    angularRenderArgs().put(AUTHENTICITY_TOKEN, SecurityUtils.stripXSS(session.getAuthenticityToken()));
    renderArgs.put(USER, userInfo);
    renderArgs.put(TOKEN, Security.getAuthToken());
    renderArgs.put(VDCS, getVDCs());
    // Notifications are only shown for tenant approvers
    if (Security.isTenantApprover() && DisasterRecoveryUtils.isActiveSite()) {
        renderArgs.put(NOTIFICATIONS, Notifications.getNotifications());
    }
    addReferrer();
}
Also used : UserInfo(models.security.UserInfo) Before(play.mvc.Before)

Example 3 with UserInfo

use of models.security.UserInfo in project coprhd-controller by CoprHD.

the class Security method authenticated.

/**
 * AJAXable method that can be used to determine if the user is authenticated.
 */
public static void authenticated() {
    if (StringUtils.isBlank(getAuthToken())) {
        renderJSON(false);
    }
    try {
        UserInfo user = getUserInfo();
        renderJSON(user != null);
    } catch (ViPRHttpException e) {
        Logger.error(e, "HTTP Error: %s %s", e.getHttpCode(), e.getMessage());
        if (e.getHttpCode() == HttpStatus.SC_UNAUTHORIZED) {
            renderJSON(false);
        }
        // Propogate other errors (502, 503 most importantly)
        error(e.getHttpCode(), e.getMessage());
    } catch (Exception e) {
        Logger.error(e, "Error getting user info");
        renderJSON("error");
    }
}
Also used : UserInfo(models.security.UserInfo) ViPRHttpException(com.emc.vipr.client.exceptions.ViPRHttpException) ViPRHttpException(com.emc.vipr.client.exceptions.ViPRHttpException)

Example 4 with UserInfo

use of models.security.UserInfo in project coprhd-controller by CoprHD.

the class Security method getUserInfo.

@Util
public static UserInfo getUserInfo() {
    String key = getUserInfoCacheKey();
    UserInfo user = (UserInfo) Cache.get(key);
    if (user == null) {
        user = new UserInfo(getViprClient().getUserInfo());
        Cache.set(key, user, CACHE_EXPR);
    }
    return user;
}
Also used : UserInfo(models.security.UserInfo) BourneUtil(util.BourneUtil) Util(play.mvc.Util)

Example 5 with UserInfo

use of models.security.UserInfo in project coprhd-controller by CoprHD.

the class Models method currentAdminTenant.

@Util
public static String currentAdminTenant() {
    String sessionTenant = session.get(TENANT_ID);
    if (sessionTenant != null && canSelectTenant(sessionTenant)) {
        return validateSessionTenant(sessionTenant);
    } else {
        session.remove(TENANT_ID);
        UserInfo info = Security.getUserInfo();
        if (Security.isTenantAdmin() && !Security.isHomeTenantAdmin()) {
            for (URI tenant : info.getSubTenants()) {
                String tenantId = tenant.toString();
                if (info.hasSubTenantRole(tenantId, Security.TENANT_ADMIN)) {
                    return tenantId;
                }
            }
        }
        // fallback to the home tenant if nothing else matches
        return info.getTenant();
    }
}
Also used : UserInfo(models.security.UserInfo) URI(java.net.URI) Util(play.mvc.Util)

Aggregations

UserInfo (models.security.UserInfo)6 Util (play.mvc.Util)3 URI (java.net.URI)2 ViPRHttpException (com.emc.vipr.client.exceptions.ViPRHttpException)1 OpenStackTenantsDataTable (models.datatable.OpenStackTenantsDataTable)1 TenantsDataTable (models.datatable.TenantsDataTable)1 Before (play.mvc.Before)1 BourneUtil (util.BourneUtil)1