Spring Security+JWT+OAuth2实现同一账号重复登录时第一次登陆成功的强制下线(包括多平台使用同一个登陆系统的)

OAuth2.0用refresh_token更新access_token令牌 概述 使用oauth2时,如果令牌失效了,可以使用刷新令牌通过refresh_token的授权模式再次获取access_token。只需修改认证服务器的配置,添加refresh_token的授权模式即可。 修改授权服务器配置,增加refresh_token配置 ​ @Autowired private UserService userService; @Override public void configure(AuthorizationServerEndpointsConfigurer endpoint 阅读详情

引言
我们后台项目是用Spring Security+JWT+OAuth2做的安全框架,现在有个需求就是同一账号重复登录时第一次登陆成功的强制下线。尝试了很多方法无果,当时真的是被弄得焦头烂额了。最后功夫不负有心人找到了解决方案,下面跟大家分享下。

单平台
具体实现方案就是重写DefaultTokenServices的createAccessToken方法(下发token的方法)
虽说是重写但是我们新建了一个SingleTokenServices类,将DefaultTokenServices中的方法复制过来,该实现的类也实现,只需要修改createAccessToken方法即可。

 OAuth2AccessToken existingAccessToken = tokenStore.getAccessToken(authentication);
        OAuth2RefreshToken refreshToken = null;
        if (existingAccessToken != null) {
            if (existingAccessToken.isExpired()) {
                if (existingAccessToken.getRefreshToken() != null) {
                    refreshToken = existingAccessToken.getRefreshToken();
                    tokenStore.removeRefreshToken(refreshToken);
                }
            }
            refreshToken = existingAccessToken.getRefreshToken();
            tokenStore.removeRefreshToken(refreshToken);
            tokenStore.removeAccessToken(existingAccessToken);
        }
        refreshToken = createRefreshToken(authentication);
        if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
            ExpiringOAuth2RefreshToken expiring = (ExpiringOAuth2RefreshToken) refreshToken;
            if (System.currentTimeMillis() > expiring.getExpiration().getTime()) {
                refreshToken = createRefreshToken(authentication);
            }
        }
        OAuth2AccessToken accessToken = createAccessToken(authentication, refreshToken);
        tokenStore.storeAccessToken(accessToken, authentication);
        refreshToken = accessToken.getRefreshToken();
        if (refreshToken != null) {
            tokenStore.storeRefreshToken(refreshToken, authentication);
        }
        return accessToken;

最后在你的OAuth2AuthorizationServerConfig类中也要进行一些改动才能生效(**endpoints.tokenServices(tokenServices(endpoints))**是关键),下面列出关键代码。

 @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
        // 设置错误转换
        endpoints.exceptionTranslator(new OAuth2ExceptionTranslator());
        //加入关键代码
        endpoints.tokenServices(tokenServices(endpoints));
        JwtAccessTokenConverter tokenConverter = new OAuth2JwtAccessTokenConverter(userDetailsService);
        // 设置token相关配置
        endpoints.reuseRefreshTokens(false) // 不复用refreshToken 每次刷新token之后返回一个新的accessToken和refreshToken
                .accessTokenConverter(tokenConverter) // 使用Jwt
                .userDetailsService(userDetailsService); // refresh_token时会用到该服务的loadUserByUsername方法

        // 追加自定义的granter
        List<TokenGranter> tokenGranters = new ArrayList<>();
        tokenGranters.add(new OAuth2LoginGranter(
                endpoints.getTokenServices(),
                endpoints.getClientDetailsService(),
                endpoints.getOAuth2RequestFactory(),
                userDetailsService,
                endpoints.getTokenStore()
        ));
        tokenGranters.add(endpoints.getTokenGranter());
        endpoints.tokenGranter(new CompositeTokenGranter(tokenGranters));
    }
    
    @Bean("tokenStore")
    public TokenStore tokenStore() {
        //使用redis的tokenStore,令牌(Access Token)会保存到内存
        return new RedisTokenStore(redisTemplate.getConnectionFactory());
    }

    private SingleTokenServices tokenServices(AuthorizationServerEndpointsConfigurer endpoints) {
        SingleTokenServices tokenServices = new SingleTokenServices();
        tokenServices.setTokenStore(tokenStore());
        tokenServices.setSupportRefreshToken(true);//支持刷新token
        tokenServices.setReuseRefreshToken(true);
        tokenServices.setClientDetailsService(endpoints.getClientDetailsService());
        tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer());
        addUserDetailsService(tokenServices, this.userDetailsService);
        return tokenServices;
    }

    private void addUserDetailsService(SingleTokenServices tokenServices, UserDetailsService userDetailsService) {
        if (userDetailsService != null) {
            PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();
            provider.setPreAuthenticatedUserDetailsService(new UserDetailsByNameServiceWrapper<>(
                    userDetailsService));
            tokenServices.setAuthenticationManager(new ProviderManager(Arrays.asList(provider)));
        }
    }

