Package io.quarkus.vertx.http.security
Interface HttpSecurity
- All Known Implementing Classes:
HttpSecurityImpl
@Experimental("This API is currently experimental and might get changed")
public interface HttpSecurity
A CDI event that facilitates programmatic path-specific authorization setup.
The event can be observed with synchronous observer method like in the example below:
import jakarta.enterprise.event.Observes;
public class HttpSecurityConfiguration {
void observe(@Observes HttpSecurity httpSecurity) {
httpSecurity
.path("/admin/*").basic().roles("admin")
.path("/user/*").form().roles("user")
.path("/public/*").permit();
// and:
httpSecurity.path("/root*").authorization()
.policy(identity -> "root".equals(identity.getPrincipal().getName()));
}
}
If multiple path-patterns matches an incoming request path, the most specific pattern wins.
Expected behavior for the programmatic configuration is very much same as for the HTTP permissions
specified in the 'application.properties' file.
For example following configuration properties:
quarkus.http.auth.permission.deny1.paths=/forbidden
quarkus.http.auth.permission.deny1.policy=deny
can be also written as:
httpSecurity.path("/forbidden").authorization().deny();
Programmatic setup for the management interface is currently not supported.
This CDI event is fired when the runtime configuration is ready,
therefore you can inject configuration properties like this:
import jakarta.enterprise.event.Observes;
import io.quarkus.vertx.http.security.HttpSecurity;
import org.eclipse.microprofile.config.inject.ConfigProperty;
public class HttpSecurityConfiguration {
void configure(@Observes HttpSecurity httpSecurity, @ConfigProperty(name = "admin1-role") String admin1) {
httpSecurity.rolesMapping("admin", admin1);
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents HTTP request authorization.static interfaceRepresents authorization and authentication requirements for given path patterns. -
Method Summary
Modifier and TypeMethodDescriptionbasic()Registers the Basic authentication mechanism in addition to all other global authentication mechanisms.Registers the Basic authentication mechanism in addition to all other global authentication mechanisms.This method is a shortcut forpath(path).methods("DELETE").This method is a shortcut forpath(path).methods("GET").mechanism(HttpAuthenticationMechanism mechanism) Registers givenHttpAuthenticationMechanismin addition to all other global authentication mechanisms.mTLS()Registers the mutual TLS client authentication mechanism in addition to all other global authentication mechanisms.mTLS(MtlsAuthenticationMechanism mTLSAuthenticationMechanism) Registers the mutual TLS client authentication mechanism in addition to all other global authentication mechanisms.mTLS(io.vertx.core.http.ClientAuth tlsClientAuth) Registers the mutual TLS client authentication mechanism in addition to all other global authentication mechanisms.Registers the mutual TLS client authentication mechanism in addition to all other global authentication mechanisms.CreatesHttpSecurity.HttpPermissionin addition to the permissions configured in the 'application.properties' file.This method is a shortcut forpath(path).methods("POST").This method is a shortcut forpath(path).methods("PUT").rolesMapping(String sourceRole, String targetRole) rolesMapping(String sourceRole, List<String> targetRoles) rolesMapping(Map<String, List<String>> roleToRoles) Map the `SecurityIdentity` roles to deployment specific roles and add the matching roles to `SecurityIdentity`.
-
Method Details
-
mechanism
Registers givenHttpAuthenticationMechanismin addition to all other global authentication mechanisms.- Parameters:
mechanism-HttpAuthenticationMechanism- Returns:
- HttpSecurity
-
basic
HttpSecurity basic()Registers the Basic authentication mechanism in addition to all other global authentication mechanisms. This method is a shortcut formechanism(Basic.create()).- Returns:
- HttpSecurity
-
basic
Registers the Basic authentication mechanism in addition to all other global authentication mechanisms. This method is a shortcut formechanism(Basic.realm(authenticationRealm)).- Parameters:
authenticationRealm- see the 'quarkus.http.auth.realm' configuration property- Returns:
- HttpSecurity
-
mTLS
HttpSecurity mTLS()Registers the mutual TLS client authentication mechanism in addition to all other global authentication mechanisms. This method is a shortcut formTLS(ClientAuth.REQUIRED), therefore the client authentication is required.- Returns:
- HttpSecurity
- See Also:
-
mTLS
Registers the mutual TLS client authentication mechanism in addition to all other global authentication mechanisms. The TLS configuration is registered against the registry and is used by the HTTP server for the TLS communication. This method is a shortcut for thehttpSecurity.mTLS(MTLS.required(tlsConfigurationName, tlsConfiguration)), therefore the client authentication is required.- Parameters:
tlsConfigurationName- the name of the configuration, cannot benull, cannot be<default>tlsConfiguration- the configuration cannot benull- Returns:
- HttpSecurity
- See Also:
-
mTLS
Registers the mutual TLS client authentication mechanism in addition to all other global authentication mechanisms.- Parameters:
mTLSAuthenticationMechanism-MtlsAuthenticationMechanismbuild with theMTLSAPI- Returns:
- HttpSecurity
-
mTLS
Registers the mutual TLS client authentication mechanism in addition to all other global authentication mechanisms. If you need to define the client certificate attribute value to role mappings, please use theMTLSbuilder.- Parameters:
tlsClientAuth- eitherClientAuth.REQUESTorClientAuth.REQUIRED; for more information, see theVertxHttpBuildTimeConfig.tlsClientAuth()configuration property- Returns:
- HttpSecurity
-
path
CreatesHttpSecurity.HttpPermissionin addition to the permissions configured in the 'application.properties' file.- Parameters:
paths- path patterns; this is programmatic analogy to the 'quarkus.http.auth.permission."permissions".paths' configuration property, same rules apply- Returns:
- new
HttpSecurity.HttpPermission
-
get
This method is a shortcut forpath(path).methods("GET").- See Also:
-
put
This method is a shortcut forpath(path).methods("PUT").- See Also:
-
post
This method is a shortcut forpath(path).methods("POST").- See Also:
-
delete
This method is a shortcut forpath(path).methods("DELETE").- See Also:
-
rolesMapping
Map the `SecurityIdentity` roles to deployment specific roles and add the matching roles to `SecurityIdentity`. Programmatic analogy to the 'quarkus.http.auth.roles-mapping."role-name"' configuration property. If the configuration property is already set, invocation of this method fails as both methods are mutually exclusive. -
rolesMapping
- See Also:
-
rolesMapping
- See Also:
-