Search in sources :

Example 31 with Operation

use of io.swagger.v3.oas.models.Operation in project cas by apereo.

the class SingleSignOnSessionsEndpoint method destroySsoSessions.

/**
 * Destroy sso sessions map.
 *
 * @param type     the type
 * @param username the username
 * @param from     the from
 * @param count    the count
 * @param request  the request
 * @param response the response
 * @return the map
 */
@Operation(summary = "Remove single sign-on session for type and user")
@DeleteMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, Object> destroySsoSessions(@Nullable @RequestParam(name = "type", required = false) final String type, @Nullable @RequestParam(name = "username", required = false) final String username, @RequestParam(name = "from", required = false, defaultValue = "0") final long from, @RequestParam(name = "count", required = false, defaultValue = "1000") final long count, final HttpServletRequest request, final HttpServletResponse response) {
    if (StringUtils.isBlank(username) && StringUtils.isBlank(type)) {
        return Map.of(STATUS, HttpServletResponse.SC_BAD_REQUEST);
    }
    if (StringUtils.isNotBlank(username)) {
        val sessionsMap = new HashMap<String, Object>(1);
        val tickets = centralAuthenticationService.getObject().getTickets(ticket -> ticket instanceof TicketGrantingTicket && ((TicketGrantingTicket) ticket).getAuthentication().getPrincipal().getId().equalsIgnoreCase(username));
        tickets.forEach(ticket -> sessionsMap.put(ticket.getId(), destroySsoSession(ticket.getId(), request, response)));
        return sessionsMap;
    }
    val sessionsMap = new HashMap<String, Object>();
    val option = SsoSessionReportOptions.valueOf(type);
    val collection = getActiveSsoSessions(option, username, from, count);
    collection.stream().map(sso -> sso.get(SsoSessionAttributeKeys.TICKET_GRANTING_TICKET.getAttributeKey()).toString()).forEach(ticketGrantingTicket -> destroySsoSession(ticketGrantingTicket, request, response));
    sessionsMap.put(STATUS, HttpServletResponse.SC_OK);
    return sessionsMap;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Getter(lombok.Getter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) LoggingUtils(org.apereo.cas.util.LoggingUtils) Operation(io.swagger.v3.oas.annotations.Operation) ObjectProvider(org.springframework.beans.factory.ObjectProvider) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) ToString(lombok.ToString) GetMapping(org.springframework.web.bind.annotation.GetMapping) Nullable(org.springframework.lang.Nullable) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) SingleLogoutRequestExecutor(org.apereo.cas.logout.slo.SingleLogoutRequestExecutor) DateTimeUtils(org.apereo.cas.util.DateTimeUtils) MediaType(org.springframework.http.MediaType) Collection(java.util.Collection) lombok.val(lombok.val) HttpServletResponse(javax.servlet.http.HttpServletResponse) Collectors(java.util.stream.Collectors) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) ISOStandardDateFormat(org.apereo.cas.util.ISOStandardDateFormat) RestControllerEndpoint(org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint) AtomicLong(java.util.concurrent.atomic.AtomicLong) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Optional(java.util.Optional) CoreAuthenticationUtils(org.apereo.cas.authentication.CoreAuthenticationUtils) Ticket(org.apereo.cas.ticket.Ticket) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 32 with Operation

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;
}
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 33 with Operation

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());
}
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 34 with Operation

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());
}
Also used : lombok.val(lombok.val) ImmutableAssertion(org.apereo.cas.validation.ImmutableAssertion) 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 35 with Operation

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);
}
Also used : lombok.val(lombok.val) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)151 Operation (io.swagger.v3.oas.models.Operation)108 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 OpenAPI (io.swagger.v3.oas.models.OpenAPI)79 Test (org.testng.annotations.Test)68 PathItem (io.swagger.v3.oas.models.PathItem)53 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)50 ArrayList (java.util.ArrayList)45 lombok.val (lombok.val)42 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)34 Map (java.util.Map)34 HashMap (java.util.HashMap)33 LinkedHashMap (java.util.LinkedHashMap)29 Test (org.junit.Test)29 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)28 Paths (io.swagger.v3.oas.models.Paths)27 Components (io.swagger.v3.oas.models.Components)26 Schema (io.swagger.v3.oas.models.media.Schema)24 Produces (javax.ws.rs.Produces)21 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)20