Search in sources :

Example 91 with Parameter

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

the class SamlRegisteredServiceCachedMetadataEndpoint method invalidate.

/**
 * Invalidate.
 *
 * @param serviceId the service id
 */
@DeleteOperation
@Operation(summary = "Invalidate SAML2 metadata cache using an entity id.", parameters = { @Parameter(name = "serviceId") })
public void invalidate(@Nullable final String serviceId) {
    if (StringUtils.isBlank(serviceId)) {
        cachingMetadataResolver.invalidate();
    } else {
        val registeredService = findRegisteredService(serviceId);
        val criteriaSet = new CriteriaSet();
        criteriaSet.add(new EntityIdCriterion(serviceId));
        criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
        cachingMetadataResolver.invalidate(registeredService, criteriaSet);
    }
}
Also used : lombok.val(lombok.val) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 92 with Parameter

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

the class CasReleaseAttributesReportEndpoint method releasePrincipalAttributes.

/**
 * Release principal attributes map.
 *
 * @param username the username
 * @param password the password
 * @param service  the service
 * @return the map
 */
@ReadOperation
@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> releasePrincipalAttributes(final String username, final String password, final String service) {
    val selectedService = this.serviceFactory.createService(service);
    val registeredService = this.servicesManager.findServiceBy(selectedService);
    val credential = new UsernamePasswordCredential(username, password);
    val result = this.authenticationSystemSupport.finalizeAuthenticationTransaction(selectedService, credential);
    val authentication = result.getAuthentication();
    val principal = authentication.getPrincipal();
    val context = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(registeredService).service(selectedService).principal(principal).build();
    val attributesToRelease = registeredService.getAttributeReleasePolicy().getAttributes(context);
    val builder = DefaultAuthenticationBuilder.of(principal, this.principalFactory, attributesToRelease, selectedService, registeredService, authentication);
    val finalAuthentication = builder.build();
    val assertion = new DefaultAssertionBuilder(finalAuthentication).with(selectedService).with(CollectionUtils.wrap(finalAuthentication)).build();
    val resValidation = new LinkedHashMap<String, Object>();
    resValidation.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_ASSERTION, assertion);
    resValidation.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_SERVICE, selectedService);
    resValidation.put("registeredService", registeredService);
    return resValidation;
}
Also used : lombok.val(lombok.val) DefaultAssertionBuilder(org.apereo.cas.validation.DefaultAssertionBuilder) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) LinkedHashMap(java.util.LinkedHashMap) 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 93 with Parameter

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

the class SSOSamlIdPPostProfileHandlerEndpoint method producePost.

/**
 * Produce response entity.
 *
 * @param request  the request
 * @param response the response
 * @param map      the RequestBody
 * @return the response entity
 */
@PostMapping(produces = MediaType.APPLICATION_XML_VALUE)
@ResponseBody
@Operation(summary = "Produce SAML2 response entity", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "password", required = true), @Parameter(name = SamlProtocolConstants.PARAMETER_ENTITY_ID, required = true), @Parameter(name = "encrypt") })
public ResponseEntity<Object> producePost(final HttpServletRequest request, final HttpServletResponse response, @RequestBody final Map<String, String> map) {
    val username = map.get("username");
    val password = map.get("password");
    val entityId = map.get(SamlProtocolConstants.PARAMETER_ENTITY_ID);
    val encrypt = Boolean.parseBoolean(map.get("encrypt"));
    return produce(request, response, username, password, entityId, encrypt);
}
Also used : lombok.val(lombok.val) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 94 with Parameter

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

the class JwtTokenCipherSigningPublicKeyEndpoint method fetchPublicKey.

/**
 * Fetch public key.
 *
 * @param service the service
 * @return the string
 * @throws Exception the exception
 */
@ReadOperation(produces = MediaType.TEXT_PLAIN_VALUE)
@Operation(summary = "Get public key for signing operations", parameters = { @Parameter(name = "service") })
public String fetchPublicKey(@Nullable final String service) throws Exception {
    var signingKey = tokenCipherExecutor.getSigningKey();
    if (StringUtils.isNotBlank(service)) {
        val registeredService = servicesManager.findServiceBy(webApplicationServiceFactory.createService(service));
        RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(registeredService);
        val serviceCipher = new RegisteredServiceJwtTicketCipherExecutor();
        if (serviceCipher.supports(registeredService)) {
            val cipher = serviceCipher.getTokenTicketCipherExecutorForService(registeredService);
            if (cipher.isEnabled()) {
                signingKey = cipher.getSigningKey();
            }
        }
    }
    if (signingKey instanceof RSAPrivateCrtKey) {
        val rsaSigningKey = (RSAPrivateCrtKey) signingKey;
        val factory = KeyFactory.getInstance("RSA");
        val publicKey = factory.generatePublic(new RSAPublicKeySpec(rsaSigningKey.getModulus(), rsaSigningKey.getPublicExponent()));
        return EncodingUtils.encodeBase64(publicKey.getEncoded());
    }
    return null;
}
Also used : lombok.val(lombok.val) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) RegisteredServiceJwtTicketCipherExecutor(org.apereo.cas.token.cipher.RegisteredServiceJwtTicketCipherExecutor) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 95 with Parameter

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

