Search in sources :

Example 1 with Selector

use of org.springframework.boot.actuate.endpoint.annotation.Selector in project cas by apereo.

the class LoggingConfigurationEndpoint method updateLoggerLevel.

/**
 * Looks up the logger in the logger factory,
 * and attempts to find the real logger instance
 * based on the underlying logging framework
 * and retrieve the logger object. Then, updates the level.
 * This functionality at this point is heavily dependant
 * on the log4j API.
 *
 * @param loggerName  the logger name
 * @param loggerLevel the logger level
 * @param additive    the additive nature of the logger
 */
@WriteOperation
@Operation(summary = "Update logger level for a logger name", parameters = { @Parameter(name = "loggerName", required = true), @Parameter(name = "loggerLevel", required = true), @Parameter(name = "additive") })
public void updateLoggerLevel(@Selector final String loggerName, final String loggerLevel, final boolean additive) {
    val loggerConfigs = getLoggerConfigurations();
    loggerConfigs.stream().filter(cfg -> cfg.getName().equals(loggerName)).forEachOrdered(cfg -> {
        cfg.setLevel(Level.getLevel(loggerLevel));
        cfg.setAdditive(additive);
    });
    this.loggerContext.updateLoggers();
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) Getter(lombok.Getter) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) SneakyThrows(lombok.SneakyThrows) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerFactory(org.slf4j.LoggerFactory) ToStringStyle(org.apache.commons.lang3.builder.ToStringStyle) Level(org.apache.logging.log4j.Level) HashMap(java.util.HashMap) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) StringUtils(org.apache.commons.lang3.StringUtils) InitializingBean(org.springframework.beans.factory.InitializingBean) HashSet(java.util.HashSet) Operation(io.swagger.v3.oas.annotations.Operation) Pair(org.apache.commons.lang3.tuple.Pair) Configurator(org.apache.logging.log4j.core.config.Configurator) Map(java.util.Map) Log4jLoggerFactory(org.apache.logging.slf4j.Log4jLoggerFactory) Resource(org.springframework.core.io.Resource) ResourceUtils(org.apereo.cas.util.ResourceUtils) Logger(org.slf4j.Logger) ResourceLoader(org.springframework.core.io.ResourceLoader) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) lombok.val(lombok.val) Set(java.util.Set) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) Slf4j(lombok.extern.slf4j.Slf4j) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) Environment(org.springframework.core.env.Environment) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) Optional(java.util.Optional) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) ILoggerFactory(org.slf4j.ILoggerFactory) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with Selector

use of org.springframework.boot.actuate.endpoint.annotation.Selector in project cas by apereo.

the class AuditLogEndpoint method getAuditLog.

/**
 * Gets Audit log for passed interval.
 *
 * @param interval - Interval subtracted from current time
 * @return the auditlog
 */
@ReadOperation
@SuppressWarnings("JavaUtilDate")
@Operation(summary = "Provide a report of the audit log using a given interval", parameters = { @Parameter(name = "interval", description = "Accepts the duration syntax, such as PT1H") })
public Set<AuditActionContext> getAuditLog(@Selector final String interval) {
    if (StringUtils.isBlank(interval)) {
        val sinceDate = LocalDate.now(ZoneId.systemDefault()).minusDays(casProperties.getAudit().getEngine().getNumberOfDaysInHistory());
        return auditTrailManager.getObject().getAuditRecordsSince(sinceDate);
    }
    val duration = Beans.newDuration(interval);
    val sinceTime = new Date(new Date().getTime() - duration.toMillis());
    val days = duration.toDays();
    val sinceDate = LocalDate.now(ZoneId.systemDefault()).minusDays(days + 1);
    return auditTrailManager.getObject().getAuditRecordsSince(sinceDate).stream().filter(a -> a.getWhenActionWasPerformed().after(sinceTime)).collect(Collectors.toSet());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) AuditTrailExecutionPlan(org.apereo.cas.audit.AuditTrailExecutionPlan) Date(java.util.Date) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) Set(java.util.Set) Beans(org.apereo.cas.configuration.support.Beans) AuditActionContext(org.apereo.inspektr.audit.AuditActionContext) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) Operation(io.swagger.v3.oas.annotations.Operation) ObjectProvider(org.springframework.beans.factory.ObjectProvider) LocalDate(java.time.LocalDate) Nullable(org.springframework.lang.Nullable) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) Date(java.util.Date) LocalDate(java.time.LocalDate) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 3 with Selector

