use of org.apache.shiro.authz.annotation.RequiresPermissions in project graylog2-server by Graylog2.
the class UsersResource method listUsers.
@GET
@RequiresPermissions(RestPermissions.USERS_LIST)
@ApiOperation(value = "List all users", notes = "The permissions assigned to the users are always included.")
public UserList listUsers() {
final List<User> users = userService.loadAll();
final Collection<MongoDbSession> sessions = sessionService.loadAll();
// among all active sessions, find the last recently used for each user
//noinspection OptionalGetWithoutIsPresent
final Map<String, Optional<MongoDbSession>> lastSessionForUser = sessions.stream().filter(s -> s.getUsernameAttribute().isPresent()).collect(groupingBy(s -> s.getUsernameAttribute().get(), maxBy(Comparator.comparing(MongoDbSession::getLastAccessTime))));
final List<UserSummary> resultUsers = Lists.newArrayListWithCapacity(users.size() + 1);
final User adminUser = userService.getAdminUser();
resultUsers.add(toUserResponse(adminUser, lastSessionForUser.getOrDefault(adminUser.getName(), Optional.empty())));
for (User user : users) {
resultUsers.add(toUserResponse(user, lastSessionForUser.getOrDefault(user.getName(), Optional.empty())));
}
return UserList.create(resultUsers);
}
use of org.apache.shiro.authz.annotation.RequiresPermissions in project graylog2-server by Graylog2.
the class DeflectorResource method cycle.
@POST
@Timed
@ApiOperation(value = "Cycle deflector to new/next index in index set")
@RequiresPermissions(RestPermissions.DEFLECTOR_CYCLE)
@Path("/{indexSetId}/cycle")
@RestrictToMaster
@AuditEvent(type = AuditEventTypes.ES_WRITE_INDEX_UPDATE_JOB_START)
public void cycle(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
checkCycle(indexSet);
final String msg = "Cycling deflector for index set <" + indexSetId + ">. Reason: REST request.";
LOG.info(msg);
activityWriter.write(new Activity(msg, DeflectorResource.class));
indexSet.cycle();
}
use of org.apache.shiro.authz.annotation.RequiresPermissions in project OpenAttestation by OpenAttestation.
the class BulkHostTrust method getTrustSaml.
/**
* REST Web Service Example: GET /hosts/trust?hosts=host_name_1
* ,host_name_2,host_name_3&force_verify=true
*
* @param hosts
* @param forceVerify
* @param timeout
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_XML })
@Path("/trust/saml")
//@RolesAllowed({"Attestation", "Report"})
@RequiresPermissions("host_attestations:create,retrieve")
public String getTrustSaml(@QueryParam("hosts") String hosts, @QueryParam("force_verify") @DefaultValue("false") Boolean forceVerify, // @QueryParam("threads") @DefaultValue("5") Integer threads, // bug #503 max threads now global and configured in properties file
@QueryParam("timeout") @DefaultValue("600") Integer timeout) {
ValidationUtil.validate(hosts);
Integer myTimeOut = timeout;
// Modified the default time out back to 600 seconds as we are seeing time out issues. 30 seconds short for VMware hosts.
if (timeout == 600) {
log.info("getTrustSaml called with default timeout, checking config");
myTimeOut = ASConfig.getConfiguration().getInt("com.intel.mountwilson.as.attestation.hostTimeout", 600);
log.debug("getTrustSaml config returned back" + myTimeOut);
}
if (hosts == null || hosts.length() == 0) {
throw new ASException(com.intel.mtwilson.datatypes.ErrorCode.AS_MISSING_INPUT, "hosts");
}
Set<String> hostSet = new HashSet<String>();
// bug #783 make sure that we only pass to the next layer hostnames that are likely to be valid
for (String host : Arrays.asList(hosts.split(","))) {
log.debug("Host: '{}'", host);
if (!(host.trim().isEmpty() || host.trim() == null)) {
hostSet.add(host.trim());
}
}
BulkHostTrustBO bulkHostTrustBO = new BulkHostTrustBO(/*threads, */
myTimeOut);
String result = bulkHostTrustBO.getBulkTrustSaml(hostSet, forceVerify);
return result;
}
use of org.apache.shiro.authz.annotation.RequiresPermissions in project graylog2-server by Graylog2.
the class ClusterSystemResource method threadDump.
@GET
@Timed
@ApiOperation(value = "Get a thread dump of the given node")
@RequiresPermissions(RestPermissions.THREADS_DUMP)
@Path("{nodeId}/threaddump")
public SystemThreadDumpResponse threadDump(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
final Node targetNode = nodeService.byNodeId(nodeId);
final RemoteSystemResource remoteSystemResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemResource.class);
final Response<SystemThreadDumpResponse> response = remoteSystemResource.threadDump().execute();
if (response.isSuccessful()) {
return response.body();
} else {
LOG.warn("Unable to get thread dump on node {}: {}", nodeId, response.message());
throw new WebApplicationException(response.message(), BAD_GATEWAY);
}
}
use of org.apache.shiro.authz.annotation.RequiresPermissions in project graylog2-server by Graylog2.
the class SavedSearchesResource method create.
@POST
@Timed
@ApiOperation(value = "Create a new saved search")
@RequiresPermissions(RestPermissions.SAVEDSEARCHES_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponse(code = 400, message = "Validation error")
@AuditEvent(type = AuditEventTypes.SAVED_SEARCH_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) @Valid CreateSavedSearchRequest cr) throws ValidationException {
if (!isTitleTaken("", cr.title())) {
final String msg = "Cannot save search " + cr.title() + ". Title is already taken.";
throw new BadRequestException(msg);
}
final SavedSearch search = savedSearchService.create(cr.title(), cr.query(), getCurrentUser().getName(), Tools.nowUTC());
final String id = savedSearchService.save(search);
final URI searchUri = getUriBuilderToSelf().path(SavedSearchesResource.class).path("{searchId}").build(id);
return Response.created(searchUri).entity(ImmutableMap.of("search_id", id)).build();
}
Aggregations