多平台
具体是指多平台共用一个登陆系统,比如我们的后台有审核后台和管理后台但是公用的是一套代码。解决方案依旧是重写DefaultTokenServices类的createAccessToken方法,介于这种玩法比较少我就直接上代码了。

package com.duanbo.server.oms.oauth2;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.oauth2.common.*;
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
import org.springframework.security.oauth2.common.exceptions.InvalidScopeException;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.security.oauth2.provider.*;
import org.springframework.security.oauth2.provider.token.*;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Date;
import java.util.Set;
import java.util.UUID;


public class SingleTokenServices implements AuthorizationServerTokenServices, ResourceServerTokenServices,
        ConsumerTokenServices, InitializingBean {
    private int refreshTokenValiditySeconds = 60 * 60 * 24 * 30; // default 30 days.

    private int accessTokenValiditySeconds = 60 * 60 * 12; // default 12 hours.

    private boolean supportRefreshToken = false;

    private boolean reuseRefreshToken = true;

    private TokenStore tokenStore;

    private ClientDetailsService clientDetailsService;

    private TokenEnhancer accessTokenEnhancer;

    private AuthenticationManager authenticationManager;

    /**
     * Initialize these token services. If no random generator is set, one will be created.
     */
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(tokenStore, "tokenStore must be set");
    }

    @Transactional
    public OAuth2AccessToken createAccessToken(OAuth2Authentication authentication) throws AuthenticationException {
        //获取当前登录人的信息
        OAuth2UserDetails principal = (OAuth2UserDetails) authentication.getUserAuthentication().getPrincipal();
        //如果当前的ClientId()为audit,并且当前登录的ClientId()和用户id与tokenStore中储存的对应
        if (authentication.getOAuth2Request().getClientId().equals("audit") && tokenStore.findTokensByClientIdAndUserName("audit", "account_password:" + principal.getId()).size() != 0) {
            return reAccessToken(authentication);
        } else if (authentication.getOAuth2Request().getClientId().equals("management") && tokenStore.findTokensByClientIdAndUserName("management", "account_password:" + principal.getId()).size() != 0) {
            return reAccessToken(authentication);
        } else {
            return firstAccessToken(authentication);
        }

    }

    public OAuth2AccessToken reAccessToken(OAuth2Authentication authentication) {
        OAuth2AccessToken existingAccessToken = tokenStore.getAccessToken(authentication);
        OAuth2RefreshToken refreshToken = null;
        if (existingAccessToken != null) {
            if (existingAccessToken.isExpired()) {
                if (existingAccessToken.getRefreshToken() != null) {
                    refreshToken = existingAccessToken.getRefreshToken();
                    tokenStore.removeRefreshToken(refreshToken);
                }
            }
            refreshToken = existingAccessToken.getRefreshToken();
            tokenStore.removeRefreshToken(refreshToken);
            tokenStore.removeAccessToken(existingAccessToken);
        }
        refreshToken = createRefreshToken(authentication);
        if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
            ExpiringOAuth2RefreshToken expiring = (ExpiringOAuth2RefreshToken) refreshToken;
            if (System.currentTimeMillis() > expiring.getExpiration().getTime()) {
                refreshToken = createRefreshToken(authentication);
            }
        }
        OAuth2AccessToken accessToken = createAccessToken(authentication, refreshToken);
        tokenStore.storeAccessToken(accessToken, authentication);
        refreshToken = accessToken.getRefreshToken();
        if (refreshToken != null) {
            tokenStore.storeRefreshToken(refreshToken, authentication);
        }
        return accessToken;
    }

    public OAuth2AccessToken firstAccessToken(OAuth2Authentication authentication) {
        OAuth2AccessToken existingAccessToken = tokenStore.getAccessToken(authentication);
        OAuth2RefreshToken refreshToken = null;
        if (existingAccessToken != null) {
            if (existingAccessToken.isExpired()) {
                if (existingAccessToken.getRefreshToken() != null) {
                    refreshToken = existingAccessToken.getRefreshToken();
                    // The token store could remove the refresh token when the
                    // access token is removed, but we want to
                    // be sure...
                    tokenStore.removeRefreshToken(refreshToken);
                }
                tokenStore.removeAccessToken(existingAccessToken);
            } else {
                // Re-store the access token in case the authentication has changed
                tokenStore.storeAccessToken(existingAccessToken, authentication);
                return existingAccessToken;
            }
        }

        // Only create a new refresh token if there wasn't an existing one
        // associated with an expired access token.
        // Clients might be holding existing refresh tokens, so we re-use it in
        // the case that the old access token
        // expired.
        if (refreshToken == null) {
            refreshToken = createRefreshToken(authentication);
        }
        // But the refresh token itself might need to be re-issued if it has
        // expired.
        else if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
            ExpiringOAuth2RefreshToken expiring = (ExpiringOAuth2RefreshToken) refreshToken;
            if (System.currentTimeMillis() > expiring.getExpiration().getTime()) {
                refreshToken = createRefreshToken(authentication);
            }
        }

        OAuth2AccessToken accessToken = createAccessToken(authentication, refreshToken);
        tokenStore.storeAccessToken(accessToken, authentication);
        // In case it was modified
        refreshToken = accessToken.getRefreshToken();
        if (refreshToken != null) {
            tokenStore.storeRefreshToken(refreshToken, authentication);
        }
        return accessToken;
    }

    @Transactional(noRollbackFor = {InvalidTokenException.class, InvalidGrantException.class})
    public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenRequest tokenRequest)
            throws AuthenticationException {

        if (!supportRefreshToken) {
            throw new InvalidGrantException("Invalid refresh token: " + refreshTokenValue);
        }

        OAuth2RefreshToken refreshToken = tokenStore.readRefreshToken(refreshTokenValue);
        if (refreshToken == null) {
            throw new InvalidGrantException("Invalid refresh token: " + refreshTokenValue);
        }

        OAuth2Authentication authentication = tokenStore.readAuthenticationForRefreshToken(refreshToken);
        if (this.authenticationManager != null && !authentication.isClientOnly()) {
            // The client has already been authenticated, but the user authentication might be old now, so give it a
            // chance to re-authenticate.
            Authentication user = new PreAuthenticatedAuthenticationToken(authentication.getUserAuthentication(), "", authentication.getAuthorities());
            user = authenticationManager.authenticate(user);
            Object details = authentication.getDetails();
            authentication = new OAuth2Authentication(authentication.getOAuth2Request(), user);
            authentication.setDetails(details);
        }
        String clientId = authentication.getOAuth2Request().getClientId();
        if (clientId == null || !clientId.equals(tokenRequest.getClientId())) {
            throw new InvalidGrantException("Wrong client for this refresh token: " + refreshTokenValue);
        }

        // clear out any access tokens already associated with the refresh
        // token.
        tokenStore.removeAccessTokenUsingRefreshToken(refreshToken);

        if (isExpired(refreshToken)) {
            tokenStore.removeRefreshToken(refreshToken);
            throw new InvalidTokenException("Invalid refresh token (expired): " + refreshToken);
        }

        authentication = createRefreshedAuthentication(authentication, tokenRequest);

        if (!reuseRefreshToken) {
            tokenStore.removeRefreshToken(refreshToken);
            refreshToken = createRefreshToken(authentication);
        }

        OAuth2AccessToken accessToken = createAccessToken(authentication, refreshToken);
        tokenStore.storeAccessToken(accessToken, authentication);
        if (!reuseRefreshToken) {
            tokenStore.storeRefreshToken(accessToken.getRefreshToken(), authentication);
        }
        return accessToken;
    }

    public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) {
        return tokenStore.getAccessToken(authentication);
    }

    /**
     * Create a refreshed authentication.
     *
     * @param authentication The authentication.
     * @param request        The scope for the refreshed token.
     * @return The refreshed authentication.
     * @throws InvalidScopeException If the scope requested is invalid or wider than the original scope.
     */
    private OAuth2Authentication createRefreshedAuthentication(OAuth2Authentication authentication, TokenRequest request) {
        OAuth2Authentication narrowed = authentication;
        Set<String> scope = request.getScope();
        OAuth2Request clientAuth = authentication.getOAuth2Request().refresh(request);
        if (scope != null && !scope.isEmpty()) {
            Set<String> originalScope = clientAuth.getScope();
            if (originalScope == null || !originalScope.containsAll(scope)) {
                throw new InvalidScopeException("Unable to narrow the scope of the client authentication to " + scope
                        + ".", originalScope);
            } else {
                clientAuth = clientAuth.narrowScope(scope);
            }
        }
        narrowed = new OAuth2Authentication(clientAuth, authentication.getUserAuthentication());
        return narrowed;
    }

    protected boolean isExpired(OAuth2RefreshToken refreshToken) {
        if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
            ExpiringOAuth2RefreshToken expiringToken = (ExpiringOAuth2RefreshToken) refreshToken;
            return expiringToken.getExpiration() == null
                    || System.currentTimeMillis() > expiringToken.getExpiration().getTime();
        }
        return false;
    }

    public OAuth2AccessToken readAccessToken(String accessToken) {
        return tokenStore.readAccessToken(accessToken);
    }

    public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException,
            InvalidTokenException {
        OAuth2AccessToken accessToken = tokenStore.readAccessToken(accessTokenValue);
        if (accessToken == null) {
            throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
        } else if (accessToken.isExpired()) {
            tokenStore.removeAccessToken(accessToken);
            throw new InvalidTokenException("Access token expired: " + accessTokenValue);
        }

        OAuth2Authentication result = tokenStore.readAuthentication(accessToken);
        if (result == null) {
            // in case of race condition
            throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
        }
        if (clientDetailsService != null) {
            String clientId = result.getOAuth2Request().getClientId();
            try {
                clientDetailsService.loadClientByClientId(clientId);
            } catch (ClientRegistrationException e) {
                throw new InvalidTokenException("Client not valid: " + clientId, e);
            }
        }
        return result;
    }

    public String getClientId(String tokenValue) {
        OAuth2Authentication authentication = tokenStore.readAuthentication(tokenValue);
        if (authentication == null) {
            throw new InvalidTokenException("Invalid access token: " + tokenValue);
        }
        OAuth2Request clientAuth = authentication.getOAuth2Request();
        if (clientAuth == null) {
            throw new InvalidTokenException("Invalid access token (no client id): " + tokenValue);
        }
        return clientAuth.getClientId();
    }

    public boolean revokeToken(String tokenValue) {
        OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
        if (accessToken == null) {
            return false;
        }
        if (accessToken.getRefreshToken() != null) {
            tokenStore.removeRefreshToken(accessToken.getRefreshToken());
        }
        tokenStore.removeAccessToken(accessToken);
        return true;
    }

    private OAuth2RefreshToken createRefreshToken(OAuth2Authentication authentication) {
        if (!isSupportRefreshToken(authentication.getOAuth2Request())) {
            return null;
        }
        int validitySeconds = getRefreshTokenValiditySeconds(authentication.getOAuth2Request());
        String value = UUID.randomUUID().toString();
        if (validitySeconds > 0) {
            return new DefaultExpiringOAuth2RefreshToken(value, new Date(System.currentTimeMillis()
                    + (validitySeconds * 1000L)));
        }
        return new DefaultOAuth2RefreshToken(value);
    }

    private OAuth2AccessToken createAccessToken(OAuth2Authentication authentication, OAuth2RefreshToken refreshToken) {
        DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(UUID.randomUUID().toString());
        int validitySeconds = getAccessTokenValiditySeconds(authentication.getOAuth2Request());
        if (validitySeconds > 0) {
            token.setExpiration(new Date(System.currentTimeMillis() + (validitySeconds * 1000L)));
        }
        token.setRefreshToken(refreshToken);
        token.setScope(authentication.getOAuth2Request().getScope());

        return accessTokenEnhancer != null ? accessTokenEnhancer.enhance(token, authentication) : token;
    }

    /**
     * The access token validity period in seconds
     *
     * @param clientAuth the current authorization request
     * @return the access token validity period in seconds
     */
    protected int getAccessTokenValiditySeconds(OAuth2Request clientAuth) {
        if (clientDetailsService != null) {
            ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
            Integer validity = client.getAccessTokenValiditySeconds();
            if (validity != null) {
                return validity;
            }
        }
        return accessTokenValiditySeconds;
    }

    /**
     * The refresh token validity period in seconds
     *
     * @param clientAuth the current authorization request
     * @return the refresh token validity period in seconds
     */
    protected int getRefreshTokenValiditySeconds(OAuth2Request clientAuth) {
        if (clientDetailsService != null) {
            ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
            Integer validity = client.getRefreshTokenValiditySeconds();
            if (validity != null) {
                return validity;
            }
        }
        return refreshTokenValiditySeconds;
    }

    /**
     * Is a refresh token supported for this client (or the global setting if
     * {@link #setClientDetailsService(ClientDetailsService) clientDetailsService} is not set.
     *
     * @param clientAuth the current authorization request
     * @return boolean to indicate if refresh token is supported
     */
    protected boolean isSupportRefreshToken(OAuth2Request clientAuth) {
        if (clientDetailsService != null) {
            ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
            return client.getAuthorizedGrantTypes().contains("refresh_token");
        }
        return this.supportRefreshToken;
    }

    /**
     * An access token enhancer that will be applied to a new token before it is saved in the token store.
     *
     * @param accessTokenEnhancer the access token enhancer to set
     */
    public void setTokenEnhancer(TokenEnhancer accessTokenEnhancer) {
        this.accessTokenEnhancer = accessTokenEnhancer;
    }

    /**
     * The validity (in seconds) of the refresh token. If less than or equal to zero then the tokens will be
     * non-expiring.
     *
     * @param refreshTokenValiditySeconds The validity (in seconds) of the refresh token.
     */
    public void setRefreshTokenValiditySeconds(int refreshTokenValiditySeconds) {
        this.refreshTokenValiditySeconds = refreshTokenValiditySeconds;
    }

    /**
     * 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.
     *
     * @param accessTokenValiditySeconds The validity (in seconds) of the access token.
     */
    public void setAccessTokenValiditySeconds(int accessTokenValiditySeconds) {
        this.accessTokenValiditySeconds = accessTokenValiditySeconds;
    }

    /**
     * Whether to support the refresh token.
     *
     * @param supportRefreshToken Whether to support the refresh token.
     */
    public void setSupportRefreshToken(boolean supportRefreshToken) {
        this.supportRefreshToken = supportRefreshToken;
    }

    /**
     * Whether to reuse refresh tokens (until expired).
     *
     * @param reuseRefreshToken Whether to reuse refresh tokens (until expired).
     */
    public void setReuseRefreshToken(boolean reuseRefreshToken) {
        this.reuseRefreshToken = reuseRefreshToken;
    }

    /**
     * The persistence strategy for token storage.
     *
     * @param tokenStore the store for access and refresh tokens.
     */
    public void setTokenStore(TokenStore tokenStore) {
        this.tokenStore = tokenStore;
    }

    /**
     * An authentication manager that will be used (if provided) to check the user authentication when a token is
     * refreshed.
     *
     * @param authenticationManager the authenticationManager to set
     */
    public void setAuthenticationManager(AuthenticationManager authenticationManager) {
        this.authenticationManager = authenticationManager;
    }

    /**
     * The client details service to use for looking up clients (if necessary). Optional if the access token expiry is
     * set globally via {@link #setAccessTokenValiditySeconds(int)}.
     *
     * @param clientDetailsService the client details service
     */
    public void setClientDetailsService(ClientDetailsService clientDetailsService) {
        this.clientDetailsService = clientDetailsService;
    }
}

