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();
}
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());
}
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;
}
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;
}
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);
}
Aggregations