Search in sources :

Example 21 with UserPrincipal

use of com.walmartlabs.concord.server.security.UserPrincipal in project concord by walmartlabs.

the class ProcessResource method fork.

/**
 * Starts a new child process by forking the start of the specified parent process.
 *
 * @param parentInstanceId
 * @param req
 * @param sync
 * @return
 */
@POST
@ApiOperation("Fork a process")
@javax.ws.rs.Path("/{id}/fork")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public StartProcessResponse fork(@ApiParam @PathParam("id") UUID parentInstanceId, @ApiParam Map<String, Object> req, @ApiParam @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @ApiParam @QueryParam("out") String[] out) {
    if (sync) {
        throw syncIsForbidden();
    }
    ProcessEntry parent = processQueueManager.get(PartialProcessKey.from(parentInstanceId));
    if (parent == null) {
        throw new ValidationErrorsException("Unknown parent instance ID: " + parentInstanceId);
    }
    PartialProcessKey processKey = PartialProcessKey.from(UUID.randomUUID());
    ProcessKey parentProcessKey = new ProcessKey(parent.instanceId(), parent.createdAt());
    UUID projectId = parent.projectId();
    UserPrincipal userPrincipal = UserPrincipal.assertCurrent();
    Set<String> handlers = parent.handlers();
    Imports imports = queueDao.getImports(parentProcessKey);
    Payload payload;
    try {
        payload = payloadManager.createFork(processKey, parentProcessKey, ProcessKind.DEFAULT, userPrincipal.getId(), userPrincipal.getUsername(), projectId, req, out, handlers, imports);
    } catch (IOException e) {
        log.error("fork ['{}', '{}'] -> error creating a payload: {}", processKey, parentProcessKey, e);
        throw new ConcordApplicationException("Error creating a payload", e);
    }
    return toResponse(processManager.startFork(payload));
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) Imports(com.walmartlabs.concord.imports.Imports) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 22 with UserPrincipal

use of com.walmartlabs.concord.server.security.UserPrincipal in project concord by walmartlabs.

the class ProcessResource method start.

/**
 * Starts a new process instance using the specified entry point and payload archive.
 *
 * @param entryPoint
 * @param in
 * @param parentInstanceId
 * @param sync
 * @return
 * @deprecated use {@link #start(MultipartInput, UUID, boolean, String[], HttpServletRequest)}
 */
@POST
@ApiOperation(value = "Start a new process using the specified entry point and payload archive", hidden = true)
@javax.ws.rs.Path("/{entryPoint}")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer(suffix = "_octetstream_and_entrypoint")
@Deprecated
public StartProcessResponse start(@PathParam("entryPoint") String entryPoint, InputStream in, @QueryParam("parentId") UUID parentInstanceId, @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @QueryParam("out") String[] out) {
    if (sync) {
        throw syncIsForbidden();
    }
    // allow empty POST requests
    if (isEmpty(in)) {
        return start(entryPoint, parentInstanceId, sync, out);
    }
    assertPartialKey(parentInstanceId);
    PartialProcessKey processKey = PartialProcessKey.from(UUID.randomUUID());
    UUID orgId = OrganizationManager.DEFAULT_ORG_ID;
    EntryPoint ep = payloadManager.parseEntryPoint(processKey, orgId, entryPoint);
    UserPrincipal userPrincipal = UserPrincipal.assertCurrent();
    Payload payload;
    try {
        payload = payloadManager.createPayload(processKey, parentInstanceId, userPrincipal.getId(), userPrincipal.getUsername(), ep, in, out);
    } catch (IOException e) {
        log.error("start ['{}'] -> error creating a payload: {}", entryPoint, e);
        throw new ConcordApplicationException("Error creating a payload", e);
    }
    return toResponse(processManager.start(payload));
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) EntryPoint(com.walmartlabs.concord.server.process.PayloadManager.EntryPoint) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 23 with UserPrincipal

use of com.walmartlabs.concord.server.security.UserPrincipal in project concord by walmartlabs.

the class ProcessResource method start.

/**
 * Starts a new process instance.
 *
 * @param in
 * @param parentInstanceId
 * @param sync
 * @return
 * @deprecated use {@link #start(MultipartInput, UUID, boolean, String[], HttpServletRequest)}
 */