而OAuth2AuthorizationServerConfig类跟单平台的操作一样。其中audit和management对应的是OAuth2AuthorizationServerConfig类中的方法,请看下面的代码。

 @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        // TODO: 提高密码安全级别
        // TODO: 为前端重新配置一个账号密码
        clients.inMemory()
                .withClient("management")
                .secret(passwordEncoder().encode(""))
                .authorizedGrantTypes("refresh_token", OAuth2LoginGranter.GRANT_TYPE)
                .scopes("ALL")
                .accessTokenValiditySeconds(604800)
                .refreshTokenValiditySeconds(2592000)
                .and()
                .withClient("audit")
                .secret(passwordEncoder().encode(""))
                .authorizedGrantTypes("refresh_token", OAuth2LoginGranter.GRANT_TYPE)
                .scopes("ALL")
                .accessTokenValiditySeconds(604800)
                .refreshTokenValiditySeconds(2592000);
    }
如何实现同一个账号多端登录强制下线的功能 阅读详情

相关推荐

springboot实现一个账号同时只能登录一个设备,其他设备登录登录之前登录的账号强制下线

这里每次登录的时候不仅会将token返回给前端,同时也会将token存到数据库里。目的就是通过对token的比较判断用户是否已经登录,如果数据库里有token,并且数据库里的token和此次登录的token不一致,说明已经有用户登录过了,此次登录的时候就会更新数据库里的token,之前登录的用户的登录状态就会失效了。因为没有使用redis,使用jwt生成的token也不会存在redis,将登录信息生成token,将生成的token以及用户信息一并返回给前端,前端每次访问后端的接口都会携带token过来。