the class TicketExpirationPoliciesEndpoint method handle.

/**
 * Produce expiration policies.
 *
 * @param serviceId the service
 * @return the map
 * @throws Exception the exception
 */
@ReadOperation
@Operation(summary = "Produce expiration policies given an optional service id", parameters = { @Parameter(name = "serviceId") })
public Map<String, String> handle(@Nullable final String serviceId) throws Exception {
    val model = new HashMap<String, String>();
    expirationPolicyBuilders.forEach(Unchecked.consumer(builder -> {
        val policy = builder.buildTicketExpirationPolicy();
        val details = getTicketExpirationPolicyDetails(policy);
        model.put(builder.getTicketType().getName(), details);
    }));
    val registeredService = StringUtils.isNotBlank(serviceId) ? NumberUtils.isCreatable(serviceId) ? servicesManager.findServiceBy(Long.parseLong(serviceId)) : servicesManager.findServiceBy(webApplicationServiceFactory.createService(serviceId)) : null;
    Optional.ofNullable(registeredService).map(RegisteredService::getTicketGrantingTicketExpirationPolicy).map(RegisteredServiceTicketGrantingTicketExpirationPolicy::toExpirationPolicy).filter(Optional::isPresent).map(Optional::get).ifPresent(Unchecked.consumer(policy -> {
        val details = getTicketExpirationPolicyDetails(policy);
        model.put(TicketGrantingTicket.class.getName().concat(registeredService.getName()), details);
    }));
    Optional.ofNullable(registeredService).map(RegisteredService::getServiceTicketExpirationPolicy).ifPresent(Unchecked.consumer(policy -> {
        val details = getTicketExpirationPolicyDetails(policy);
        model.put(ServiceTicket.class.getName().concat(registeredService.getName()), details);
    }));
    Optional.ofNullable(registeredService).map(RegisteredService::getProxyGrantingTicketExpirationPolicy).ifPresent(Unchecked.consumer(policy -> {
        val details = getTicketExpirationPolicyDetails(policy);
        model.put(ProxyGrantingTicket.class.getName().concat(registeredService.getName()), details);
    }));
    Optional.ofNullable(registeredService).map(RegisteredService::getProxyTicketExpirationPolicy).ifPresent(Unchecked.consumer(policy -> {
        val details = getTicketExpirationPolicyDetails(policy);
        model.put(ProxyTicket.class.getName().concat(registeredService.getName()), details);
    }));
    return model;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Getter(lombok.Getter) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ExpirationPolicyBuilder(org.apereo.cas.ticket.ExpirationPolicyBuilder) RegisteredServiceTicketGrantingTicketExpirationPolicy(org.apereo.cas.services.RegisteredServiceTicketGrantingTicketExpirationPolicy) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Operation(io.swagger.v3.oas.annotations.Operation) Map(java.util.Map) Nullable(org.springframework.lang.Nullable) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) ServicesManager(org.apereo.cas.services.ServicesManager) Unchecked(org.jooq.lambda.Unchecked) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) RegisteredService(org.apereo.cas.services.RegisteredService) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Serializable(java.io.Serializable) Parameter(io.swagger.v3.oas.annotations.Parameter) List(java.util.List) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) JacksonObjectMapperFactory(org.apereo.cas.util.serialization.JacksonObjectMapperFactory) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) RegisteredService(org.apereo.cas.services.RegisteredService) Optional(java.util.Optional) HashMap(java.util.HashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

Parameter (io.swagger.v3.oas.models.parameters.Parameter)48 Test (org.testng.annotations.Test)39 Operation (io.swagger.v3.oas.models.Operation)28 Operation (io.swagger.v3.oas.annotations.Operation)27 lombok.val (lombok.val)26 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Map (java.util.Map)17 ArrayList (java.util.ArrayList)16 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)15 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)14 Test (org.junit.Test)14 PathItem (io.swagger.v3.oas.models.PathItem)13 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)13 StringUtils (org.apache.commons.lang3.StringUtils)13 StringSchema (io.swagger.v3.oas.models.media.StringSchema)12 LinkedHashMap (java.util.LinkedHashMap)12 Parameter (io.swagger.v3.oas.annotations.Parameter)11 RequestParameters (io.vertx.ext.web.api.RequestParameters)11 HashMap (java.util.HashMap)11 Schema (io.swagger.v3.oas.models.media.Schema)10