Search in sources :

Example 46 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter 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;
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationContext(org.springframework.context.ApplicationContext) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) Operation(io.swagger.v3.oas.annotations.Operation) SpringExpressionLanguageValueResolver(org.apereo.cas.util.spring.SpringExpressionLanguageValueResolver) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Nullable(org.springframework.lang.Nullable) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) 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 47 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter 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;
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationContext(org.springframework.context.ApplicationContext) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) Operation(io.swagger.v3.oas.annotations.Operation) SpringExpressionLanguageValueResolver(org.apereo.cas.util.spring.SpringExpressionLanguageValueResolver) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Nullable(org.springframework.lang.Nullable) 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 48 with Parameter

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

the class SingleSignOnSessionStatusEndpoint method ssoStatus.

/**
 * Sso status response entity.
 *
 * @param tgc     the tgc
 * @param request the request
 * @return the response entity
 */
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get current status of single sign-on", parameters = { @Parameter(name = "tgc", required = false), @Parameter(name = "request", required = false) })
public ResponseEntity<Map<?, ?>> ssoStatus(@RequestParam(name = "tgc", required = false, defaultValue = StringUtils.EMPTY) final String tgc, final HttpServletRequest request) {
    val tgtId = StringUtils.isNotBlank(tgc) ? ticketGrantingTicketCookieGenerator.getCasCookieValueManager().obtainCookieValue(tgc, request) : ticketGrantingTicketCookieGenerator.retrieveCookieValue(request);
    if (StringUtils.isBlank(tgtId)) {
        return ResponseEntity.badRequest().build();
    }
    val auth = this.ticketRegistrySupport.getAuthenticationFrom(tgtId);
    if (auth == null) {
        return ResponseEntity.badRequest().build();
    }
    val ticketState = this.ticketRegistrySupport.getTicket(tgtId);
    val body = CollectionUtils.wrap("principal", auth.getPrincipal().getId(), "authenticationDate", auth.getAuthenticationDate(), "ticketGrantingTicketCreationTime", ticketState.getCreationTime(), "ticketGrantingTicketPreviousTimeUsed", ticketState.getPreviousTimeUsed(), "ticketGrantingTicketLastTimeUsed", ticketState.getLastTimeUsed());
    return ResponseEntity.ok(body);
}
Also used : lombok.val(lombok.val) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 49 with Parameter

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

the class SpringWebflowEndpoint method getReport.

/**
 * Get SWF report.
 *
 * @param flowId  the flow id
 * @param stateId the state id
 * @return JSON representing the current state of SWF.
 */