2301_80333628的博客 2287

SSO&OAuth2.0&JWT

SSO单点登录是为了解决一个用户在鉴权服务器登陆过一次以后,可以在任何应用中畅通无阻,一次登陆,多系统访问在此之前引入一个问题https本身数据传输就是加密的,已经防止了数据篡改和数据窃和防止钓鱼网站等,那为什么token还要加密?解答:有一台机器当访问的入口,要放在公网上(类似nginx)。但是内网传输数据采用的是http协议,可以防止内网泄露数据或者内部人员泄露数据。同时数据多次加密,增加破解难度。

qq_47075878的博客 992

解决重复登陆问题

解决重复登陆问题@@@@@@

JWT 续期和服务下线

传统httpsession和spring-session都是采用httpsession默认机制。内部会有线程不停的轮询会话列表。把那些内存中的会话列表中的过期时间和当前时间进行比较,如果超过> 30分钟 自动把session删除。如果在30以内的请求,会自动续期(时间会从0开始计数)。为什么要这样做?你思考。如果没有续期,会怎么样?就好比你登录腾讯游戏,你登录有效时间是30分钟。那么也就意味着你每隔30分钟要退出重新登录一次。所以我们应该是在你登录以后,未来的每一次请求中,只要用户一直在发起请求,就把时间永

