Search in sources :

Example 66 with Operation

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

the class AttributeConsentReportEndpoint method importAccount.

/**
 * Import account.
 *
 * @param request the request
 * @return the http status
 * @throws Exception the exception
 */
@PostMapping(path = "/import", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Import a consent decision as a JSON document")
public HttpStatus importAccount(final HttpServletRequest request) throws Exception {
    val requestBody = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
    LOGGER.trace("Submitted account: [{}]", requestBody);
    val decision = MAPPER.readValue(requestBody, new TypeReference<ConsentDecision>() {
    });
    LOGGER.trace("Storing account: [{}]", decision);
    consentRepository.getObject().storeConsentDecision(decision);
    return HttpStatus.CREATED;
}
Also used : lombok.val(lombok.val) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 67 with Operation

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

the class AttributeConsentReportEndpoint method export.

/**
 * Export.
 *
 * @return the response entity
 */
@GetMapping(path = "/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@Operation(summary = "Export consent decisions as a zip file")
public ResponseEntity<Resource> export() {
    val accounts = consentRepository.getObject().findConsentDecisions();
    val resource = CompressionUtils.toZipFile(accounts.stream(), Unchecked.function(entry -> {
        val acct = (ConsentDecision) entry;
        val fileName = String.format("%s-%s", acct.getPrincipal(), acct.getId());
        val sourceFile = File.createTempFile(fileName, ".json");
        MAPPER.writeValue(sourceFile, acct);
        return sourceFile;
    }), "attrconsent");
    val headers = new HttpHeaders();
    headers.setContentDisposition(ContentDisposition.attachment().filename(Objects.requireNonNull(resource.getFilename())).build());
    return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) PathVariable(org.springframework.web.bind.annotation.PathVariable) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Operation(io.swagger.v3.oas.annotations.Operation) ObjectProvider(org.springframework.beans.factory.ObjectProvider) HttpServletRequest(javax.servlet.http.HttpServletRequest) ContentDisposition(org.springframework.http.ContentDisposition) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Resource(org.springframework.core.io.Resource) PostMapping(org.springframework.web.bind.annotation.PostMapping) Unchecked(org.jooq.lambda.Unchecked) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) CompressionUtils(org.apereo.cas.util.CompressionUtils) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) RestControllerEndpoint(org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) JacksonObjectMapperFactory(org.apereo.cas.util.serialization.JacksonObjectMapperFactory) ResponseEntity(org.springframework.http.ResponseEntity) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 68 with Operation

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

the class AttributeConsentReportEndpoint method consentDecisions.

/**
 * Consent decisions collection.
 *
 * @param principal the principal
 * @return the collection
 */
@GetMapping(path = "{principal}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get consent decisions for principal", parameters = { @Parameter(name = "principal", required = true) })
public Collection<Map<String, Object>> consentDecisions(@PathVariable final String principal) {
    val result = new HashSet<Map<String, Object>>();
    LOGGER.debug("Fetching consent decisions for principal [{}]", principal);
    val consentDecisions = this.consentRepository.getObject().findConsentDecisions(principal);
    LOGGER.debug("Resolved consent decisions for principal [{}]: [{}]", principal, consentDecisions);
    consentDecisions.forEach(d -> {
        val map = new HashMap<String, Object>();
        map.put("decision", d);
        map.put("attributes", this.consentEngine.getObject().resolveConsentableAttributesFrom(d));
        result.add(map);
    });
    return result;
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 69 with Operation

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

the class SingleSignOnSessionsEndpoint method destroySsoSession.

/**
 * Endpoint for destroying a single SSO Session.
 *
 * @param ticketGrantingTicket the ticket granting ticket
 * @param request              the request
 * @param response             the response
 * @return result map
 */
@DeleteMapping(path = "/{ticketGrantingTicket}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Remove single sign-on session for ticket id")
public Map<String, Object> destroySsoSession(@PathVariable final String ticketGrantingTicket, final HttpServletRequest request, final HttpServletResponse response) {
    val sessionsMap = new HashMap<String, Object>(1);
    try {
        val sloRequests = singleLogoutRequestExecutor.getObject().execute(ticketGrantingTicket, request, response);
        sessionsMap.put(STATUS, HttpServletResponse.SC_OK);
        sessionsMap.put(TICKET_GRANTING_TICKET, ticketGrantingTicket);
        sessionsMap.put("singleLogoutRequests", sloRequests);
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
        sessionsMap.put(STATUS, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        sessionsMap.put(TICKET_GRANTING_TICKET, ticketGrantingTicket);
        sessionsMap.put("message", e.getMessage());
    }
    return sessionsMap;
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 70 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)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)177 Operation (io.swagger.v3.oas.models.Operation)174 OpenAPI (io.swagger.v3.oas.models.OpenAPI)141 Test (org.testng.annotations.Test)129 PathItem (io.swagger.v3.oas.models.PathItem)108 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 Schema (io.swagger.v3.oas.models.media.Schema)68 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)62 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)59 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)55 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)51 ArrayList (java.util.ArrayList)51 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)50 StringSchema (io.swagger.v3.oas.models.media.StringSchema)48 MediaType (io.swagger.v3.oas.models.media.MediaType)44 Path (javax.ws.rs.Path)44 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)43 Content (io.swagger.v3.oas.models.media.Content)42 lombok.val (lombok.val)42 Parameter (io.swagger.v3.oas.models.parameters.Parameter)39