Search in sources :

Example 1 with Timed

use of com.codahale.metrics.annotation.Timed in project cas by apereo.

the class AbstractAuthenticationManager method authenticate.

@Override
@Audit(action = "AUTHENTICATION", actionResolverName = "AUTHENTICATION_RESOLVER", resourceResolverName = "AUTHENTICATION_RESOURCE_RESOLVER")
@Timed(name = "AUTHENTICATE_TIMER")
@Metered(name = "AUTHENTICATE_METER")
@Counted(name = "AUTHENTICATE_COUNT", monotonic = true)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {
    AuthenticationCredentialsLocalBinder.bindCurrent(transaction.getCredentials());
    final AuthenticationBuilder builder = authenticateInternal(transaction);
    authenticationEventExecutionPlan.getAuthenticationPostProcessors().forEach(p -> {
        LOGGER.info("Invoking authentication post processor [{}]", p);
        p.process(transaction, builder);
    });
    final Authentication authentication = builder.build();
    final Principal principal = authentication.getPrincipal();
    if (principal instanceof NullPrincipal) {
        throw new UnresolvedPrincipalException(authentication);
    }
    addAuthenticationMethodAttribute(builder, authentication);
    LOGGER.info("Authenticated principal [{}] with attributes [{}] via credentials [{}].", principal.getId(), principal.getAttributes(), transaction.getCredentials());
    populateAuthenticationMetadataAttributes(builder, transaction.getCredentials());
    final Authentication a = builder.build();
    AuthenticationCredentialsLocalBinder.bindCurrent(a);
    return a;
}
Also used : NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) UnresolvedPrincipalException(org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException) NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) Principal(org.apereo.cas.authentication.principal.Principal) Audit(org.apereo.inspektr.audit.annotation.Audit) Counted(com.codahale.metrics.annotation.Counted) Metered(com.codahale.metrics.annotation.Metered) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class KeywordSearchResource method searchKeyword.

@GET
@Timed
@ApiOperation(value = "Message search with keyword as timerange.", notes = "Search for messages in a timerange defined by a keyword like \"yesterday\" or \"2 weeks ago to wednesday\".")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid keyword provided.") })
public SearchResponse searchKeyword(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "keyword", value = "Range keyword", required = true) @QueryParam("keyword") @NotEmpty String keyword, @ApiParam(name = "limit", value = "Maximum number of messages to return.", required = false) @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset", required = false) @QueryParam("offset") int offset, @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return", required = false) @QueryParam("fields") String fields, @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)", required = false) @QueryParam("sort") String sort, @ApiParam(name = "decorate", value = "Run decorators on search result", required = false) @QueryParam("decorate") @DefaultValue("true") boolean decorate) {
    checkSearchPermission(filter, RestPermissions.SEARCHES_KEYWORD);
    final List<String> fieldList = parseOptionalFields(fields);
    final Sorting sorting = buildSorting(sort);
    final TimeRange timeRange = buildKeywordTimeRange(keyword);
    final SearchesConfig searchesConfig = SearchesConfig.builder().query(query).filter(filter).fields(fieldList).range(timeRange).limit(limit).offset(offset).sorting(sorting).build();
    final Optional<String> streamId = Searches.extractStreamId(filter);
    try {
        return buildSearchResponse(searches.search(searchesConfig), timeRange, decorate, streamId);
    } catch (SearchPhaseExecutionException e) {
        throw createRequestExceptionForParseFailure(query, e);
    }
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) SearchesConfig(org.graylog2.indexer.searches.SearchesConfig) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) Sorting(org.graylog2.indexer.searches.Sorting) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class StreamResource method create.

@POST
@Timed
@ApiOperation(value = "Create a stream")
@RequiresPermissions(RestPermissions.STREAMS_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) final CreateStreamRequest cr) throws ValidationException {
    // Create stream.
    final Stream stream = streamService.create(cr, getCurrentUser().getName());
    stream.setDisabled(true);
    if (!stream.getIndexSet().getConfig().isWritable()) {
        throw new BadRequestException("Assigned index set must be writable!");
    }
    final String id = streamService.save(stream);
    final List<CreateStreamRuleRequest> rules = firstNonNull(cr.rules(), Collections.<CreateStreamRuleRequest>emptyList());
    for (CreateStreamRuleRequest request : rules) {
        StreamRule streamRule = streamRuleService.create(id, request);
        streamRuleService.save(streamRule);
    }
    clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
    final Map<String, String> result = ImmutableMap.of("stream_id", id);
    final URI streamUri = getUriBuilderToSelf().path(StreamResource.class).path("{streamId}").build(id);
    return Response.created(streamUri).entity(result).build();
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule) CreateStreamRuleRequest(org.graylog2.rest.resources.streams.rules.requests.CreateStreamRuleRequest) BadRequestException(javax.ws.rs.BadRequestException) Stream(org.graylog2.plugin.streams.Stream) URI(java.net.URI) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 4 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class StreamResource method cloneStream.

