Search in sources :

Example 1 with Validate

use of org.sonatype.siesta.Validate in project concord by walmartlabs.

the class SecretResource method create.

@POST
@ApiOperation("Creates a new secret")
@Path("/{orgName}/secret")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Validate
public SecretOperationResponse create(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam MultipartInput input) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    try {
        SecretType type = assertType(input);
        String storeType = assertStoreType(input);
        String name = assertName(input);
        assertUnique(org.getId(), name);
        boolean generatePwd = MultipartUtils.getBoolean(input, Constants.Multipart.GENERATE_PASSWORD, false);
        String storePwd = getOrGenerateStorePassword(input, generatePwd);
        SecretVisibility visibility = getVisibility(input);
        UUID projectId = getProject(input, org.getId());
        switch(type) {
            case KEY_PAIR:
                {
                    return createKeyPair(org.getId(), projectId, name, storePwd, visibility, input, storeType);
                }
            case USERNAME_PASSWORD:
                {
                    return createUsernamePassword(org.getId(), projectId, name, storePwd, visibility, input, storeType);
                }
            case DATA:
                {
                    return createData(org.getId(), projectId, name, storePwd, visibility, input, storeType);
                }
            default:
                throw new ValidationErrorsException("Unsupported secret type: " + type);
        }
    } catch (IOException e) {
        throw new ConcordApplicationException("Error while processing the request: " + e.getMessage(), e);
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) IOException(java.io.IOException) UUID(java.util.UUID) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) Validate(org.sonatype.siesta.Validate)

Example 2 with Validate

use of org.sonatype.siesta.Validate in project concord by walmartlabs.

the class SecretResource method updateAccessLevel.

@POST
@ApiOperation("Updates the access level for the specified secret and team")
@Path("/{orgName}/secret/{secretName}/access/bulk")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Validate
public GenericOperationResult updateAccessLevel(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("secretName") @ConcordKey String secretName, @ApiParam @Valid Collection<ResourceAccessEntry> entries) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    UUID secretId = secretDao.getId(org.getId(), secretName);
    if (secretId == null) {
        throw new ConcordApplicationException("Secret not found: " + secretName, Status.NOT_FOUND);
    }
    if (entries == null) {
        throw new ConcordApplicationException("List of teams is null.", Status.BAD_REQUEST);
    }
    secretManager.updateAccessLevel(secretId, entries, true);
    return new GenericOperationResult(OperationResult.UPDATED);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) Validate(org.sonatype.siesta.Validate)

Example 3 with Validate

use of org.sonatype.siesta.Validate in project concord by walmartlabs.

the class SecretResource method updateAccessLevel.

@POST
@ApiOperation("Updates the access level for the specified secret and team")
@Path("/{orgName}/secret/{secretName}/access")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Validate
public GenericOperationResult updateAccessLevel(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("secretName") @ConcordKey String secretName, @ApiParam @Valid ResourceAccessEntry entry) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    UUID secretId = secretDao.getId(org.getId(), secretName);
    if (secretId == null) {
        throw new ConcordApplicationException("Secret not found: " + secretName, Status.NOT_FOUND);
    }
    UUID teamId = ResourceAccessUtils.getTeamId(orgDao, teamDao, org.getId(), entry);
    secretManager.updateAccessLevel(secretId, teamId, entry.getLevel());
    return new GenericOperationResult(OperationResult.UPDATED);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) Validate(org.sonatype.siesta.Validate)

Example 4 with Validate

use of org.sonatype.siesta.Validate in project concord by walmartlabs.

the class UserLdapGroup method sync.

/**
 * Sync Ldap groups for a ldap user
 *
 * @param req user's data
 * @return GenericOperationResult result
 */
@POST
@ApiOperation("Sync ldap groups for a user")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/sync")
@Validate
public GenericOperationResult sync(@ApiParam @Valid SyncUserLdapGroupRequest req) {
    assertAdmin();
    UUID id = userManager.getId(req.getUsername(), req.getUserDomain(), UserType.LDAP).orElse(null);
    if (id == null) {
        throw new ConcordApplicationException("User not found: " + req.getUsername(), Response.Status.BAD_REQUEST);
    }
    UserInfoProvider.UserInfo info = ldapUserInfoProvider.getInfo(id, req.getUsername(), req.getUserDomain());
    if (info == null) {
        throw new ConcordApplicationException("User '" + req.getUsername() + "' with domain '" + req.getUserDomain() + "' not found in LDAP", Response.Status.BAD_REQUEST);
    }
    try {
        Set<String> groups = ldapManager.getGroups(req.getUsername(), req.getUserDomain());
        if (groups == null) {
            ldapGroupsDao.update(id, Collections.emptySet());
        } else {
            ldapGroupsDao.update(id, groups);
        }
    } catch (Exception e) {
        throw new ConcordApplicationException("Failed to update groups for user '" + req.getUsername() + "' error -> '" + e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
    }
    return new GenericOperationResult(OperationResult.UPDATED);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UserInfoProvider(com.walmartlabs.concord.server.user.UserInfoProvider) UUID(java.util.UUID) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Validate(org.sonatype.siesta.Validate) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with Validate

use of org.sonatype.siesta.Validate in project concord by walmartlabs.

the class UserResource method createOrUpdate.

/**
 * Creates a new user or updated an existing one.
 *
 * @param req user's data
 * @return
 */
@POST
@ApiOperation("Create a new user or update an existing one")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Validate
public CreateUserResponse createOrUpdate(@ApiParam @Valid CreateUserRequest req) {
    assertAdmin();
    String username = req.getUsername();
    UserType type = assertUserType(req.getType());
    UUID id = userManager.getId(username, req.getUserDomain(), type).orElse(null);
    if (id == null) {
        UserEntry e = userManager.create(username, req.getUserDomain(), req.getDisplayName(), req.getEmail(), req.getType(), req.getRoles());
        return new CreateUserResponse(e.getId(), e.getName(), OperationResult.CREATED);
    } else {
        UserEntry e = userManager.update(id, req.getDisplayName(), req.getEmail(), req.getType(), req.isDisabled(), req.getRoles()).orElse(null);
        if (e == null) {
            throw new ConcordApplicationException("User not found: " + id, Status.BAD_REQUEST);
        }
        return new CreateUserResponse(id, e.getName(), OperationResult.UPDATED);
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) Validate(org.sonatype.siesta.Validate) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Validate (org.sonatype.siesta.Validate)17 UUID (java.util.UUID)13 ApiOperation (io.swagger.annotations.ApiOperation)12 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)10 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)8 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)4 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)3 IOException (java.io.IOException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ConfigurationUtils (com.walmartlabs.concord.common.ConfigurationUtils)1 IOUtils (com.walmartlabs.concord.common.IOUtils)1 Imports (com.walmartlabs.concord.imports.Imports)1 AttachmentsRule (com.walmartlabs.concord.policyengine.AttachmentsRule)1 CheckResult (com.walmartlabs.concord.policyengine.CheckResult)1 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)1 Constants (com.walmartlabs.concord.sdk.Constants)1 HttpUtils (com.walmartlabs.concord.server.HttpUtils)1 MultipartUtils (com.walmartlabs.concord.server.MultipartUtils)1 OffsetDateTimeParam (com.walmartlabs.concord.server.OffsetDateTimeParam)1 OperationResult (com.walmartlabs.concord.server.OperationResult)1