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