Search in sources :

Example 1 with RefreshTokenAuthenticationProvider

use of org.thingsboard.server.service.security.auth.jwt.RefreshTokenAuthenticationProvider in project thingsboard by thingsboard.

the class TokenOutdatingTest method setUp.

@BeforeEach
public void setUp() {
    jwtSettings = new JwtSettings();
    jwtSettings.setTokenIssuer("test.io");
    jwtSettings.setTokenExpirationTime((int) MINUTES.toSeconds(10));
    jwtSettings.setRefreshTokenExpTime((int) DAYS.toSeconds(7));
    jwtSettings.setTokenSigningKey("secret");
    tokenFactory = new JwtTokenFactory(jwtSettings);
    cacheManager = new ConcurrentMapCacheManager();
    tokenOutdatingService = new TokenOutdatingService(cacheManager, tokenFactory, jwtSettings);
    tokenOutdatingService.initCache();
    userId = new UserId(UUID.randomUUID());
    UserService userService = mock(UserService.class);
    User user = new User();
    user.setId(userId);
    user.setAuthority(Authority.TENANT_ADMIN);
    user.setEmail("email");
    when(userService.findUserById(any(), eq(userId))).thenReturn(user);
    UserCredentials userCredentials = new UserCredentials();
    userCredentials.setEnabled(true);
    when(userService.findUserCredentialsByUserId(any(), eq(userId))).thenReturn(userCredentials);
    accessTokenAuthenticationProvider = new JwtAuthenticationProvider(tokenFactory, tokenOutdatingService);
    refreshTokenAuthenticationProvider = new RefreshTokenAuthenticationProvider(tokenFactory, userService, mock(CustomerService.class), tokenOutdatingService);
}
Also used : ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) User(org.thingsboard.server.common.data.User) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) JwtSettings(org.thingsboard.server.config.JwtSettings) UserService(org.thingsboard.server.dao.user.UserService) UserId(org.thingsboard.server.common.data.id.UserId) JwtTokenFactory(org.thingsboard.server.service.security.model.token.JwtTokenFactory) UserCredentials(org.thingsboard.server.common.data.security.UserCredentials) JwtAuthenticationProvider(org.thingsboard.server.service.security.auth.jwt.JwtAuthenticationProvider) RefreshTokenAuthenticationProvider(org.thingsboard.server.service.security.auth.jwt.RefreshTokenAuthenticationProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BeforeEach (org.junit.jupiter.api.BeforeEach)1 ConcurrentMapCacheManager (org.springframework.cache.concurrent.ConcurrentMapCacheManager)1 User (org.thingsboard.server.common.data.User)1 UserId (org.thingsboard.server.common.data.id.UserId)1 UserCredentials (org.thingsboard.server.common.data.security.UserCredentials)1 JwtSettings (org.thingsboard.server.config.JwtSettings)1 UserService (org.thingsboard.server.dao.user.UserService)1 JwtAuthenticationProvider (org.thingsboard.server.service.security.auth.jwt.JwtAuthenticationProvider)1 RefreshTokenAuthenticationProvider (org.thingsboard.server.service.security.auth.jwt.RefreshTokenAuthenticationProvider)1 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)1 JwtTokenFactory (org.thingsboard.server.service.security.model.token.JwtTokenFactory)1