@ReadOperation
@Operation(summary = "Get Spring webflow report using an optional flow id", parameters = { @Parameter(name = "flowId"), @Parameter(name = "stateId") })
public Map<?, ?> getReport(@Nullable final String flowId, @Nullable final String stateId) {
    val jsonMap = new LinkedHashMap<String, Object>();
    val executionPlan = applicationContext.getBean(CasWebflowExecutionPlan.BEAN_NAME, CasWebflowExecutionPlan.class);
    executionPlan.execute();
    val map = applicationContext.getBeansOfType(FlowDefinitionRegistry.class);
    map.forEach((k, value) -> Arrays.stream(value.getFlowDefinitionIds()).filter(currentId -> StringUtils.isBlank(flowId) || flowId.equalsIgnoreCase(currentId)).forEach(id -> {
        val flowDefinition = (Flow) value.getFlowDefinition(id);
        val flowDetails = new LinkedHashMap<String, Object>();
        flowDetails.put("startState", flowDefinition.getStartState().getId());
        val startActions = StreamSupport.stream(flowDefinition.getStartActionList().spliterator(), false).map(SpringWebflowEndpoint::convertActionToString).collect(Collectors.toList());
        if (!startActions.isEmpty()) {
            flowDetails.put("startActions", startActions);
        }
        val states = new LinkedHashMap<String, Map>();
        Arrays.stream(flowDefinition.getStateIds()).filter(st -> StringUtils.isBlank(stateId) || RegexUtils.find(stateId, st)).forEach(st -> {
            val stateMap = getStateDetails(flowDefinition, st);
            states.put(st, stateMap);
        });
        flowDetails.put("states", states);
        flowDetails.put("possibleOutcomes", flowDefinition.getPossibleOutcomes());
        flowDetails.put("stateCount", flowDefinition.getStateCount());
        var acts = StreamSupport.stream(flowDefinition.getEndActionList().spliterator(), false).map(SpringWebflowEndpoint::convertActionToString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            flowDetails.put("endActions", acts);
        }
        acts = StreamSupport.stream(flowDefinition.getGlobalTransitionSet().spliterator(), false).map(tr -> tr.getId() + " -> " + tr.getTargetStateId() + " @ " + tr.getExecutionCriteria().toString()).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            flowDetails.put("globalTransitions", acts);
        }
        acts = Arrays.stream(flowDefinition.getExceptionHandlerSet().toArray()).map(Object::toString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            flowDetails.put("exceptionHandlers", acts);
        }
        val vars = Arrays.stream(flowDefinition.getVariables()).map(FlowVariable::getName).collect(Collectors.joining(","));
        if (StringUtils.isNotBlank(vars)) {
            flowDetails.put("variables", vars);
        }
        jsonMap.put(id, flowDetails);
    }));
    return jsonMap;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ActionState(org.springframework.webflow.engine.ActionState) Arrays(java.util.Arrays) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) SetAction(org.springframework.webflow.action.SetAction) ExternalRedirectAction(org.springframework.webflow.action.ExternalRedirectAction) AnnotatedAction(org.springframework.webflow.execution.AnnotatedAction) ActionExecutingViewFactory(org.springframework.webflow.engine.support.ActionExecutingViewFactory) CasWebflowExecutionPlan(org.apereo.cas.web.flow.CasWebflowExecutionPlan) StringUtils(org.apache.commons.lang3.StringUtils) TransitionableState(org.springframework.webflow.engine.TransitionableState) LinkedHashMap(java.util.LinkedHashMap) Operation(io.swagger.v3.oas.annotations.Operation) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Nullable(org.springframework.lang.Nullable) StreamSupport(java.util.stream.StreamSupport) FlowDefinitionRegistry(org.springframework.webflow.definition.registry.FlowDefinitionRegistry) FlowVariable(org.springframework.webflow.engine.FlowVariable) State(org.springframework.webflow.engine.State) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) lombok.val(lombok.val) Expression(org.springframework.binding.expression.Expression) EvaluateAction(org.springframework.webflow.action.EvaluateAction) Flow(org.springframework.webflow.engine.Flow) Action(org.springframework.webflow.execution.Action) Field(java.lang.reflect.Field) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) RegexUtils(org.apereo.cas.util.RegexUtils) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) EndState(org.springframework.webflow.engine.EndState) ViewState(org.springframework.webflow.engine.ViewState) ReflectionUtils(org.springframework.util.ReflectionUtils) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) FlowVariable(org.springframework.webflow.engine.FlowVariable) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 50 with Parameter

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

the class CasResolveAttributesReportEndpoint method resolvePrincipalAttributes.

/**
 * Resolve principal attributes map.
 *
 * @param uid the uid
 * @return the map
 */
@ReadOperation
@Operation(summary = "Resolve principal attributes for user", parameters = { @Parameter(name = "uid", required = true) })
public Map<String, Object> resolvePrincipalAttributes(@Selector final String uid) {
    val p = defaultPrincipalResolver.getObject().resolve(new BasicIdentifiableCredential(uid));
    val map = new HashMap<String, Object>();
    map.put("uid", p.getId());
    map.put("attributes", p.getAttributes());
    return map;
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) BasicIdentifiableCredential(org.apereo.cas.authentication.credential.BasicIdentifiableCredential) 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