@POST
@Path("/{streamId}/clone")
@Timed
@ApiOperation(value = "Clone a stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid or missing Stream id.") })
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_CREATE)
public Response cloneStream(@ApiParam(name = "streamId", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CloneStreamRequest cr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.STREAMS_CREATE);
    checkPermission(RestPermissions.STREAMS_READ, streamId);
    checkNotDefaultStream(streamId, "The default stream cannot be cloned.");
    final Stream sourceStream = streamService.load(streamId);
    final String creatorUser = getCurrentUser().getName();
    // Create stream.
    final Map<String, Object> streamData = Maps.newHashMap();
    streamData.put(StreamImpl.FIELD_TITLE, cr.title());
    streamData.put(StreamImpl.FIELD_DESCRIPTION, cr.description());
    streamData.put(StreamImpl.FIELD_CREATOR_USER_ID, creatorUser);
    streamData.put(StreamImpl.FIELD_CREATED_AT, Tools.nowUTC());
    streamData.put(StreamImpl.FIELD_MATCHING_TYPE, sourceStream.getMatchingType().toString());
    streamData.put(StreamImpl.FIELD_REMOVE_MATCHES_FROM_DEFAULT_STREAM, cr.removeMatchesFromDefaultStream());
    streamData.put(StreamImpl.FIELD_INDEX_SET_ID, cr.indexSetId());
    final Stream stream = streamService.create(streamData);
    streamService.pause(stream);
    final String id = streamService.save(stream);
    final List<StreamRule> sourceStreamRules = streamRuleService.loadForStream(sourceStream);
    for (StreamRule streamRule : sourceStreamRules) {
        final Map<String, Object> streamRuleData = Maps.newHashMapWithExpectedSize(6);
        streamRuleData.put(StreamRuleImpl.FIELD_TYPE, streamRule.getType().toInteger());
        streamRuleData.put(StreamRuleImpl.FIELD_FIELD, streamRule.getField());
        streamRuleData.put(StreamRuleImpl.FIELD_VALUE, streamRule.getValue());
        streamRuleData.put(StreamRuleImpl.FIELD_INVERTED, streamRule.getInverted());
        streamRuleData.put(StreamRuleImpl.FIELD_STREAM_ID, new ObjectId(id));
        streamRuleData.put(StreamRuleImpl.FIELD_DESCRIPTION, streamRule.getDescription());
        final StreamRule newStreamRule = streamRuleService.create(streamRuleData);
        streamRuleService.save(newStreamRule);
    }
    for (AlertCondition alertCondition : streamService.getAlertConditions(sourceStream)) {
        try {
            final AlertCondition clonedAlertCondition = alertService.fromRequest(CreateConditionRequest.create(alertCondition.getType(), alertCondition.getTitle(), alertCondition.getParameters()), stream, creatorUser);
            streamService.addAlertCondition(stream, clonedAlertCondition);
        } catch (ConfigurationException e) {
            LOG.warn("Unable to clone alert condition <" + alertCondition + "> - skipping: ", e);
        }
    }
    for (AlarmCallbackConfiguration alarmCallbackConfiguration : alarmCallbackConfigurationService.getForStream(sourceStream)) {
        final CreateAlarmCallbackRequest request = CreateAlarmCallbackRequest.create(alarmCallbackConfiguration);
        final AlarmCallbackConfiguration alarmCallback = alarmCallbackConfigurationService.create(stream.getId(), request, getCurrentUser().getName());
        alarmCallbackConfigurationService.save(alarmCallback);
    }
    for (Output output : sourceStream.getOutputs()) {
        streamService.addOutput(stream, output);
    }
    clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
    final Map<String, String> result = ImmutableMap.of("stream_id", id);
    final URI streamUri = getUriBuilderToSelf().path(StreamResource.class).path("{streamId}").build(id);
    return Response.created(streamUri).entity(result).build();
}
Also used : ObjectId(org.bson.types.ObjectId) StreamRule(org.graylog2.plugin.streams.StreamRule) URI(java.net.URI) CreateAlarmCallbackRequest(org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) Output(org.graylog2.plugin.streams.Output) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Stream(org.graylog2.plugin.streams.Stream) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class MessageResource method analyze.

