Package io.helidon.security
Interface SecurityContext
- 
 public interface SecurityContextSecurity context to retrieve security information about current user, either injected or obtained fromSecurity.contextBuilder(String)and to handle programmatic security.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Interface Description static classSecurityContext.BuilderFluent API builder forSecurityContext.
 - 
Field SummaryFields Modifier and Type Field Description static SubjectANONYMOUSAnonymous subject.static PrincipalANONYMOUS_PRINCIPALAnonymous user principal.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description SecurityClientBuilder<AuthenticationResponse>atnClientBuilder()Authenticator client builder to use for programmatic authentication.booleanatzChecked()Return true if either of authorization methods (authorize(Object...)oratzClientBuilder()was called).SecurityClientBuilder<AuthorizationResponse>atzClientBuilder()Authorization client builder to use for programmatic authorization.voidaudit(AuditEvent event)Audit a security event.AuthenticationResponseauthenticate()Authenticate current request (based on currentSecurityEnvironmentandEndpointConfig.AuthorizationResponseauthorize(Object... resource)Authorize access to a resource (or more resources) based on current environment and endpoint configuration.EndpointConfigendpointConfig()Current endpoint configuration.voidendpointConfig(EndpointConfig ec)Set endpoint configuration to use for subsequent security requests.default voidendpointConfig(Supplier<EndpointConfig> epBuilder)Shortcut method to setEndpointConfigusing a builder rather than built instance.SecurityEnvironmentenv()CurrentSecurityEnvironment.voidenv(SecurityEnvironment env)Set a new security environment to be used in this context.default voidenv(Supplier<SecurityEnvironment> envBuilder)Set a new security environment to be used int this context.ExecutorServiceexecutorService()Executor service of the security module.Stringid()Id of this context instance.booleanisAuthenticated()Return true if the user is authenticated.booleanisUserInRole(String role)Check if user is in specified role if supported by global authorization provider.booleanisUserInRole(String role, String authorizerName)Check if user is in specified role if supported by global or specific authorization provider.voidlogout()Logout user, clear current security context.OutboundSecurityClientBuilderoutboundClientBuilder()Outbound security client builder for programmatic outbound security used for identity propagation, identity mapping, encryption of outbound calls etc.voidrunAs(Subject subject, Runnable runnable)Executes provided code under provided subject.voidrunAs(String role, Runnable runnable)Execute provided code as current user with an additional explicit role added.SecurityRequestBuilder<?>securityRequestBuilder()A builder to build aSecurityRequest.SecurityRequestBuilder<?>securityRequestBuilder(SecurityEnvironment environment)A builder to build aSecurityRequestwith a specific environment.SecurityTimeserverTime()Get time instance, that can be used to obtain current time consistent with the security framework.Optional<Subject>service()Returns subject of current context (caller) service or client identity.default StringserviceName()A helper method to get service name if authenticated.default Optional<Principal>servicePrincipal()Returns service principal if service is authenticated.Tracertracer()Provides the tracer to create new spans.SpanContexttracingSpan()Provides the span for tracing.Optional<Subject>user()Returns subject of current context (caller) user.default StringuserName()A helper method to get user name if authenticated.default Optional<Principal>userPrincipal()Returns user principal if user is authenticated.
 
- 
- 
- 
Field Detail- 
ANONYMOUS_PRINCIPALstatic final Principal ANONYMOUS_PRINCIPAL Anonymous user principal. This is the user principal used when no user is authenticated (e.g. when a service is authenticated or when fullyANONYMOUS.
 - 
ANONYMOUSstatic final Subject ANONYMOUS Anonymous subject. This is the subject you get when not authenticated and a Subject is required..
 
- 
 - 
Method Detail- 
securityRequestBuilderSecurityRequestBuilder<?> securityRequestBuilder() A builder to build aSecurityRequest.- Returns:
- security request builder
 
 - 
securityRequestBuilderSecurityRequestBuilder<?> securityRequestBuilder(SecurityEnvironment environment) A builder to build aSecurityRequestwith a specific environment.- Parameters:
- environment- environment to use for this request
- Returns:
- security request builder
 
 - 
atnClientBuilderSecurityClientBuilder<AuthenticationResponse> atnClientBuilder() Authenticator client builder to use for programmatic authentication.- Returns:
- a builder for SecurityClientinstance providingAuthenticationResponse
 
 - 
authenticateAuthenticationResponse authenticate() Authenticate current request (based on currentSecurityEnvironmentandEndpointConfig.- Returns:
- response of authentication operation
 
 - 
atzClientBuilderSecurityClientBuilder<AuthorizationResponse> atzClientBuilder() Authorization client builder to use for programmatic authorization. Will use existing environment.- Returns:
- a builder for SecurityClientinstance providingAuthorizationResponse
 
 - 
outboundClientBuilderOutboundSecurityClientBuilder outboundClientBuilder() Outbound security client builder for programmatic outbound security used for identity propagation, identity mapping, encryption of outbound calls etc.- Returns:
- a builder for SecurityClientinstance providingOutboundSecurityResponse
 
 - 
authorizeAuthorizationResponse authorize(Object... resource) Authorize access to a resource (or more resources) based on current environment and endpoint configuration.- Parameters:
- resource- resources to authorize access to (may be empty)
- Returns:
- response of authorization
 
 - 
isAuthenticatedboolean isAuthenticated() Return true if the user is authenticated. This only cares about USER! not about service. To check if service is authenticated, useservice()and check the resulting optional.- Returns:
- true for authenticated user, false otherwise (e.g. no subject or ANONYMOUS)
 
 - 
logoutvoid logout() Logout user, clear current security context.
 - 
isUserInRoleboolean isUserInRole(String role, String authorizerName) Check if user is in specified role if supported by global or specific authorization provider.- Parameters:
- role- Role to check
- authorizerName- explicit authorization provider class name to use (or config property pointing to class name)
- Returns:
- true if current user is in specified role and current authorization provider supports roles, false otherwise
 
 - 
executorServiceExecutorService executorService() Executor service of the security module.- Returns:
- executor service to use to execute asynchronous tasks related to security
 
 - 
isUserInRoleboolean isUserInRole(String role) Check if user is in specified role if supported by global authorization provider. This method expects global authorization provider is in use. If you explicitly use a custom provider, useisUserInRole(String, String)instead.- Parameters:
- role- Role to check
- Returns:
- true if current user is in specified role and current authorization provider supports roles, false otherwise
 
 - 
auditvoid audit(AuditEvent event) Audit a security event. This allows custom auditing events from applications. Note that main security events are already audited (e.g. authentication, authorization, identity propagation and various runAs events).- Parameters:
- event- AuditEvent to store
 
 - 
serviceOptional<Subject> service() Returns subject of current context (caller) service or client identity.- Returns:
- current context service (client) subject. If there is no service/client, returns empty.
 
 - 
servicePrincipaldefault Optional<Principal> servicePrincipal() Returns service principal if service is authenticated.- Returns:
- current context service principal, or empty if none authenticated
 
 - 
serviceNamedefault String serviceName() A helper method to get service name if authenticated.- Returns:
- name of currently authenticated service or null.
 
 - 
userOptional<Subject> user() Returns subject of current context (caller) user.- Returns:
- current context user subject. If there is no authenticated user, returns empty.
 
 - 
userPrincipaldefault Optional<Principal> userPrincipal() Returns user principal if user is authenticated.- Returns:
- current context user principal, or empty if none authenticated
 
 - 
userNamedefault String userName() A helper method to get user name if authenticated.- Returns:
- name of currently authenticated user or null.
 
 - 
runAsvoid runAs(Subject subject, Runnable runnable) Executes provided code under provided subject.- Parameters:
- subject- to use for execution. Use- ANONYMOUSfor anon.
- runnable- to execute.
 
 - 
runAsvoid runAs(String role, Runnable runnable) Execute provided code as current user with an additional explicit role added.- Parameters:
- role- name of role
- runnable- to execute
 
 - 
tracingSpanSpanContext tracingSpan() Provides the span for tracing. This is the span of current context (e.g. parent to security).- Returns:
- Open tracing Span context of current security context
 
 - 
tracerTracer tracer() Provides the tracer to create new spans. If you use this, we can control whether tracing is enabled or disabled as part of security. If you useGlobalTracer.get()you will get around this.- Returns:
- Tracerto build custom- Spans. Use in combination with- tracingSpan()to create a nice tree of spans
 
 - 
idString id() Id of this context instance. Created as security instance id : context id (depends on container integration or id provided by developer).- Returns:
- id uniquely identifying this context
 
 - 
serverTimeSecurityTime serverTime() Get time instance, that can be used to obtain current time consistent with the security framework. This time may be shifted against real time, may have a different time zone, explicit values (for testing). To obtain the decisive time for current request, please useSecurityEnvironment.- Returns:
- time instance to obtain current time
- See Also:
- SecurityTime.get()
 
 - 
envSecurityEnvironment env() CurrentSecurityEnvironment. For web, this probably won't change, as the environment is valid for whole request. For other frameworks or standalone applications, this may change over time.- Returns:
- environment of current security context (e.g. to use for ABAC)
 
 - 
envdefault void env(Supplier<SecurityEnvironment> envBuilder) Set a new security environment to be used int this context.- Parameters:
- envBuilder- builder to build environment from
- See Also:
- SecurityEnvironment.derive(),- SecurityEnvironment.builder(SecurityTime)
 
 - 
envvoid env(SecurityEnvironment env) Set a new security environment to be used in this context.- Parameters:
- env- environment to use for further security operations
- See Also:
- SecurityEnvironment.derive()
 
 - 
endpointConfigEndpointConfig endpointConfig() Current endpoint configuration.- Returns:
- configuration specific to current endpoint (annotations, config, custom object, attributes)
 
 - 
endpointConfigvoid endpointConfig(EndpointConfig ec) Set endpoint configuration to use for subsequent security requests.- Parameters:
- ec- configuration specific to current endpoint (annotations, config, custom object, attributes)
 
 - 
endpointConfigdefault void endpointConfig(Supplier<EndpointConfig> epBuilder) Shortcut method to setEndpointConfigusing a builder rather than built instance. Shortcut toendpointConfig(EndpointConfig)- Parameters:
- epBuilder- builder of an endpoint configuration
 
 - 
atzCheckedboolean atzChecked() Return true if either of authorization methods (authorize(Object...)oratzClientBuilder()was called). This is a safe-guard for attribute based authorization that is using annotations and requires object to be passed for evaluation.- Returns:
- true if authorization was checked, false otherwise
 
 
- 
 
-