类 MyDefaultTokenServices

  • 所有已实现的接口:
    org.springframework.beans.factory.InitializingBean, org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices, org.springframework.security.oauth2.provider.token.ConsumerTokenServices, org.springframework.security.oauth2.provider.token.ResourceServerTokenServices

    public class MyDefaultTokenServices
    extends Object
    implements org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices, org.springframework.security.oauth2.provider.token.ResourceServerTokenServices, org.springframework.security.oauth2.provider.token.ConsumerTokenServices, org.springframework.beans.factory.InitializingBean
    实现了可以单端登陆功能的服务
    作者:
    zhanglinfeng
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      void afterPropertiesSet()
      Initialize these token services.
      org.springframework.security.oauth2.common.OAuth2AccessToken createAccessToken​(org.springframework.security.oauth2.provider.OAuth2Authentication authentication)  
      org.springframework.security.oauth2.common.OAuth2AccessToken getAccessToken​(org.springframework.security.oauth2.provider.OAuth2Authentication authentication)  
      protected int getAccessTokenValiditySeconds​(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
      The access token validity period in seconds
      String getClientId​(String tokenValue)  
      protected int getRefreshTokenValiditySeconds​(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
      The refresh token validity period in seconds
      protected boolean isExpired​(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken)  
      protected boolean isSupportRefreshToken​(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
      Is a refresh token supported for this client (or the global setting if clientDetailsService is not set.
      org.springframework.security.oauth2.provider.OAuth2Authentication loadAuthentication​(String accessTokenValue)  
      org.springframework.security.oauth2.common.OAuth2AccessToken readAccessToken​(String accessToken)  
      org.springframework.security.oauth2.common.OAuth2AccessToken refreshAccessToken​(String refreshTokenValue, org.springframework.security.oauth2.provider.TokenRequest tokenRequest)  
      boolean revokeToken​(String tokenValue)  
      void setAccessTokenValiditySeconds​(int accessTokenValiditySeconds)
      The default validity (in seconds) of the access token.
      void setAuthenticationManager​(org.springframework.security.authentication.AuthenticationManager authenticationManager)
      An authentication manager that will be used (if provided) to check the user authentication when a token is refreshed.
      void setClientDetailsService​(org.springframework.security.oauth2.provider.ClientDetailsService clientDetailsService)
      The client details service to use for looking up clients (if necessary).
      void setRefreshTokenValiditySeconds​(int refreshTokenValiditySeconds)
      The validity (in seconds) of the refresh token.
      void setReuseRefreshToken​(boolean reuseRefreshToken)
      Whether to reuse refresh tokens (until expired).
      void setSingleClientToken​(boolean singleClientToken)  
      void setSupportRefreshToken​(boolean supportRefreshToken)
      Whether to support the refresh token.
      void setTokenEnhancer​(org.springframework.security.oauth2.provider.token.TokenEnhancer accessTokenEnhancer)
      An access token enhancer that will be applied to a new token before it is saved in the token store.
      void setTokenStore​(org.springframework.security.oauth2.provider.token.TokenStore tokenStore)
      The persistence strategy for token storage.
    • 构造器详细资料

      • MyDefaultTokenServices

        public MyDefaultTokenServices()
    • 方法详细资料

      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws Exception
        Initialize these token services. If no random generator is set, one will be created.
        指定者:
        afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBean
        抛出:
        Exception
      • createAccessToken

        @Transactional
        public org.springframework.security.oauth2.common.OAuth2AccessToken createAccessToken​(org.springframework.security.oauth2.provider.OAuth2Authentication authentication)
                                                                                       throws org.springframework.security.core.AuthenticationException
        指定者:
        createAccessToken 在接口中 org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices
        抛出:
        org.springframework.security.core.AuthenticationException
      • refreshAccessToken

        @Transactional(noRollbackFor={org.springframework.security.oauth2.common.exceptions.InvalidTokenException.class,org.springframework.security.oauth2.common.exceptions.InvalidGrantException.class})
        public org.springframework.security.oauth2.common.OAuth2AccessToken refreshAccessToken​(String refreshTokenValue,
                                                                                               org.springframework.security.oauth2.provider.TokenRequest tokenRequest)
                                                                                        throws org.springframework.security.core.AuthenticationException
        指定者:
        refreshAccessToken 在接口中 org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices
        抛出:
        org.springframework.security.core.AuthenticationException
      • getAccessToken

        public org.springframework.security.oauth2.common.OAuth2AccessToken getAccessToken​(org.springframework.security.oauth2.provider.OAuth2Authentication authentication)
        指定者:
        getAccessToken 在接口中 org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices
      • isExpired

        protected boolean isExpired​(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken)
      • readAccessToken

        public org.springframework.security.oauth2.common.OAuth2AccessToken readAccessToken​(String accessToken)
        指定者:
        readAccessToken 在接口中 org.springframework.security.oauth2.provider.token.ResourceServerTokenServices
      • loadAuthentication

        public org.springframework.security.oauth2.provider.OAuth2Authentication loadAuthentication​(String accessTokenValue)
                                                                                             throws org.springframework.security.core.AuthenticationException,
                                                                                                    org.springframework.security.oauth2.common.exceptions.InvalidTokenException
        指定者:
        loadAuthentication 在接口中 org.springframework.security.oauth2.provider.token.ResourceServerTokenServices
        抛出:
        org.springframework.security.core.AuthenticationException
        org.springframework.security.oauth2.common.exceptions.InvalidTokenException
      • getClientId

        public String getClientId​(String tokenValue)
      • revokeToken

        public boolean revokeToken​(String tokenValue)
        指定者:
        revokeToken 在接口中 org.springframework.security.oauth2.provider.token.ConsumerTokenServices
      • getAccessTokenValiditySeconds

        protected int getAccessTokenValiditySeconds​(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
        The access token validity period in seconds
        参数:
        clientAuth - the current authorization request
        返回:
        the access token validity period in seconds
      • getRefreshTokenValiditySeconds

        protected int getRefreshTokenValiditySeconds​(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
        The refresh token validity period in seconds
        参数:
        clientAuth - the current authorization request
        返回:
        the refresh token validity period in seconds
      • isSupportRefreshToken

        protected boolean isSupportRefreshToken​(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
        Is a refresh token supported for this client (or the global setting if clientDetailsService is not set.
        参数:
        clientAuth - the current authorization request
        返回:
        boolean to indicate if refresh token is supported
      • setTokenEnhancer

        public void setTokenEnhancer​(org.springframework.security.oauth2.provider.token.TokenEnhancer accessTokenEnhancer)
        An access token enhancer that will be applied to a new token before it is saved in the token store.
        参数:
        accessTokenEnhancer - the access token enhancer to set
      • setRefreshTokenValiditySeconds

        public void setRefreshTokenValiditySeconds​(int refreshTokenValiditySeconds)
        The validity (in seconds) of the refresh token. If less than or equal to zero then the tokens will be non-expiring.
        参数:
        refreshTokenValiditySeconds - The validity (in seconds) of the refresh token.
      • setAccessTokenValiditySeconds

        public void setAccessTokenValiditySeconds​(int accessTokenValiditySeconds)
        The default validity (in seconds) of the access token. Zero or negative for non-expiring tokens. If a client details service is set the validity period will be read from the client, defaulting to this value if not defined by the client.
        参数:
        accessTokenValiditySeconds - The validity (in seconds) of the access token.
      • setSupportRefreshToken

        public void setSupportRefreshToken​(boolean supportRefreshToken)
        Whether to support the refresh token.
        参数:
        supportRefreshToken - Whether to support the refresh token.
      • setReuseRefreshToken

        public void setReuseRefreshToken​(boolean reuseRefreshToken)
        Whether to reuse refresh tokens (until expired).
        参数:
        reuseRefreshToken - Whether to reuse refresh tokens (until expired).
      • setTokenStore

        public void setTokenStore​(org.springframework.security.oauth2.provider.token.TokenStore tokenStore)
        The persistence strategy for token storage.
        参数:
        tokenStore - the store for access and refresh tokens.
      • setAuthenticationManager

        public void setAuthenticationManager​(org.springframework.security.authentication.AuthenticationManager authenticationManager)
        An authentication manager that will be used (if provided) to check the user authentication when a token is refreshed.
        参数:
        authenticationManager - the authenticationManager to set
      • setClientDetailsService

        public void setClientDetailsService​(org.springframework.security.oauth2.provider.ClientDetailsService clientDetailsService)
        The client details service to use for looking up clients (if necessary). Optional if the access token expiry is set globally via setAccessTokenValiditySeconds(int).
        参数:
        clientDetailsService - the client details service
      • setSingleClientToken

        public void setSingleClientToken​(boolean singleClientToken)