use of javax.ws.rs.core.SecurityContext in project syndesis by syndesisio.
the class IntegrationHandler method putDeployment.
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/deployments")
public IntegrationDeployment putDeployment(@Context SecurityContext sec, @NotNull @PathParam("id") @ApiParam(required = true) String id) {
Integration integration = getIntegration(id);
int nextDeploymentVersion = 1;
// Update previous deployments targetState=Undeployed and make sure nextDeploymentVersion is larger than all previous ones.
Set<String> deploymentIds = getDataManager().fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", id);
if (deploymentIds != null && !deploymentIds.isEmpty()) {
Stream<IntegrationDeployment> deployments = deploymentIds.stream().map(i -> getDataManager().fetch(IntegrationDeployment.class, i)).filter(r -> r != null);
for (IntegrationDeployment d : deployments.toArray(IntegrationDeployment[]::new)) {
nextDeploymentVersion = Math.max(nextDeploymentVersion, d.getVersion() + 1);
getDataManager().update(d.withTargetState(IntegrationDeploymentState.Unpublished));
}
}
IntegrationDeployment deployment = new IntegrationDeployment.Builder().id(IntegrationDeployment.compositeId(id, nextDeploymentVersion)).spec(integration).version(nextDeploymentVersion).userId(sec.getUserPrincipal().getName()).build();
deployment = getDataManager().create(deployment);
return deployment;
}
use of javax.ws.rs.core.SecurityContext in project streamline by hortonworks.
the class SecurityCatalogResource method filter.
private Collection<AclEntry> filter(Collection<AclEntry> aclEntries, SecurityContext securityContext) {
User currentUser = getCurrentUser(securityContext);
Set<Role> currentUserRoles = catalogService.getAllUserRoles(currentUser);
boolean isSecurityAdmin = SecurityUtil.hasRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
return aclEntries.stream().filter(aclEntry -> isSecurityAdmin || matches(aclEntry, currentUser, currentUserRoles)).collect(Collectors.toSet());
}
use of javax.ws.rs.core.SecurityContext in project streamline by hortonworks.
the class TopologyTestRunResource method getEventsOfTestRunTopologyHistory.
private Response getEventsOfTestRunTopologyHistory(Long topologyId, Long historyId, String componentName, SecurityContext securityContext) throws IOException {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, READ);
File eventLogFile = getEventLogFile(topologyId, historyId);
Stream<EventInformation> eventsStream = eventLogFileReader.loadEventLogFileAsStream(eventLogFile);
if (!StringUtils.isEmpty(componentName)) {
eventsStream = eventsStream.filter(event -> {
String eventComponentName = event.getComponentName();
return eventComponentName != null && eventComponentName.equals(componentName);
});
}
return WSUtils.respondEntities(eventsStream.collect(toList()), OK);
}
use of javax.ws.rs.core.SecurityContext in project streamline by hortonworks.
the class NamespaceCatalogResource method setServicesToClusterInNamespace.
@POST
@Path("/namespaces/{id}/mapping/bulk")
@Timed
public Response setServicesToClusterInNamespace(@PathParam("id") Long namespaceId, List<NamespaceServiceClusterMap> mappings, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId(namespaceId.toString());
}
String streamingEngine = namespace.getStreamingEngine();
String timeSeriesDB = namespace.getTimeSeriesDB();
Collection<NamespaceServiceClusterMap> existing = environmentService.listServiceClusterMapping(namespaceId);
Optional<NamespaceServiceClusterMap> existingStreamingEngine = existing.stream().filter(m -> m.getServiceName().equals(streamingEngine)).findFirst();
// indicates that mapping of streaming engine has been changed or removed
if (existingStreamingEngine.isPresent() && !mappings.contains(existingStreamingEngine.get())) {
assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
}
// we're OK to just check with new mappings since we will remove existing mappings
assertServiceIsUnique(mappings, streamingEngine);
assertServiceIsUnique(mappings, timeSeriesDB);
// remove any existing mapping for (namespace, service name) pairs
Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId);
if (existingMappings != null) {
existingMappings.forEach(m -> environmentService.removeServiceClusterMapping(m.getNamespaceId(), m.getServiceName(), m.getClusterId()));
}
List<NamespaceServiceClusterMap> newMappings = mappings.stream().map(environmentService::addOrUpdateServiceClusterMapping).collect(toList());
return WSUtils.respondEntities(newMappings, CREATED);
}
use of javax.ws.rs.core.SecurityContext in project streamline by hortonworks.
the class NamespaceCatalogResource method unmapAllServicesToClusterInNamespace.
@DELETE
@Path("/namespaces/{id}/mapping")
@Timed
public Response unmapAllServicesToClusterInNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId(namespaceId.toString());
}
String streamingEngine = namespace.getStreamingEngine();
Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId);
boolean containsStreamingEngine = mappings.stream().anyMatch(m -> m.getServiceName().equals(streamingEngine));
if (containsStreamingEngine) {
assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
}
List<NamespaceServiceClusterMap> removed = mappings.stream().map((x) -> environmentService.removeServiceClusterMapping(x.getNamespaceId(), x.getServiceName(), x.getClusterId())).collect(toList());
return WSUtils.respondEntities(removed, OK);
}
Aggregations