com.holonplatform.spring.security

## Interface SpringSecurity

-     public interface SpringSecurity

  Entry point interface to deal with Spring Security integration with the Holon platform authentication and authorization architecture.

  A set of buider methods is provided to setup a bridge from the Holon platform authentication and authorization API and the Spring Security architecture.

  Since:
    5.1.0

- - ### Method Summary

    All Methods Static Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Authenticator<AccountCredentialsToken>` | `accountCredentialsAuthenticator(org.springframework.security.authentication.AuthenticationManager authenticationManager)` Create an `Authenticator` for the default `AccountCredentialsToken`, using the Spring Security `AuthenticationManager` to perform the authentication operations.
    `static Authentication` | `asAuthentication(org.springframework.security.core.Authentication authentication)` Get the `Authentication` representation of the given Spring Security Authentication.
    `static SpringSecurityAuthenticationToken` | `asAuthenticationToken(org.springframework.security.core.Authentication authentication)` Create a new `AuthenticationToken` using given Spring Security `Authentication` as concrete authentication token.
    `static SpringSecurityAuthenticationToken` | `asAuthenticationToken(String accountId, String secret)` Create an account credentials authentican token, using the Spring Security `UsernamePasswordAuthenticationToken` as concrete authentication token.
    `static org.springframework.security.core.GrantedAuthority` | `asAuthority(Permission permission)` Get the Spring Security `GrantedAuthority` representation of the given `Permission`.
    `static Permission` | `asPermission(org.springframework.security.core.GrantedAuthority authority)` Get the `Permission` representation of the given Spring Security `GrantedAuthority`.
    `static AuthContext` | `authContext()` Create an `AuthContext` which uses the Spring Security `SecurityContext` as authentication holder.
    `static AuthContext` | `authContext(org.springframework.security.authentication.AuthenticationManager authenticationManager)` Create an `AuthContext` which uses the Spring Security `SecurityContext` as authentication holder.
    `static AuthContext` | `authContext(org.springframework.security.authentication.AuthenticationManager authenticationManager, boolean accountCredentialsAuthenticator)` Create an `AuthContext` which uses the Spring Security `SecurityContext` as authentication holder.
    `static AuthContext` | `authContext(Realm realm)` Create an `AuthContext` which uses the Spring Security `SecurityContext` as authentication holder.
    `static <T extends AuthenticationToken,A extends org.springframework.security.core.Authentication> org.springframework.security.authentication.AuthenticationProvider` | `authenticationProvider(Authenticator<T> authenticator, Class<A> authenticationType, Function<A,T> converter)` Create a Spring Security `AuthenticationProvider` using an `Authenticator` as concrete authentication provider.
    `static Authenticator<SpringSecurityAuthenticationToken>` | `authenticator(org.springframework.security.authentication.AuthenticationManager authenticationManager)` Create an `Authenticator` which supports `SpringSecurityAuthenticationToken` types and uses the Spring Security `AuthenticationManager` to perform the authentication operations.

- - ### Method Detail

    - #### authContext

          static AuthContext authContext()

      Create an `AuthContext` which uses the Spring Security `SecurityContext` as authentication holder. The default `SecurityContextHolder.getContext()` method is used to obtain the Spring Security `SecurityContext` reference.

      The `AuthContext` is bound to a default `Realm` instance, configured with the default `Authorizer`.

      Returns:
        A new `AuthContext` using the Spring Security `SecurityContext` as authentication holder
      See Also:
        `authContext(Realm)`

    - #### authContext

          static AuthContext authContext(Realm realm)

      Create an `AuthContext` which uses the Spring Security `SecurityContext` as authentication holder. The default `SecurityContextHolder.getContext()` method is used to obtain the Spring Security `SecurityContext` reference.
      Parameters:
        `realm` - The `Realm` to which the auth context is bound (not null)
      Returns:
        A new `AuthContext` bound to given realm and using the Spring Security `SecurityContext` as authentication holder

    - #### authContext

          static AuthContext authContext(org.springframework.security.authentication.AuthenticationManager authenticationManager)

      Create an `AuthContext` which uses the Spring Security `SecurityContext` as authentication holder. The default `SecurityContextHolder.getContext()` method is used to obtain the Spring Security `SecurityContext` reference.

      A default `Realm` is created using the default authorizer and registering an `Authenticator` hich supports `SpringSecurityAuthenticationToken` types and uses the Spring Security `AuthenticationManager` to perform the authentication operations.

      Parameters:
        `authenticationManager` - The Spring Security `AuthenticationManager` (not null)
      Returns:
        A new `AuthContext` instance
      See Also:
        `authContext(Realm)`

    - #### authContext

          static AuthContext authContext(org.springframework.security.authentication.AuthenticationManager authenticationManager,
                                         boolean accountCredentialsAuthenticator)

      Create an `AuthContext` which uses the Spring Security `SecurityContext` as authentication holder. The default `SecurityContextHolder.getContext()` method is used to obtain the Spring Security `SecurityContext` reference.

      A default `Realm` is created using the default authorizer and registering an `Authenticator` hich supports `SpringSecurityAuthenticationToken` types and uses the Spring Security `AuthenticationManager` to perform the authentication operations.

      Parameters:
        `authenticationManager` - The Spring Security `AuthenticationManager` (not null)
        `accountCredentialsAuthenticator` - Whether to register in Realm an Authenticator for the default `AccountCredentialsToken` which uses the Spring Security `AuthenticationManager` to perform the authentication operations.
      Returns:
        A new `AuthContext` instance
      See Also:
        `authContext(Realm)`

    - #### authenticator

          static Authenticator<SpringSecurityAuthenticationToken> authenticator(org.springframework.security.authentication.AuthenticationManager authenticationManager)

      Create an `Authenticator` which supports `SpringSecurityAuthenticationToken` types and uses the Spring Security `AuthenticationManager` to perform the authentication operations. The `SpringSecurityAuthenticationToken.getAuthentication()` reference is used as authentication token whithin the Spring Security environment.
      Parameters:
        `authenticationManager` - The Spring Security `AuthenticationManager` (not null)
      Returns:
        The new `Authenticator` instance

    - #### accountCredentialsAuthenticator

          static Authenticator<AccountCredentialsToken> accountCredentialsAuthenticator(org.springframework.security.authentication.AuthenticationManager authenticationManager)

      Create an `Authenticator` for the default `AccountCredentialsToken`, using the Spring Security `AuthenticationManager` to perform the authentication operations.
      Parameters:
        `authenticationManager` - The Spring Security `AuthenticationManager` (not null)
      Returns:
        The new `Authenticator` instance

    - #### authenticationProvider

          static <T extends AuthenticationToken,A extends org.springframework.security.core.Authentication> org.springframework.security.authentication.AuthenticationProvider authenticationProvider(Authenticator<T> authenticator,
                                                                                                                                                                                                      Class<A> authenticationType,
                                                                                                                                                                                                      Function<A,T> converter)

      Create a Spring Security `AuthenticationProvider` using an `Authenticator` as concrete authentication provider. Authentication execeptions translation is applied by default.
      Type Parameters:
        `T` - Authentication token type
        `A` - Spring Security `Authentication` type
      Parameters:
        `authenticator` - The concrete `Authenticator`
        `authenticationType` - Supported Spring Security `Authentication` type
        `converter` - Function to convert the Spring Security `Authentication` into the required `AuthenticationToken` type
      Returns:
        A new `AuthenticationProvider` using given `Authenticator`

    - #### asAuthentication

          static Authentication asAuthentication(org.springframework.security.core.Authentication authentication)

      Get the `Authentication` representation of the given Spring Security Authentication.

      If authentication details are available through `Authentication.getDetails()`, it will be available as an `Authentication` parameter with name `SpringSecurityAuthentication.AUTHENTICATION_DETAILS_KEY`.

      Parameters:
        `authentication` - The Spring Security Authentication (not null)
      Returns:
        The `Authentication` representation of the Spring Security Authentication

    - #### asPermission

          static Permission asPermission(org.springframework.security.core.GrantedAuthority authority)

      Get the `Permission` representation of the given Spring Security `GrantedAuthority`.
      Parameters:
        `authority` - The `GrantedAuthority` to be represented as a `Permission` (not null)
      Returns:
        The `Permission` representation of the Spring Security `GrantedAuthority`

    - #### asAuthority

          static org.springframework.security.core.GrantedAuthority asAuthority(Permission permission)

      Get the Spring Security `GrantedAuthority` representation of the given `Permission`.
      Parameters:
        `permission` - The `Permission` to be represented as a `GrantedAuthority` (not null)
      Returns:
        The Spring Security `GrantedAuthority` representation of given `Permission`

    - #### asAuthenticationToken

          static SpringSecurityAuthenticationToken asAuthenticationToken(org.springframework.security.core.Authentication authentication)

      Create a new `AuthenticationToken` using given Spring Security `Authentication` as concrete authentication token.
      Parameters:
        `authentication` - the Spring Security `Authentication` token (not null)
      Returns:
        A new `SpringSecurityAuthenticationToken`

    - #### asAuthenticationToken

          static SpringSecurityAuthenticationToken asAuthenticationToken(String accountId,
                                                                         String secret)

      Create an account credentials authentican token, using the Spring Security `UsernamePasswordAuthenticationToken` as concrete authentication token.
      Parameters:
        `accountId` - Account id (username)
        `secret` - Account secret (password)
      Returns:
        A new `SpringSecurityAuthenticationToken` with given account credentials

Copyright © 2019 The Holon Platform. All rights reserved.