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);
}
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations