Search in sources :

Example 1 with TokenHandler

use of io.helidon.security.util.TokenHandler in project helidon by oracle.

the class HeaderAtnProvider method syncOutbound.

@Override
protected OutboundSecurityResponse syncOutbound(ProviderRequest providerRequest, SecurityEnvironment outboundEnv, EndpointConfig outboundEndpointConfig) {
    Optional<Subject> toPropagate;
    if (subjectType == SubjectType.USER) {
        toPropagate = providerRequest.securityContext().user();
    } else {
        toPropagate = providerRequest.securityContext().service();
    }
    // find the target
    var target = outboundConfig.findTargetCustomObject(outboundEnv, HeaderAtnOutboundConfig.class, HeaderAtnOutboundConfig::create, HeaderAtnOutboundConfig::create);
    // we have no target, let's fall back to original behavior
    if (target.isEmpty()) {
        if (outboundTokenHandler != null) {
            return toPropagate.map(Subject::principal).map(Principal::id).map(id -> respond(outboundEnv, outboundTokenHandler, id)).orElseGet(OutboundSecurityResponse::abstain);
        }
        return OutboundSecurityResponse.abstain();
    }
    // we found a target
    HeaderAtnOutboundConfig outboundConfig = target.get();
    TokenHandler tokenHandler = outboundConfig.tokenHandler().orElse(defaultOutboundTokenHandler);
    return outboundConfig.explicitUser().or(() -> toPropagate.map(Subject::principal).map(Principal::id)).map(id -> respond(outboundEnv, tokenHandler, id)).orElseGet(OutboundSecurityResponse::abstain);
}
Also used : OutboundSecurityResponse(io.helidon.security.OutboundSecurityResponse) ProviderRequest(io.helidon.security.ProviderRequest) Config(io.helidon.config.Config) SubjectType(io.helidon.security.SubjectType) OutboundSecurityProvider(io.helidon.security.spi.OutboundSecurityProvider) SynchronousProvider(io.helidon.security.spi.SynchronousProvider) HashMap(java.util.HashMap) TokenHandler(io.helidon.security.util.TokenHandler) AuthenticationResponse(io.helidon.security.AuthenticationResponse) OutboundConfig(io.helidon.security.providers.common.OutboundConfig) Principal(io.helidon.security.Principal) List(java.util.List) AuthenticationProvider(io.helidon.security.spi.AuthenticationProvider) EndpointConfig(io.helidon.security.EndpointConfig) SecurityEnvironment(io.helidon.security.SecurityEnvironment) OutboundTarget(io.helidon.security.providers.common.OutboundTarget) Map(java.util.Map) Optional(java.util.Optional) Subject(io.helidon.security.Subject) TokenHandler(io.helidon.security.util.TokenHandler) Subject(io.helidon.security.Subject) Principal(io.helidon.security.Principal) OutboundSecurityResponse(io.helidon.security.OutboundSecurityResponse)

Example 2 with TokenHandler

use of io.helidon.security.util.TokenHandler in project helidon by oracle.

the class QueryParamMapping method create.

/**
 * Read a new instance from configuration.
 * The current node should contain a {@code "name"} and configuration for {@link TokenHandler}
 *
 * @param config configuration instance
 * @return new query parameter handler instance
 */
public static QueryParamMapping create(Config config) {
    String name = config.get("name").asString().get();
    TokenHandler handler = config.as(TokenHandler::create).get();
    return create(name, handler);
}
Also used : TokenHandler(io.helidon.security.util.TokenHandler)

Aggregations

TokenHandler (io.helidon.security.util.TokenHandler)2 Config (io.helidon.config.Config)1 AuthenticationResponse (io.helidon.security.AuthenticationResponse)1 EndpointConfig (io.helidon.security.EndpointConfig)1 OutboundSecurityResponse (io.helidon.security.OutboundSecurityResponse)1 Principal (io.helidon.security.Principal)1 ProviderRequest (io.helidon.security.ProviderRequest)1 SecurityEnvironment (io.helidon.security.SecurityEnvironment)1 Subject (io.helidon.security.Subject)1 SubjectType (io.helidon.security.SubjectType)1 OutboundConfig (io.helidon.security.providers.common.OutboundConfig)1 OutboundTarget (io.helidon.security.providers.common.OutboundTarget)1 AuthenticationProvider (io.helidon.security.spi.AuthenticationProvider)1 OutboundSecurityProvider (io.helidon.security.spi.OutboundSecurityProvider)1 SynchronousProvider (io.helidon.security.spi.SynchronousProvider)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1