L的博客 1011

DEA-Malmquist指数模型实战:从理论到应用的全流程解析

本文全面解析了DEA-Malmquist指数模型从理论到应用的全流程。文章详细阐述了该模型如何动态衡量效率随时间的变化,并将其分解为技术效率变化与技术进步,从而精准定位效率变动的根源。通过实战步骤演示了数据准备、软件操作(如DEAP 2.1)及结果解读,并结合水资源环境效率等案例,展示了其在包含非期望产出时的应用价值,为研究者进行动态效率分析提供了清晰指南。

b0c1d2的博客 220

sap外币重估流程图_SAP 外币评估方法(Valuation Method,评估方法)

在FI-GL模块评估外币时(T-code:F.05),需要输入ValuationMethod。下面分解一下评估方法是如何定义的。IMG -> FI -> General LedgerAccounting ->Business Transactions ->Closing ->Valuating -> ForeignCurrency Valuation ->...

weixin_39640543的博客 2355

jwt+shiro实现登录强制下线

其实这个东西你只需要在登录的时候重新刷新accessToken和refreshToken就行了,因为所有的请求都会携带accessToken和refreshToken,并且都会走shiro的请求拦截器,我在这个shiro请求拦截器中对这两个token做比较,如果refreshToken过期了(不相同就代表过期)的话就直接让前端跳转登录页面就行了 登录: @Override publ...

