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