use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation in project cas by apereo.
the class DuoSecurityPingEndpoint method pingDuo.
/**
* Ping duo and return availability result.
*
* @param providerId the provider id, if any.
* @return the map
*/
@ReadOperation(produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Ping Duo Security given the provider id", parameters = { @Parameter(name = "providerId") })
public Map<?, ?> pingDuo(@Nullable final String providerId) {
val resolver = SpringExpressionLanguageValueResolver.getInstance();
val results = new LinkedHashMap<>();
val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).forEach(p -> {
val duoService = p.getDuoAuthenticationService();
val available = duoService.ping();
results.put(p.getId(), CollectionUtils.wrap("duoApiHost", resolver.resolve(duoService.getProperties().getDuoApiHost()), "name", p.getFriendlyName(), "availability", available));
});
return results;
}
use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation in project cas by apereo.
the class DuoSecurityUserAccountStatusEndpoint method fetchAccountStatus.
/**
* Fetch account status map.
*
* @param username the username
* @param providerId the provider id
* @return the map
*/
@ReadOperation(produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Fetch Duo Security user account status", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "providerId") })
public Map<?, ?> fetchAccountStatus(@Selector final String username, @Nullable final String providerId) {
val resolver = SpringExpressionLanguageValueResolver.getInstance();
val results = new LinkedHashMap<>();
val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).forEach(p -> {
val duoService = p.getDuoAuthenticationService();
val accountStatus = duoService.getUserAccount(username);
results.put(p.getId(), CollectionUtils.wrap("duoApiHost", resolver.resolve(duoService.getProperties().getDuoApiHost()), "name", p.getFriendlyName(), "accountStatus", accountStatus));
});
return results;
}
use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation in project spring-cloud-stream by spring-cloud.
the class ChannelsEndpoint method channels.
@ReadOperation
public Map<String, Object> channels() {
ChannelsMetaData map = new ChannelsMetaData();
Map<String, BindingProperties> inputs = map.getInputs();
Map<String, BindingProperties> outputs = map.getOutputs();
for (Bindable factory : this.adapters) {
for (String name : factory.getInputs()) {
inputs.put(name, this.properties.getBindingProperties(name));
}
for (String name : factory.getOutputs()) {
outputs.put(name, this.properties.getBindingProperties(name));
}
}
return new ObjectMapper().convertValue(map, new TypeReference<Map<String, Object>>() {
});
}
use of org.springframework.boot.actuate.endpoint.annotation.ReadOperation in project cas by apereo.
the class SamlValidateEndpoint method handle.
/**
* Handle validation request and produce saml1 payload.
*
* @param username the username
* @param password the password
* @param service the service
* @return the map
*/
@ReadOperation
@Operation(summary = "Handle validation request and produce saml1 payload.", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "password", required = true), @Parameter(name = "service", required = true) })
public Map<String, Object> handle(final String username, final String password, final String service) {
val credential = new UsernamePasswordCredential(username, password);
val selectedService = this.serviceFactory.createService(service);
val result = this.authenticationSystemSupport.finalizeAuthenticationTransaction(selectedService, credential);
val authentication = result.getAuthentication();
val registeredService = this.servicesManager.findServiceBy(selectedService);
val audit = AuditableContext.builder().service(selectedService).authentication(authentication).registeredService(registeredService).build();
val accessResult = registeredServiceAccessStrategyEnforcer.execute(audit);
accessResult.throwExceptionIfNeeded();
val principal = authentication.getPrincipal();
val context = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(registeredService).service(selectedService).principal(principal).build();
val attributesToRelease = registeredService.getAttributeReleasePolicy().getAttributes(context);
val principalId = registeredService.getUsernameAttributeProvider().resolveUsername(principal, selectedService, registeredService);
val modifiedPrincipal = this.principalFactory.createPrincipal(principalId, attributesToRelease);
val builder = DefaultAuthenticationBuilder.newInstance(authentication);
builder.setPrincipal(modifiedPrincipal);
val finalAuthentication = builder.build();
val samlResponse = this.samlResponseBuilder.createResponse(selectedService.getId(), selectedService);
samlResponseBuilder.prepareSuccessfulResponse(samlResponse, selectedService, finalAuthentication, principal, finalAuthentication.getAttributes(), principal.getAttributes());
val resValidation = new LinkedHashMap<String, Object>();
val encoded = SamlUtils.transformSamlObject(this.openSamlConfigBean, samlResponse).toString();
resValidation.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_ASSERTION, encoded);
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 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;
}
Aggregations