Search in sources :

Example 16 with ReadOperation

use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation 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 17 with ReadOperation

use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation in project cas by apereo.

the class StatusEndpoint method handle.

/**
 * Handle request.
 *
 * @return the map
 */
@ReadOperation
@Operation(summary = "Provides CAS server's health status", deprecated = true)
public Map<String, Object> handle() {
    val model = new LinkedHashMap<String, Object>();
    if (healthEndpoint.getIfAvailable() == null) {
        model.put("status", HttpStatus.OK.value());
        model.put("description", HttpStatus.OK.name());
        LOGGER.info("Health endpoint is undefined/disabled. No health indicators may be consulted to query for health data " + "and the status results are always going to be [{}]", model);
    } else {
        val health = this.healthEndpoint.getObject().health();
        val status = health.getStatus();
        if (status.equals(Status.DOWN) || status.equals(Status.OUT_OF_SERVICE)) {
            model.put("status", HttpStatus.SERVICE_UNAVAILABLE.value());
            model.put("description", HttpStatus.SERVICE_UNAVAILABLE.name());
        } else {
            model.put("status", HttpStatus.OK.value());
            model.put("description", HttpStatus.OK.name());
        }
        model.put("health", status.getCode());
    }
    val hostname = casProperties.getHost().getName();
    model.put("host", StringUtils.isBlank(hostname) ? InetAddressUtils.getCasServerHostName() : hostname);
    model.put("server", casProperties.getServer().getName());
    model.put("version", CasVersion.asString());
    return model;
}
Also used : lombok.val(lombok.val) LinkedHashMap(java.util.LinkedHashMap) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 18 with ReadOperation

use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation in project cas by apereo.

the class CasConfigurationMetadataServerEndpoint method search.

/**
 * Search for property.
 *
 * @param name the name
 * @return the response entity
 */
@ReadOperation
@Operation(summary = "Get all properties from the repository that match the name", parameters = { @Parameter(name = "name", required = true) })
public List<ConfigurationMetadataSearchResult> search(@Selector final String name) {
    val allProps = repository.getRepository().getAllProperties();
    if (StringUtils.isNotBlank(name) && RegexUtils.isValidRegex(name)) {
        val names = StreamSupport.stream(RelaxedPropertyNames.forCamelCase(name).spliterator(), false).map(Object::toString).collect(Collectors.joining("|"));
        val pattern = RegexUtils.createPattern(names);
        return allProps.entrySet().stream().filter(propEntry -> RegexUtils.find(pattern, propEntry.getKey())).map(propEntry -> new ConfigurationMetadataSearchResult(propEntry.getValue(), repository)).sorted().collect(Collectors.toList());
    }
    return new ArrayList<>(0);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) Collectors(java.util.stream.Collectors) RegexUtils(org.apereo.cas.util.RegexUtils) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) ArrayList(java.util.ArrayList) Parameter(io.swagger.v3.oas.annotations.Parameter) CasConfigurationMetadataRepository(org.apereo.cas.metadata.CasConfigurationMetadataRepository) Operation(io.swagger.v3.oas.annotations.Operation) List(java.util.List) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) RelaxedPropertyNames(org.apereo.cas.configuration.support.RelaxedPropertyNames) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) ArrayList(java.util.ArrayList) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 19 with ReadOperation

use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation in project cas by apereo.

the class SamlRegisteredServiceCachedMetadataEndpoint method getCachedMetadataObject.

/**
 * Gets cached metadata object.
 *
 * @param serviceId the service id
 * @param entityId  the entity id
 * @return the cached metadata object
 */
@ReadOperation
@Operation(summary = "Get SAML2 cached metadata", parameters = { @Parameter(name = "serviceId", required = true), @Parameter(name = "entityId") })
public Map<String, Object> getCachedMetadataObject(final String serviceId, @Nullable final String entityId) {
    try {
        val registeredService = findRegisteredService(serviceId);
        val issuer = StringUtils.defaultIfBlank(entityId, registeredService.getServiceId());
        val criteriaSet = new CriteriaSet();
        criteriaSet.add(new EntityIdCriterion(issuer));
        criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
        val metadataResolver = cachingMetadataResolver.resolve(registeredService, criteriaSet);
        val iteration = metadataResolver.resolve(criteriaSet).spliterator();
        return StreamSupport.stream(iteration, false).map(entity -> Pair.of(entity.getEntityID(), SamlUtils.transformSamlObject(openSamlConfigBean, entity).toString())).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
        return CollectionUtils.wrap("error", e.getMessage());
    }
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) StringUtils(org.apache.commons.lang3.StringUtils) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) SamlUtils(org.apereo.cas.support.saml.SamlUtils) LoggingUtils(org.apereo.cas.util.LoggingUtils) Operation(io.swagger.v3.oas.annotations.Operation) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Nullable(org.springframework.lang.Nullable) StreamSupport(java.util.stream.StreamSupport) ServicesManager(org.apereo.cas.services.ServicesManager) AuditableContext(org.apereo.cas.audit.AuditableContext) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) Collection(java.util.Collection) lombok.val(lombok.val) Collectors(java.util.stream.Collectors) RegisteredService(org.apereo.cas.services.RegisteredService) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) SPSSODescriptor(org.opensaml.saml.saml2.metadata.SPSSODescriptor) OpenSamlConfigBean(org.apereo.cas.support.saml.OpenSamlConfigBean) Parameter(io.swagger.v3.oas.annotations.Parameter) Slf4j(lombok.extern.slf4j.Slf4j) AuditableExecution(org.apereo.cas.audit.AuditableExecution) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) NumberUtils(org.apache.commons.lang3.math.NumberUtils) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 20 with ReadOperation

use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation 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)

Aggregations

ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)27 Operation (io.swagger.v3.oas.annotations.Operation)14 lombok.val (lombok.val)14 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)10 Map (java.util.Map)9 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)9 BaseCasActuatorEndpoint (org.apereo.cas.web.BaseCasActuatorEndpoint)9 Endpoint (org.springframework.boot.actuate.endpoint.annotation.Endpoint)9 Parameter (io.swagger.v3.oas.annotations.Parameter)8 StringUtils (org.apache.commons.lang3.StringUtils)8 Nullable (org.springframework.lang.Nullable)6 ApplicationContext (org.springframework.context.ApplicationContext)5 Collectors (java.util.stream.Collectors)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Objects (java.util.Objects)3 StreamSupport (java.util.stream.StreamSupport)3 Slf4j (lombok.extern.slf4j.Slf4j)3 CollectionUtils (org.apereo.cas.util.CollectionUtils)3