@POST
@ApiOperation(value = "Start a new process instance using the supplied payload archive", hidden = true)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer(suffix = "_octetstream")
@Deprecated
public StartProcessResponse start(InputStream in, @QueryParam("parentId") UUID parentInstanceId, @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @QueryParam("out") String[] out) {
    if (sync) {
        throw syncIsForbidden();
    }
    assertPartialKey(parentInstanceId);
    PartialProcessKey processKey = PartialProcessKey.from(UUID.randomUUID());
    UserPrincipal userPrincipal = UserPrincipal.assertCurrent();
    Payload payload;
    try {
        payload = payloadManager.createPayload(processKey, parentInstanceId, userPrincipal.getId(), userPrincipal.getUsername(), in, out);
    } catch (IOException e) {
        log.error("start -> error creating a payload: {}", e.getMessage());
        throw new ConcordApplicationException("Error creating a payload", e);
    }
    return toResponse(processManager.start(payload));
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 24 with UserPrincipal

use of com.walmartlabs.concord.server.security.UserPrincipal in project concord by walmartlabs.

the class ProcessSecurityContext method runAs.

public <T> T runAs(UUID userID, Callable<T> c) throws Exception {
    UserEntry u = userManager.get(userID).orElse(null);
    if (u == null) {
        throw new UnauthorizedException("User '" + userID + "'not found");
    }
    try {
        ThreadContext.bind(securityManager);
        SimplePrincipalCollection principals = new SimplePrincipalCollection();
        principals.add(new UserPrincipal(InternalRealm.REALM_NAME, u), InternalRealm.REALM_NAME);
        Subject subject = new Subject.Builder().sessionCreationEnabled(false).authenticated(true).principals(principals).buildSubject();
        ThreadContext.bind(subject);
        return c.call();
    } finally {
        ThreadContext.unbindSubject();
        ThreadContext.unbindSecurityManager();
    }
}
Also used : CacheBuilder(com.google.common.cache.CacheBuilder) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) UserEntry(com.walmartlabs.concord.server.user.UserEntry) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) Subject(org.apache.shiro.subject.Subject)

Example 25 with UserPrincipal

use of com.walmartlabs.concord.server.security.UserPrincipal in project concord by walmartlabs.

the class PayloadManager method createPayload.

@WithTimer
public Payload createPayload(MultipartInput input, HttpServletRequest request) throws IOException {
    PartialProcessKey processKey = PartialProcessKey.create();
    UUID parentInstanceId = MultipartUtils.getUuid(input, Constants.Multipart.PARENT_INSTANCE_ID);
    UUID orgId = getOrg(input);
    UUID projectId = getProject(input, orgId);
    UUID repoId = getRepo(input, projectId);
    if (repoId != null && projectId == null) {
        // allow starting processes by specifying repository IDs without project IDs or names
        projectId = repositoryDao.getProjectId(repoId);
    }
    String entryPoint = MultipartUtils.getString(input, Constants.Multipart.ENTRY_POINT);
    UserPrincipal initiator = UserPrincipal.assertCurrent();
    String[] out = getOutExpressions(input);
    Map<String, Object> meta = MultipartUtils.getMap(input, Constants.Multipart.META);
    if (meta == null) {
        meta = Collections.emptyMap();
    }
    return PayloadBuilder.start(processKey).parentInstanceId(parentInstanceId).with(input).organization(orgId).project(projectId).repository(repoId).entryPoint(entryPoint).outExpressions(out).initiator(initiator.getId(), initiator.getUsername()).meta(meta).request(request).build();
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) UUID(java.util.UUID) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Aggregations

UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)37 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)15 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)14 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)9 UserEntry (com.walmartlabs.concord.server.user.UserEntry)8 UUID (java.util.UUID)8 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)7 ApiOperation (io.swagger.annotations.ApiOperation)6 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)3 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)3 ProcessEntry (com.walmartlabs.concord.server.process.ProcessEntry)3 SessionKeyPrincipal (com.walmartlabs.concord.server.security.sessionkey.SessionKeyPrincipal)3 SimpleAccount (org.apache.shiro.authc.SimpleAccount)3 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)3 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)2 LdapPrincipal (com.walmartlabs.concord.server.security.ldap.LdapPrincipal)2 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)2 Subject (org.apache.shiro.subject.Subject)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 Imports (com.walmartlabs.concord.imports.Imports)1