myllxy 2547

DIY电子管耳放实战:12AU7+6V6GT组合的电路设计与调试心得

本文详细分享了DIY电子管耳放的实战经验,重点解析了12AU7与6V6GT经典组合的电路设计、元件选型与调试过程。内容涵盖从核心架构设计、关键元件(如输出变压器、耦合电容)的科学选型,到静态工作点设置、负反馈引入及常见噪声问题的排查,旨在帮助音响DIY爱好者和电子管放大器初学者成功打造一台低失真、高信噪比且富有“胆味”的耳机放大器,享受动手制作的乐趣与温暖音质。

weixin_29230805的博客 552

refreshToken刷新token后会变化的原因以及refreshToken的复用

refreshToken刷新token后会变化的原因以及refreshToken的复用 两次使用refreshToken刷新token返回的refreshToken如下: 将两次返回的refreshToken解密后可以看到。处理ati不一样,其它参数都是一样的 ati(access token):新的访问令牌的id jti : refreshToken 的id 既然刷出了新的token,那么ati肯定变了,那么由这些信息加密成的refreshToken自然也是一直变化的 那么如果想无限制刷新refres

weixin_43757027的博客 7194

OpenCV实战(1)——OpenCV与图像处理基础

OpenCV 是一个跨平台计算机视觉和机器学习库,实现了图像处理和计算机视觉方面的很多通用算法。本节将介绍 OpenCV 的基础知识,以及如何编译运行 OpenCV 程序,并介绍如何完成最基本的图像处理任务——读取、显示和保存图像。除此之外,鼠标事件和图形绘制也是 OpenCV 计算机视觉项目中常用的基本功能,本节介绍了如何使用这两个重要的 OpenCV 功能。