@GET
@Path("/{index}/analyze")
@Timed
@ApiOperation(value = "Analyze a message string", notes = "Returns what tokens/terms a message string (message or full_message) is split to.")
@RequiresPermissions(RestPermissions.MESSAGES_ANALYZE)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Specified index does not exist.") })
public MessageTokens analyze(@ApiParam(name = "index", value = "The index the message containing the string is stored in.", required = true) @PathParam("index") String index, @ApiParam(name = "analyzer", value = "The analyzer to use.") @QueryParam("analyzer") @Nullable String analyzer, @ApiParam(name = "string", value = "The string to analyze.", required = true) @QueryParam("string") @NotEmpty String string) {
    final String indexAnalyzer = indexSetRegistry.getForIndex(index).map(indexSet -> indexSet.getConfig().indexAnalyzer()).orElse("standard");
    final String messageAnalyzer = analyzer == null ? indexAnalyzer : analyzer;
    try {
        return MessageTokens.create(messages.analyze(string, index, messageAnalyzer));
    } catch (IndexNotFoundException e) {
        final String message = "Index " + index + " does not exist.";
        LOG.error(message, e);
        throw new NotFoundException(message);
    }
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) PathParam(javax.ws.rs.PathParam) UUID(com.eaio.uuid.UUID) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) MessageTokens(org.graylog2.rest.models.messages.responses.MessageTokens) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ApiResponses(io.swagger.annotations.ApiResponses) CodecFactory(org.graylog2.inputs.codecs.CodecFactory) MessageParseRequest(org.graylog2.rest.models.messages.requests.MessageParseRequest) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ResolvableInetSocketAddress(org.graylog2.plugin.ResolvableInetSocketAddress) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ResultMessage(org.graylog2.indexer.results.ResultMessage) Consumes(javax.ws.rs.Consumes) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Objects.requireNonNull(java.util.Objects.requireNonNull) RawMessage(org.graylog2.plugin.journal.RawMessage) Messages(org.graylog2.indexer.messages.Messages) BadRequestException(javax.ws.rs.BadRequestException) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Nullable(javax.annotation.Nullable) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ForbiddenException(javax.ws.rs.ForbiddenException) RestResource(org.graylog2.shared.rest.resources.RestResource) InetSocketAddress(java.net.InetSocketAddress) NotFoundException(javax.ws.rs.NotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Timed(com.codahale.metrics.annotation.Timed) Codec(org.graylog2.plugin.inputs.codecs.Codec) ApiResponse(io.swagger.annotations.ApiResponse) RestPermissions(org.graylog2.shared.security.RestPermissions) NotEmpty(org.hibernate.validator.constraints.NotEmpty) InetAddresses(com.google.common.net.InetAddresses) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) Message(org.graylog2.plugin.Message) DocumentNotFoundException(org.graylog2.indexer.messages.DocumentNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) DocumentNotFoundException(org.graylog2.indexer.messages.DocumentNotFoundException) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)1042 Path (javax.ws.rs.Path)386 ApiOperation (io.swagger.annotations.ApiOperation)316 ApiResponses (io.swagger.annotations.ApiResponses)218 GET (javax.ws.rs.GET)203 POST (javax.ws.rs.POST)167 URI (java.net.URI)157 Produces (javax.ws.rs.Produces)148 Counted (com.codahale.metrics.annotation.Counted)122 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)105 AuditEvent (org.graylog2.audit.jersey.AuditEvent)96 Consumes (javax.ws.rs.Consumes)91 PUT (javax.ws.rs.PUT)91 DELETE (javax.ws.rs.DELETE)78 Response (javax.ws.rs.core.Response)73 NotFoundException (javax.ws.rs.NotFoundException)68 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)66 ResponseEntity (org.springframework.http.ResponseEntity)66 HttpHeaders (org.springframework.http.HttpHeaders)54 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)53