use of org.springframework.boot.actuate.endpoint.annotation.Selector in project cas by apereo.

the class DuoSecurityUserAccountStatusEndpoint method fetchAccountStatus.

/**
 * Fetch account status map.
 *
 * @param username   the username
 * @param providerId the provider id
 * @return the map
 */
@ReadOperation(produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Fetch Duo Security user account status", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "providerId") })
public Map<?, ?> fetchAccountStatus(@Selector final String username, @Nullable final String providerId) {
    val resolver = SpringExpressionLanguageValueResolver.getInstance();
    val results = new LinkedHashMap<>();
    val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
    providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).forEach(p -> {
        val duoService = p.getDuoAuthenticationService();
        val accountStatus = duoService.getUserAccount(username);
        results.put(p.getId(), CollectionUtils.wrap("duoApiHost", resolver.resolve(duoService.getProperties().getDuoApiHost()), "name", p.getFriendlyName(), "accountStatus", accountStatus));
    });
    return results;
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationContext(org.springframework.context.ApplicationContext) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) Operation(io.swagger.v3.oas.annotations.Operation) SpringExpressionLanguageValueResolver(org.apereo.cas.util.spring.SpringExpressionLanguageValueResolver) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Nullable(org.springframework.lang.Nullable) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) LinkedHashMap(java.util.LinkedHashMap) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 4 with Selector

use of org.springframework.boot.actuate.endpoint.annotation.Selector in project spring-boot by spring-projects.

the class RequestPredicateFactory method getAllRemainingPathSegmentsParameter.

private Parameter getAllRemainingPathSegmentsParameter(Parameter[] selectorParameters) {
    Parameter trailingPathsParameter = null;
    for (Parameter selectorParameter : selectorParameters) {
        Selector selector = selectorParameter.getAnnotation(Selector.class);
        if (selector.match() == Match.ALL_REMAINING) {
            Assert.state(trailingPathsParameter == null, "@Selector annotation with Match.ALL_REMAINING must be unique");
            trailingPathsParameter = selectorParameter;
        }
    }
    if (trailingPathsParameter != null) {
        Assert.state(trailingPathsParameter == selectorParameters[selectorParameters.length - 1], "@Selector annotation with Match.ALL_REMAINING must be the last parameter");
    }
    return trailingPathsParameter;
}
Also used : Parameter(java.lang.reflect.Parameter) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector)

Example 5 with Selector

use of org.springframework.boot.actuate.endpoint.annotation.Selector in project cas by apereo.

the class U2FRegisteredDevicesEndpoint method delete.

/**
 * Delete.
 *
 * @param username the username
 * @param id       the id
 */
@DeleteOperation
@Operation(summary = "Delete registered device for username and device")
public void delete(@Selector final String username, @Selector final Long id) {
    val registeredDevices = new ArrayList<>(u2fDeviceRepository.getObject().getRegisteredDevices(username));
    registeredDevices.stream().filter(d -> d.getId() == id).forEach(u2fDeviceRepository.getObject()::deleteRegisteredDevice);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) MediaType(org.springframework.http.MediaType) Collection(java.util.Collection) lombok.val(lombok.val) U2FDeviceRegistration(org.apereo.cas.adaptors.u2f.storage.U2FDeviceRegistration) Collectors(java.util.stream.Collectors) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) ArrayList(java.util.ArrayList) Parameter(io.swagger.v3.oas.annotations.Parameter) Operation(io.swagger.v3.oas.annotations.Operation) ObjectProvider(org.springframework.beans.factory.ObjectProvider) U2FDeviceRepository(org.apereo.cas.adaptors.u2f.storage.U2FDeviceRepository) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) ArrayList(java.util.ArrayList) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

Selector (org.springframework.boot.actuate.endpoint.annotation.Selector)6 Operation (io.swagger.v3.oas.annotations.Operation)5 Parameter (io.swagger.v3.oas.annotations.Parameter)5 lombok.val (lombok.val)5 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)5 BaseCasActuatorEndpoint (org.apereo.cas.web.BaseCasActuatorEndpoint)5 Endpoint (org.springframework.boot.actuate.endpoint.annotation.Endpoint)5 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)5 StringUtils (org.apache.commons.lang3.StringUtils)4 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 MediaType (org.springframework.http.MediaType)3 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 WriteOperation (org.springframework.boot.actuate.endpoint.annotation.WriteOperation)2 Nullable (org.springframework.lang.Nullable)2 Parameter (java.lang.reflect.Parameter)1 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 Collection (java.util.Collection)1