Package io.jmix.core.security
Interface SystemAuthenticator
- All Known Implementing Classes:
SystemAuthenticatorImpl
public interface SystemAuthenticator
Provides ad-hoc authentication, i.e. allows you to execute code on behalf of the 'system' or a specified user.
Example usage:
authenticator.runWithSystem(() -> {
// valid current thread's authentication presents here
});
or
authenticator.begin();
try {
// valid current thread's authentication presents here
} finally {
authenticator.end();
}
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceOperation with a result to be used inwithSystem(AuthenticatedOperation)andwithUser(String, AuthenticatedOperation). -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.core.Authenticationbegin()Authenticate as the 'system' user.org.springframework.security.core.AuthenticationBegins an authenticated code block.voidend()End of an authenticated code block.voidrunWithSystem(Runnable operation) Execute code as the 'system' user.voidrunWithUser(String login, Runnable operation) Execute code on behalf of the specified user.<T> TwithSystem(SystemAuthenticator.AuthenticatedOperation<T> operation) Execute code as the 'system' user and return a result.<T> TwithUser(String login, SystemAuthenticator.AuthenticatedOperation<T> operation) Execute code on behalf of the specified user and return a result.
-
Method Details
-
begin
Begins an authenticated code block.
Saves the current thread session on a stack to get it back onend(). Subsequentend()method must be called in "finally" section.- Parameters:
login- user login. If null, authenticates as the 'system' user.- Returns:
- populated
Authenticationobject
-
begin
org.springframework.security.core.Authentication begin()Authenticate as the 'system' user.
Same asbegin(String)with null parameter. -
end
void end()End of an authenticated code block.
The previous session (or null) is set to security context. Must be called in "finally" section of a try/finally block. -
withUser
Execute code on behalf of the specified user and return a result.- Parameters:
login- user login. If null, the system session is used.operation- code to execute- Returns:
- result of the execution
-
runWithUser
Execute code on behalf of the specified user.- Parameters:
login- user login. If null, the system session is used.operation- code to execute
-
withSystem
Execute code as the 'system' user and return a result.- Parameters:
operation- code to execute- Returns:
- result of the execution
-
runWithSystem
Execute code as the 'system' user.- Parameters:
operation- code to execute
-