Search in sources :

Example 6 with ReadOperation

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

the class LoggingConfigurationEndpoint method configuration.

/**
 * Configuration map.
 *
 * @return the map
 */
@ReadOperation
@Operation(summary = "Get logging configuration report")
public Map<String, Object> configuration() {
    val configuredLoggers = new HashSet<>();
    getLoggerConfigurations().forEach(config -> {
        val loggerMap = new HashMap<String, Object>();
        loggerMap.put("name", StringUtils.defaultIfBlank(config.getName(), LOGGER_NAME_ROOT));
        loggerMap.put("state", config.getState());
        if (config.getPropertyList() != null) {
            loggerMap.put("properties", config.getPropertyList());
        }
        loggerMap.put("additive", config.isAdditive());
        loggerMap.put("level", config.getLevel().name());
        val appenders = new HashSet<>();
        config.getAppenders().keySet().stream().map(key -> config.getAppenders().get(key)).forEach(appender -> {
            val builder = new ToStringBuilder(this, ToStringStyle.JSON_STYLE);
            builder.append("name", appender.getName());
            builder.append("state", appender.getState());
            builder.append("layoutFormat", appender.getLayout().getContentFormat());
            builder.append("layoutContentType", appender.getLayout().getContentType());
            if (appender instanceof FileAppender) {
                builder.append(FILE_PARAM, ((FileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RandomAccessFileAppender) {
                builder.append(FILE_PARAM, ((RandomAccessFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RollingFileAppender) {
                builder.append(FILE_PARAM, ((RollingFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, ((RollingFileAppender) appender).getFilePattern());
            }
            if (appender instanceof MemoryMappedFileAppender) {
                builder.append(FILE_PARAM, ((MemoryMappedFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RollingRandomAccessFileAppender) {
                builder.append(FILE_PARAM, ((RollingRandomAccessFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, ((RollingRandomAccessFileAppender) appender).getFilePattern());
            }
            appenders.add(builder.build());
        });
        loggerMap.put("appenders", appenders);
        configuredLoggers.add(loggerMap);
    });
    val responseMap = new HashMap<String, Object>();
    responseMap.put("loggers", configuredLoggers);
    val loggers = getActiveLoggersInFactory();
    responseMap.put("activeLoggers", loggers.values());
    return responseMap;
}
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) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) HashMap(java.util.HashMap) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) HashSet(java.util.HashSet) 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 7 with ReadOperation

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

the class StatisticsEndpoint method handle.

/**
 * Gets availability times of the server.
 *
 * @return the availability
 */
@ReadOperation
@Operation(summary = "Get a report of CAS statistics")
public Map<String, Object> handle() {
    val model = new HashMap<String, Object>();
    val diff = Duration.between(this.upTimeStartDate, ZonedDateTime.now(ZoneOffset.UTC));
    model.put("upTime", diff.getSeconds());
    val runtime = Runtime.getRuntime();
    model.put("totalMemory", FileUtils.byteCountToDisplaySize(runtime.totalMemory()));
    model.put("maxMemory", FileUtils.byteCountToDisplaySize(runtime.maxMemory()));
    model.put("freeMemory", FileUtils.byteCountToDisplaySize(runtime.freeMemory()));
    val unexpiredTgts = new AtomicInteger();
    val unexpiredSts = new AtomicInteger();
    val expiredTgts = new AtomicInteger();
    val expiredSts = new AtomicInteger();
    val tickets = this.centralAuthenticationService.getObject().getTickets(ticket -> true);
    tickets.forEach(Unchecked.consumer(ticket -> {
        if (ticket instanceof ServiceTicket) {
            if (ticket.isExpired()) {
                this.centralAuthenticationService.getObject().deleteTicket(ticket.getId());
                expiredSts.incrementAndGet();
            } else {
                unexpiredSts.incrementAndGet();
            }
        } else {
            if (ticket.isExpired()) {
                this.centralAuthenticationService.getObject().deleteTicket(ticket.getId());
                expiredTgts.incrementAndGet();
            } else {
                unexpiredTgts.incrementAndGet();
            }
        }
    }));
    model.put("unexpiredTgts", unexpiredTgts);
    model.put("unexpiredSts", unexpiredSts);
    model.put("expiredTgts", expiredTgts);
    model.put("expiredSts", expiredSts);
    return model;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Unchecked(org.jooq.lambda.Unchecked) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) ZonedDateTime(java.time.ZonedDateTime) lombok.val(lombok.val) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) FileUtils(org.apache.commons.io.FileUtils) HashMap(java.util.HashMap) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Operation(io.swagger.v3.oas.annotations.Operation) ObjectProvider(org.springframework.beans.factory.ObjectProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) ZoneOffset(java.time.ZoneOffset) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 8 with ReadOperation

use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation 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 9 with ReadOperation

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

the class SpringWebflowEndpoint method getReport.

/**
 * Get SWF report.
 *
 * @param flowId  the flow id
 * @param stateId the state id
 * @return JSON representing the current state of SWF.
 */
@ReadOperation
@Operation(summary = "Get Spring webflow report using an optional flow id", parameters = { @Parameter(name = "flowId"), @Parameter(name = "stateId") })
public Map<?, ?> getReport(@Nullable final String flowId, @Nullable final String stateId) {
    val jsonMap = new LinkedHashMap<String, Object>();
    val executionPlan = applicationContext.getBean(CasWebflowExecutionPlan.BEAN_NAME, CasWebflowExecutionPlan.class);
    executionPlan.execute();
    val map = applicationContext.getBeansOfType(FlowDefinitionRegistry.class);
    map.forEach((k, value) -> Arrays.stream(value.getFlowDefinitionIds()).filter(currentId -> StringUtils.isBlank(flowId) || flowId.equalsIgnoreCase(currentId)).forEach(id -> {
        val flowDefinition = (Flow) value.getFlowDefinition(id);
        val flowDetails = new LinkedHashMap<String, Object>();
        flowDetails.put("startState", flowDefinition.getStartState().getId());
        val startActions = StreamSupport.stream(flowDefinition.getStartActionList().spliterator(), false).map(SpringWebflowEndpoint::convertActionToString).collect(Collectors.toList());
        if (!startActions.isEmpty()) {
            flowDetails.put("startActions", startActions);
        }
        val states = new LinkedHashMap<String, Map>();
        Arrays.stream(flowDefinition.getStateIds()).filter(st -> StringUtils.isBlank(stateId) || RegexUtils.find(stateId, st)).forEach(st -> {
            val stateMap = getStateDetails(flowDefinition, st);
            states.put(st, stateMap);
        });
        flowDetails.put("states", states);
        flowDetails.put("possibleOutcomes", flowDefinition.getPossibleOutcomes());
        flowDetails.put("stateCount", flowDefinition.getStateCount());
        var acts = StreamSupport.stream(flowDefinition.getEndActionList().spliterator(), false).map(SpringWebflowEndpoint::convertActionToString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            flowDetails.put("endActions", acts);
        }
        acts = StreamSupport.stream(flowDefinition.getGlobalTransitionSet().spliterator(), false).map(tr -> tr.getId() + " -> " + tr.getTargetStateId() + " @ " + tr.getExecutionCriteria().toString()).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            flowDetails.put("globalTransitions", acts);
        }
        acts = Arrays.stream(flowDefinition.getExceptionHandlerSet().toArray()).map(Object::toString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            flowDetails.put("exceptionHandlers", acts);
        }
        val vars = Arrays.stream(flowDefinition.getVariables()).map(FlowVariable::getName).collect(Collectors.joining(","));
        if (StringUtils.isNotBlank(vars)) {
            flowDetails.put("variables", vars);
        }
        jsonMap.put(id, flowDetails);
    }));
    return jsonMap;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ActionState(org.springframework.webflow.engine.ActionState) Arrays(java.util.Arrays) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) SetAction(org.springframework.webflow.action.SetAction) ExternalRedirectAction(org.springframework.webflow.action.ExternalRedirectAction) AnnotatedAction(org.springframework.webflow.execution.AnnotatedAction) ActionExecutingViewFactory(org.springframework.webflow.engine.support.ActionExecutingViewFactory) CasWebflowExecutionPlan(org.apereo.cas.web.flow.CasWebflowExecutionPlan) StringUtils(org.apache.commons.lang3.StringUtils) TransitionableState(org.springframework.webflow.engine.TransitionableState) LinkedHashMap(java.util.LinkedHashMap) Operation(io.swagger.v3.oas.annotations.Operation) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Nullable(org.springframework.lang.Nullable) StreamSupport(java.util.stream.StreamSupport) FlowDefinitionRegistry(org.springframework.webflow.definition.registry.FlowDefinitionRegistry) FlowVariable(org.springframework.webflow.engine.FlowVariable) State(org.springframework.webflow.engine.State) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) lombok.val(lombok.val) Expression(org.springframework.binding.expression.Expression) EvaluateAction(org.springframework.webflow.action.EvaluateAction) Flow(org.springframework.webflow.engine.Flow) Action(org.springframework.webflow.execution.Action) Field(java.lang.reflect.Field) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) RegexUtils(org.apereo.cas.util.RegexUtils) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) EndState(org.springframework.webflow.engine.EndState) ViewState(org.springframework.webflow.engine.ViewState) ReflectionUtils(org.springframework.util.ReflectionUtils) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) FlowVariable(org.springframework.webflow.engine.FlowVariable) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 10 with ReadOperation

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

the class CasResolveAttributesReportEndpoint method resolvePrincipalAttributes.

/**
 * Resolve principal attributes map.
 *
 * @param uid the uid
 * @return the map
 */
@ReadOperation
@Operation(summary = "Resolve principal attributes for user", parameters = { @Parameter(name = "uid", required = true) })
public Map<String, Object> resolvePrincipalAttributes(@Selector final String uid) {
    val p = defaultPrincipalResolver.getObject().resolve(new BasicIdentifiableCredential(uid));
    val map = new HashMap<String, Object>();
    map.put("uid", p.getId());
    map.put("attributes", p.getAttributes());
    return map;
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) BasicIdentifiableCredential(org.apereo.cas.authentication.credential.BasicIdentifiableCredential) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)27 Operation (io.swagger.v3.oas.annotations.Operation)14 lombok.val (lombok.val)14 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)10 Map (java.util.Map)9 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)9 BaseCasActuatorEndpoint (org.apereo.cas.web.BaseCasActuatorEndpoint)9 Endpoint (org.springframework.boot.actuate.endpoint.annotation.Endpoint)9 Parameter (io.swagger.v3.oas.annotations.Parameter)8 StringUtils (org.apache.commons.lang3.StringUtils)8 Nullable (org.springframework.lang.Nullable)6 ApplicationContext (org.springframework.context.ApplicationContext)5 Collectors (java.util.stream.Collectors)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Objects (java.util.Objects)3 StreamSupport (java.util.stream.StreamSupport)3 Slf4j (lombok.extern.slf4j.Slf4j)3 CollectionUtils (org.apereo.cas.util.CollectionUtils)3