shiro (6) 분포 식 응용 감 권 방식 의 Shiro 통합 SpringBoot 에서 사용자 정의 SessionId
                                            
 2806 단어  shiro
                    
public class RandomSessionIdGenerator implements SessionIdGenerator {
    private static final Logger log = LoggerFactory.getLogger(RandomSessionIdGenerator.class);
    private static final String RANDOM_NUM_GENERATOR_ALGORITHM_NAME = "SHA1PRNG";
    private Random random;
    public RandomSessionIdGenerator() {
        try {
            this.random = java.security.SecureRandom.getInstance(RANDOM_NUM_GENERATOR_ALGORITHM_NAME);
        } catch (java.security.NoSuchAlgorithmException e) {
            log.debug("The SecureRandom SHA1PRNG algorithm is not available on the current platform.  Using the " +
                    "platform's default SecureRandom algorithm.", e);
            this.random = new java.security.SecureRandom();
        }
    }
    public Random getRandom() {
        return this.random;
    }
    public void setRandom(Random random) {
        this.random = random;
    }
    /**
     * Returns the String value of the configured {@link Random}'s {@link Random#nextLong() nextLong()} invocation.
     *
     * @param session the {@link Session} instance to which the ID will be applied.
     * @return the String value of the configured {@link Random}'s {@link Random#nextLong()} invocation.
     */
    public Serializable generateId(Session session) {
        //ignore the argument - just call the Random:
        return Long.toString(getRandom().nextLong());
    }
}
public class JavaUuidSessionIdGenerator implements SessionIdGenerator {
    /**
     * Ignores the method argument and simply returns
     * {@code UUID}.{@link java.util.UUID#randomUUID() randomUUID()}.{@code toString()}.
     *
     * @param session the {@link Session} instance to which the ID will be applied.
     * @return the String value of the JDK's next {@link UUID#randomUUID() randomUUID()}.
     */
    public Serializable generateId(Session session) {
        return UUID.randomUUID().toString();
    }
}
    /**
     *    session   
     * @return
     */
    public RedisSessionDAO redisSessionDAO(){
        RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
        redisSessionDAO.setRedisManager(getRedisManager());
        //  sessionid   
        redisSessionDAO.setSessionIdGenerator(new CustomSessionIdGenerator());
        return redisSessionDAO;
    }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
shiro 권한 부여Shiro 는 세 가지 방식 의 인증 을 지원 합 니 다. 본 교육 프로그램 은 첫 번 째 프로 그래 밍 방식 을 사용 하고 실제 와 웹 시스템 을 통합 하여 사용 한 후 두 가지 방식 을 사용 하도록 권한 을 부여...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.