盼小辉丶的博客 12万+

威纶通触摸屏与S7-1200以太网通信的具体方法和步骤(非常详细)

威纶通触摸屏与S7-1200以太网通信的具体方法和步骤(非常详细)

Robot_PLC_HMI_Automation 1万+

场景-JWT无状态有什么问题考虑过吗?强制让用户下线怎么弄?

3.可以使用缓存创建一个Token黑名单,把客观上需要注销的token存入即可;2.注销时从客户端删除存储的token;1.合理的设置令牌过期时间;

qq_74763440的博客 214

手把手教你学Simulink——基于Simulink的多用户MIMO系统仿真建模示例

多用户MIMO概述在多用户MIMO系统中,基站配备多个天线,可以同时与多个用户进行通信。利用空间复用技术,不同用户的信号被分配到不同的空间流上,从而实现频谱资源的高效利用。多用户MIMO的核心挑战包括信道估计、波束成形设计以及干扰管理。关键技术点波束成形:通过调整发射信号的相位和幅度,在特定方向上增强信号强度并减少干扰。信道估计:获取每个用户的信道状态信息(CSI),用于优化波束成形矩阵。调制与解调:选择合适的调制方式(如QPSK、16-QAM等)以适应不同用户的信道条件。干扰消除。

MHD0815的博客 268

SpringBoot集成SpringSecurity5和OAuth2 — 5、OAuth2集成JWT

SpringBoot集成SpringSecurity5和OAuth2 — 5、OAuth2集成JWT

Mr_XiMu的博客 3117

【实验必备】对AffectNet数据集进行人脸对齐的小Demo

本文首先简单介绍了AffectNet数据集,及人脸关键点等背景知识,接着Po出了人脸对齐的代码及效果展示。注:本文代码参考自FG2021的Emotion-GCN的开源代码,具有一定的可靠性,欢迎大家学习!

信小海 2666

