Search in sources :

Example 96 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class VirtualArrayService method userTenantHasPermissionForVirtualPool.

/**
 * Determines if the VirtualPool with the passed id is accessible to
 * the user's tenant (includes the subtenants user has TenantAdmin role) .
 *
 * @param vpoolId The VirtualPool id.
 *
 * @return true if the VirtualPool is accessible to the user's tenant, false otherwise.
 */
private boolean userTenantHasPermissionForVirtualPool(String vpoolId) {
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, URI.create(vpoolId));
    if (vpool == null) {
        _log.error("VirtualPool {} could not be found in the database", vpoolId);
        return false;
    }
    StorageOSUser user = getUserFromContext();
    URI tenantURI = URI.create(user.getTenantId());
    // check user's home tenant
    if (_permissionsHelper.tenantHasUsageACL(tenantURI, vpool)) {
        _log.debug("Home tenant {} has usage ACL for VirtualPool {}", tenantURI, vpoolId);
        return true;
    }
    // check user's subtenant
    for (String subtenantId : _permissionsHelper.getSubtenantsForUser(user)) {
        if (_permissionsHelper.tenantHasUsageACL(URI.create(subtenantId), vpool)) {
            _log.debug("Subtenant {} has usage ACL for VirtualPool {}", tenantURI, vpoolId);
            return true;
        }
    }
    return false;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI)

Example 97 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class VolumeGroupService method getVolumeGroups.

/**
 * List volume groups.
 *
 * @brief List all volume groups
 * @return A reference to VolumeGroupList.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VolumeGroupList getVolumeGroups() {
    VolumeGroupList volumeGroupList = new VolumeGroupList();
    List<URI> ids = _dbClient.queryByType(VolumeGroup.class, true);
    Iterator<VolumeGroup> iter = _dbClient.queryIterativeObjects(VolumeGroup.class, ids);
    StorageOSUser user = getUserFromContext();
    if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN)) {
        while (iter.hasNext()) {
            VolumeGroup vg = iter.next();
            volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(vg));
        }
    } else {
        log.info("checking tenant");
        // otherwise, filter by only authorized to use
        URI tenant = URI.create(user.getTenantId());
        while (iter.hasNext()) {
            VolumeGroup vg = iter.next();
            List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, vg);
            if (volumes == null || volumes.isEmpty()) {
                // if no volume in the application yet, the application is visible to all tenants
                volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(vg));
            } else {
                Volume firstVol = volumes.get(0);
                URI volTenant = firstVol.getTenant().getURI();
                if (volTenant.equals(tenant)) {
                    volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(vg));
                }
            }
        }
    }
    return volumeGroupList;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 98 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class VolumeGroupService method getVolumeGroup.

/**
 * List a volume group
 *
 * @param id volume group Id
 * @brief Show details for a volume group
 * @return ApplicationRestRep
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
public VolumeGroupRestRep getVolumeGroup(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, VolumeGroup.class, "id");
    VolumeGroup volumeGroup = (VolumeGroup) queryResource(id);
    StorageOSUser user = getUserFromContext();
    if (!_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN)) {
        // Check if the application tenant is the same as the user tenant
        List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
        if (volumes != null && !volumes.isEmpty()) {
            URI tenant = URI.create(user.getTenantId());
            Volume firstVol = volumes.get(0);
            URI volTenant = firstVol.getTenant().getURI();
            if (!volTenant.equals(tenant)) {
                APIException.forbidden.insufficientPermissionsForUser(user.getName());
            }
        }
    }
    VolumeGroupRestRep resp = DbObjectMapper.map(volumeGroup);
    resp.setReplicationGroupNames(CopyVolumeGroupUtils.getReplicationGroupNames(volumeGroup, _dbClient));
    resp.setVirtualArrays(CopyVolumeGroupUtils.getVirtualArrays(volumeGroup, _dbClient));
    return resp;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) VolumeGroupRestRep(com.emc.storageos.model.application.VolumeGroupRestRep) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 99 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class VirtualDataCenterService method blockRoot.

private void blockRoot() {
    Principal principal = sc.getUserPrincipal();
    if (!(principal instanceof StorageOSUser)) {
        throw APIException.forbidden.invalidSecurityContext();
    }
    StorageOSUser user = (StorageOSUser) principal;
    if (user.getName().equalsIgnoreCase(ROOT)) {
        throw APIException.forbidden.insufficientPermissionsForUser(ROOT);
    }
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Principal(java.security.Principal)

Example 100 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class AuthenticationResource method tryLogin.

/**
 * See if the user is already logged in or try to login the user
 * if credentials were supplied. Return authentication status
 *
 * @param httpRequest
 * @param service
 * @param setCookie
 * @param servletResponse
 * @param tokenOnly false if either token or credentials can be used to attempt the login. True if only token is accepted.
 * @return LoginStatus of the user.
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
private LoginStatus tryLogin(HttpServletRequest httpRequest, String service, boolean setCookie, HttpServletResponse servletResponse, boolean tokenOnly) throws UnsupportedEncodingException, IOException {
    String newToken = null;
    String userName = null;
    _log.debug("Logging in");
    UsernamePasswordCredentials credentials = tokenOnly ? null : getCredentials(httpRequest);
    if (credentials == null) {
        // check if we already have a user context
        StorageOSUser user = getUserFromContext();
        if (user != null) {
            newToken = user.getToken();
            userName = user.getName();
            _log.debug("Logged in with user from context");
        }
    } else {
        StorageOSUserDAO user = authenticateUser(credentials);
        if (user != null) {
            validateLocalUserExpiration(credentials);
            newToken = _tokenManager.getToken(user);
            if (newToken == null) {
                _log.error("Could not generate token for user: {}", user.getUserName());
                throw new IllegalStateException(MessageFormat.format("Could not generate token for user: {}", user.getUserName()));
            }
            userName = user.getUserName();
            auditOp(URI.create(user.getTenantId()), URI.create(user.getUserName()), OperationTypeEnum.AUTHENTICATION, true, null, credentials.getUserName());
        } else {
            auditOp(null, null, OperationTypeEnum.AUTHENTICATION, false, null, credentials.getUserName());
        }
    }
    return new LoginStatus(userName, newToken, null != credentials);
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Aggregations

StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)105 Produces (javax.ws.rs.Produces)59 Path (javax.ws.rs.Path)53 URI (java.net.URI)50 GET (javax.ws.rs.GET)36 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)31 Consumes (javax.ws.rs.Consumes)24 POST (javax.ws.rs.POST)15 ArrayList (java.util.ArrayList)13 Order (com.emc.storageos.db.client.model.uimodels.Order)12 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)12 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)11 NamedURI (com.emc.storageos.db.client.model.NamedURI)10 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)10 PUT (javax.ws.rs.PUT)10 Operation (com.emc.storageos.db.client.model.Operation)9 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)9 HashSet (java.util.HashSet)9 StringSet (com.emc.storageos.db.client.model.StringSet)8 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)8