use of io.swagger.v3.oas.models.Operation 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;
}
use of io.swagger.v3.oas.models.Operation 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 io.swagger.v3.oas.models.Operation in project cas by apereo.
the class CasReleaseAttributesReportEndpoint method releaseAttributes.
/**
* Method that accepts a JSON body through a POST method to receive user credentials and only returns a
* map of attributes released for the authenticated user.
*
* @param username - the username
* @param password - the password
* @param service - the service id
* @return - the map
*/
@WriteOperation
@Operation(summary = "Get collection of released attributes for the user and application", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "password", required = true), @Parameter(name = "service", required = true) })
public Map<String, Object> releaseAttributes(final String username, final String password, final String service) {
val map = releasePrincipalAttributes(username, password, service);
val assertion = (ImmutableAssertion) map.get("assertion");
return Map.of("uid", username, "attributes", assertion.getPrimaryAuthentication().getPrincipal().getAttributes());
}
use of io.swagger.v3.oas.models.Operation in project cas by apereo.
the class SingleSignOnSessionStatusEndpoint method ssoStatus.
/**
* Sso status response entity.
*
* @param tgc the tgc
* @param request the request
* @return the response entity
*/
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get current status of single sign-on", parameters = { @Parameter(name = "tgc", required = false), @Parameter(name = "request", required = false) })
public ResponseEntity<Map<?, ?>> ssoStatus(@RequestParam(name = "tgc", required = false, defaultValue = StringUtils.EMPTY) final String tgc, final HttpServletRequest request) {
val tgtId = StringUtils.isNotBlank(tgc) ? ticketGrantingTicketCookieGenerator.getCasCookieValueManager().obtainCookieValue(tgc, request) : ticketGrantingTicketCookieGenerator.retrieveCookieValue(request);
if (StringUtils.isBlank(tgtId)) {
return ResponseEntity.badRequest().build();
}
val auth = this.ticketRegistrySupport.getAuthenticationFrom(tgtId);
if (auth == null) {
return ResponseEntity.badRequest().build();
}
val ticketState = this.ticketRegistrySupport.getTicket(tgtId);
val body = CollectionUtils.wrap("principal", auth.getPrincipal().getId(), "authenticationDate", auth.getAuthenticationDate(), "ticketGrantingTicketCreationTime", ticketState.getCreationTime(), "ticketGrantingTicketPreviousTimeUsed", ticketState.getPreviousTimeUsed(), "ticketGrantingTicketLastTimeUsed", ticketState.getLastTimeUsed());
return ResponseEntity.ok(body);
}
use of io.swagger.v3.oas.models.Operation 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;
}
Aggregations