linux系统宝塔服务器temp文件夹里总是被上传病毒php脚本

服务器时不时的会发送短信说你服务器有病毒,找到了这个tmp文件,删除了之后又有了。确实是有很多人就这么无聊,每天都攻击你的服务器。找了很久的原因,网上也提供了一大堆方法,但都是很简陋的答案,具体怎么操作并没有说。没办法只能自己去排查这个问题。从两个角度来考虑,第一是服务器系统问题,比如宝塔的漏洞。但一时半会看不出问题来。只能去排查自己的项目代码。最后了解到代码确实是存在漏洞的。但代码中也确实了很多的校验,为什么会存在漏洞了?这就不得不从上传的过程开始说起。

guiplan 1496

Spring Security OAuth2 实现登录互踢

Spring Security OAuth2 实现登录互踢 工作中遇到的问题,通过网上查找资料,解决问题,记录一下,防止丢失。 1、重写DefaultTokenServices中的方法 ​ 自定义一个TokenService类继承DefaultTokenServices,重写里面的createAccessToken、setTokenStore和setTokenEnhancer方法,代码如下: public class TokenService extends DefaultTokenServices {

weixin_52996020的博客 1741

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

SpringBoot集成WebSocket实现单用户登录(强制下线)

SpringBoot集成WebSocket实现单用户登录(强制下线)

xiaosong2001的博客 3848

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

SpringBoot限制用户同时在线,顶下上一次登录

业务的实现主要利用了ServletContext的性质。 Servlet Context 是Servlet中最大的一个接口 一个全局的储存信息的空间 生命周期伴随服务器的运行周期 比较:①一个用户可有多个request ②一个用户只能有一个session ③所有用户公用一个servletContext 为了节省空间,提高效率,ServletContext中存储必要的、所有用户需要共享的、安全的信息。 验证登录时,需要进行如下步骤。 // 在服务器端作用域appl

hosheaw的博客 2341

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

「JWT 令牌」玩到极致

唐玄奘就好比客户端,通关文牒就好比 JWT 令牌,经过的每个国家就好比集群中的微服务。唐玄奘借助 JWT 令牌的认证授权模式,一路通关,最终取得真经,是不是很酷呀~

xiaoqi270620903的专栏 492

踢人下线是什么意思?JWT的双Token怎么实现踢人下线。怎么防止被篡改。Token登出怎么处理。

"踢人下线"是指强制终止某个用户的登录状态,使其需要重新登录才能继续访问系统。这在以下场景中很常见:管理员强制下线某个用户检测到异常登录行为用户修改密码后使旧会话失效账号被封禁时。

m0_75265256的博客 709

springboot+redis+session相同用户只能登陆一次,前者会被挤下线(类似QQ)

1.springbootWeb项目 引包 <!--redis--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> .

bobo_supper的博客 3194

SpringSecurity OAuth2中关于创建Token的实现类DefaultTokenServices及TokenStore实现类的详解

5、AuthorizationServerTokenServices 生成Token   AuthorizationServerTokenServices接口提供了创建Token、刷新Token、获取Token的方法,如下所示: public interface AuthorizationServerTokenServices { OAuth2AccessToken createAccessToken(OAuth2Authentication authentication) throws Authent

向心行者 6047

spring security & oauth2 安全认证机制

基本概念: (1) Third-party application:第三方应用程序,本文中又称"客户端"(client),即上一节例子中的"云冲印"。 (2)HTTP service:HTTP服务提供商,本文中简称"服务提供商",即上一节例子中的Google。 (3)Resource Owner:资源所有者,本文中又称"用户"(user)。 (4)User Agent:用户代理,本文中就是指浏览器...

dulabing的专栏 1705

Spring Security OAuth2 Opaque 令牌的简单使用指南

在本文中,我们使用Spring Authorization Server设置OAuth2授权服务器,并学习了如何配置基于 Spring Security 的资源服务器应用程序来验证不透明令牌。

new_ord的博客 2540
上一篇: mybatis-plus打印sql日志和参数到日志文件
下一篇: springboot中使用@Async
IT油条
博客等级 码龄15年 35粉丝 20原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值