Browse Source

fixed circular dependency

pull/10671/head
YevhenBondarenko 2 years ago
parent
commit
3cd8c60518
  1. 2
      application/src/main/java/org/thingsboard/server/service/security/auth/jwt/settings/DefaultJwtSettingsService.java
  2. 2
      application/src/main/java/org/thingsboard/server/service/security/model/token/JwtTokenFactory.java
  3. 3
      application/src/test/java/org/thingsboard/server/service/security/auth/JwtTokenFactoryTest.java

2
application/src/main/java/org/thingsboard/server/service/security/auth/jwt/settings/DefaultJwtSettingsService.java

@ -17,6 +17,7 @@ package org.thingsboard.server.service.security.auth.jwt.settings;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
@ -42,7 +43,6 @@ public class DefaultJwtSettingsService implements JwtSettingsService {
private final AdminSettingsService adminSettingsService; private final AdminSettingsService adminSettingsService;
private final Optional<TbClusterService> tbClusterService; private final Optional<TbClusterService> tbClusterService;
private final JwtSettingsValidator jwtSettingsValidator; private final JwtSettingsValidator jwtSettingsValidator;
@Lazy
private final Optional<JwtTokenFactory> jwtTokenFactory; private final Optional<JwtTokenFactory> jwtTokenFactory;
private volatile JwtSettings jwtSettings = null; //lazy init private volatile JwtSettings jwtSettings = null; //lazy init

2
application/src/main/java/org/thingsboard/server/service/security/model/token/JwtTokenFactory.java

@ -28,6 +28,7 @@ import io.jsonwebtoken.UnsupportedJwtException;
import io.jsonwebtoken.security.Keys; import io.jsonwebtoken.security.Keys;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -70,6 +71,7 @@ public class JwtTokenFactory {
private static final String CUSTOMER_ID = "customerId"; private static final String CUSTOMER_ID = "customerId";
private static final String SESSION_ID = "sessionId"; private static final String SESSION_ID = "sessionId";
@Lazy
private final JwtSettingsService jwtSettingsService; private final JwtSettingsService jwtSettingsService;
private volatile JwtParser jwtParser; private volatile JwtParser jwtParser;

3
application/src/test/java/org/thingsboard/server/service/security/auth/JwtTokenFactoryTest.java

@ -53,7 +53,6 @@ public class JwtTokenFactoryTest {
private JwtTokenFactory tokenFactory; private JwtTokenFactory tokenFactory;
private AdminSettingsService adminSettingsService; private AdminSettingsService adminSettingsService;
private JwtSettingsService jwtSettingsService; private JwtSettingsService jwtSettingsService;
private JwtTokenFactory jwtTokenFactory;
private JwtSettings jwtSettings; private JwtSettings jwtSettings;
@ -171,7 +170,7 @@ public class JwtTokenFactoryTest {
} }
private DefaultJwtSettingsService mockJwtSettingsService() { private DefaultJwtSettingsService mockJwtSettingsService() {
return new DefaultJwtSettingsService(adminSettingsService, Optional.empty(), new DefaultJwtSettingsValidator(), jwtTokenFactory); return new DefaultJwtSettingsService(adminSettingsService, Optional.empty(), new DefaultJwtSettingsValidator(), Optional.empty());
} }
private void checkExpirationTime(JwtToken jwtToken, int tokenLifetime) { private void checkExpirationTime(JwtToken jwtToken, int tokenLifetime) {

Loading…
Cancel
Save