Search in sources :

Example 26 with Operation

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

the class LoggingConfigurationEndpoint method configuration.

/**
 * Configuration map.
 *
 * @return the map
 */
@ReadOperation
@Operation(summary = "Get logging configuration report")
public Map<String, Object> configuration() {
    val configuredLoggers = new HashSet<>();
    getLoggerConfigurations().forEach(config -> {
        val loggerMap = new HashMap<String, Object>();
        loggerMap.put("name", StringUtils.defaultIfBlank(config.getName(), LOGGER_NAME_ROOT));
        loggerMap.put("state", config.getState());
        if (config.getPropertyList() != null) {
            loggerMap.put("properties", config.getPropertyList());
        }
        loggerMap.put("additive", config.isAdditive());
        loggerMap.put("level", config.getLevel().name());
        val appenders = new HashSet<>();
        config.getAppenders().keySet().stream().map(key -> config.getAppenders().get(key)).forEach(appender -> {
            val builder = new ToStringBuilder(this, ToStringStyle.JSON_STYLE);
            builder.append("name", appender.getName());
            builder.append("state", appender.getState());
            builder.append("layoutFormat", appender.getLayout().getContentFormat());
            builder.append("layoutContentType", appender.getLayout().getContentType());
            if (appender instanceof FileAppender) {
                builder.append(FILE_PARAM, ((FileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RandomAccessFileAppender) {
                builder.append(FILE_PARAM, ((RandomAccessFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RollingFileAppender) {
                builder.append(FILE_PARAM, ((RollingFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, ((RollingFileAppender) appender).getFilePattern());
            }
            if (appender instanceof MemoryMappedFileAppender) {
                builder.append(FILE_PARAM, ((MemoryMappedFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RollingRandomAccessFileAppender) {
                builder.append(FILE_PARAM, ((RollingRandomAccessFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, ((RollingRandomAccessFileAppender) appender).getFilePattern());
            }
            appenders.add(builder.build());
        });
        loggerMap.put("appenders", appenders);
        configuredLoggers.add(loggerMap);
    });
    val responseMap = new HashMap<String, Object>();
    responseMap.put("loggers", configuredLoggers);
    val loggers = getActiveLoggersInFactory();
    responseMap.put("activeLoggers", loggers.values());
    return responseMap;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) Getter(lombok.Getter) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) SneakyThrows(lombok.SneakyThrows) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerFactory(org.slf4j.LoggerFactory) ToStringStyle(org.apache.commons.lang3.builder.ToStringStyle) Level(org.apache.logging.log4j.Level) HashMap(java.util.HashMap) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) StringUtils(org.apache.commons.lang3.StringUtils) InitializingBean(org.springframework.beans.factory.InitializingBean) HashSet(java.util.HashSet) Operation(io.swagger.v3.oas.annotations.Operation) Pair(org.apache.commons.lang3.tuple.Pair) Configurator(org.apache.logging.log4j.core.config.Configurator) Map(java.util.Map) Log4jLoggerFactory(org.apache.logging.slf4j.Log4jLoggerFactory) Resource(org.springframework.core.io.Resource) ResourceUtils(org.apereo.cas.util.ResourceUtils) Logger(org.slf4j.Logger) ResourceLoader(org.springframework.core.io.ResourceLoader) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) lombok.val(lombok.val) Set(java.util.Set) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) Slf4j(lombok.extern.slf4j.Slf4j) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) Environment(org.springframework.core.env.Environment) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) Optional(java.util.Optional) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) ILoggerFactory(org.slf4j.ILoggerFactory) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) HashMap(java.util.HashMap) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) HashSet(java.util.HashSet) 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 27 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 28 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 29 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 30 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)

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