Skip to content

Commit

Permalink
Merge branch 'feature/1.0.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhouyu committed Oct 9, 2024
2 parents ac274e2 + 4f44256 commit 60bbb96
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.fuhouyu.framework.security;

import com.fuhouyu.framework.cache.CacheAutoConfigure;
import com.fuhouyu.framework.cache.service.CacheService;
import com.fuhouyu.framework.security.core.passwordencoder.PasswordEncoderFactory;
import com.fuhouyu.framework.security.token.TokenStore;
import com.fuhouyu.framework.security.token.TokenStoreCache;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
Expand All @@ -44,6 +46,7 @@
*/
@ComponentScan(basePackageClasses = SecurityAutoConfigure.class)
@Import({OpenPlatformAutoConfigure.class})
@AutoConfigureAfter(CacheAutoConfigure.class)
public class SecurityAutoConfigure {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fuhouyu.framework.security.token.DefaultOAuth2Token;
import com.fuhouyu.framework.security.token.TokenStore;
import com.fuhouyu.framework.security.token.TokenStoreCache;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -31,7 +32,6 @@
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.Assert;

import java.util.Collections;

Expand Down Expand Up @@ -68,22 +68,22 @@ void setup() {
void testTokenStore() {

DefaultOAuth2Token accessToken = tokenStore.createToken(authentication, 60, 60);
Assert.notNull(accessToken, "生成的token不能为空");
Assertions.assertNotNull(accessToken, "生成的token不能为空");

Authentication tokenAuthentication = tokenStore.readAuthentication(accessToken);
Assert.notNull(tokenAuthentication, "未获取到token认证的对象");
Assertions.assertNotNull(tokenAuthentication, "未获取到token认证的对象");

OAuth2RefreshToken oAuth2RefreshToken = tokenStore.readRefreshToken(accessToken.getAuth2RefreshToken().getTokenValue());
Assert.notNull(oAuth2RefreshToken, "未获取到刷新令牌对象");
Assertions.assertNotNull(oAuth2RefreshToken, "未获取到刷新令牌对象");

Authentication authenticationByRefreshToken = tokenStore.readAuthenticationForRefreshToken(oAuth2RefreshToken);
Assert.notNull(authenticationByRefreshToken, "未通过刷新令牌获取到认证对象");
Assertions.assertNotNull(authenticationByRefreshToken, "未通过刷新令牌获取到认证对象");

tokenStore.removeAllToken(accessToken);
OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(accessToken.getTokenValue());
Assert.isNull(oAuth2AccessToken, "access token 未被清除");
Assertions.assertNull(oAuth2AccessToken, "access token 未被清除");

Assert.isNull(tokenStore.readRefreshToken(accessToken.getAuth2RefreshToken().getTokenValue()), "refresh token 未被清除");
Assertions.assertNull(tokenStore.readRefreshToken(accessToken.getAuth2RefreshToken().getTokenValue()), "refresh token 未被清除");
}

}
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,12 @@
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<version>${spring-boot-dependencies.version}</version>
</path>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot-dependencies.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
Expand Down

0 comments on commit 60bbb96

Please sign in to comment.