Class SAPOfflineTokenServicesCloud

  • All Implemented Interfaces:
    org.springframework.beans.factory.InitializingBean, org.springframework.security.oauth2.provider.token.ResourceServerTokenServices

    public class SAPOfflineTokenServicesCloud
    extends Object
    implements org.springframework.security.oauth2.provider.token.ResourceServerTokenServices, org.springframework.beans.factory.InitializingBean
    This constructor requires a dependency to spring-security-oauth2, which is deprecated.
     
     <dependency>
         <groupId>org.springframework.security.oauth</groupId>
         <artifactId>spring-security-oauth2</artifactId>
         <scope>provided</scope>
     </dependency>
     <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-beans</artifactId>
         <scope>provided</scope>
     </dependency>
     
     
    By default it used Apache Rest Client for communicating with the OAuth2 Server.

    When used in conjunction with Java Http Servlets, the HttpServletRequest.getRemoteUser() will be filled with either the user_name claim of the token or the client id (azp) if it is not an user token.

    Spring Security framework initializes the SecurityContext with the OAuth2Authentication which is provided as part of loadAuthentication(java.lang.String) method.
    This gives you the following options:
    • All Spring security features are supported that uses SecurityContext.getAuthentication()
    • You can access the Authentication via SecurityContextHolder.getContext() also within asynchronous threads.
    • You can access the Token via SpringSecurityContext.getToken() also within asynchronous threads.
    • Constructor Detail

      • SAPOfflineTokenServicesCloud

        public SAPOfflineTokenServicesCloud()
        Constructs an instance which is preconfigured for XSUAA service configuration from SAP CP Environment.
      • SAPOfflineTokenServicesCloud

        public SAPOfflineTokenServicesCloud​(OAuth2ServiceConfiguration serviceConfiguration,
                                            org.springframework.web.client.RestOperations restOperations)
        Constructs an instance with custom configuration and rest template.
        Parameters:
        serviceConfiguration - the service configuration. You can use Environments in order to load service configuration from the binding information in your environment.
        restOperations - the spring rest template
    • Method Detail

      • loadAuthentication

        public org.springframework.security.oauth2.provider.OAuth2Authentication loadAuthentication​(@Nonnull
                                                                                                    String accessToken)
                                                                                             throws org.springframework.security.core.AuthenticationException,
                                                                                                    org.springframework.security.oauth2.common.exceptions.InvalidTokenException
        Specified by:
        loadAuthentication in interface org.springframework.security.oauth2.provider.token.ResourceServerTokenServices
        Throws:
        org.springframework.security.core.AuthenticationException
        org.springframework.security.oauth2.common.exceptions.InvalidTokenException
      • afterPropertiesSet

        public void afterPropertiesSet()
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      • readAccessToken

        public org.springframework.security.oauth2.common.OAuth2AccessToken readAccessToken​(String accessToken)
        Specified by:
        readAccessToken in interface org.springframework.security.oauth2.provider.token.ResourceServerTokenServices
      • setLocalScopeAsAuthorities

        public SAPOfflineTokenServicesCloud setLocalScopeAsAuthorities​(boolean extractLocalScopesOnly)
        This method allows to overwrite the default behavior of the authorities converter implementation.
        Parameters:
        extractLocalScopesOnly - true when only local scopes are extracted. Local scopes means that non-application specific scopes are filtered out and scopes are returned without appId prefix, e.g. "Display".
        Returns:
        the token authenticator itself