Skip to content

Commit

Permalink
[ISSUE #8214] Resolve CI error
Browse files Browse the repository at this point in the history
  • Loading branch information
onewe committed Apr 22, 2022
1 parent 433b319 commit ecd8fa9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
* @author onewe
*/
@Configuration
@Conditional(ConditionOnLdapAuth.class)
@EnableAutoConfiguration(exclude = LdapAutoConfiguration.class)
public class LdapAuthConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.alibaba.nacos.plugin.auth.impl.users.NacosUserDetailsServiceImpl;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.io.DecodingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.security.authentication.AuthenticationManager;
Expand Down Expand Up @@ -63,23 +63,17 @@ public class NacosAuthConfig extends WebSecurityConfigurerAdapter {

private static final String PROPERTY_IGNORE_URLS = "nacos.security.ignore.urls";

@Autowired
private Environment env;
private final Environment env;

@Autowired
private JwtTokenManager tokenProvider;
private final JwtTokenManager tokenProvider;

@Autowired
private AuthConfigs authConfigs;
private final AuthConfigs authConfigs;

@Autowired
private NacosUserDetailsServiceImpl userDetailsService;
private final NacosUserDetailsServiceImpl userDetailsService;

@Autowired
private LdapAuthenticationProvider ldapAuthenticationProvider;
private final LdapAuthenticationProvider ldapAuthenticationProvider;

@Autowired
private ControllerMethodsCache methodsCache;
private final ControllerMethodsCache methodsCache;

/**
* secret key.
Expand All @@ -96,6 +90,20 @@ public class NacosAuthConfig extends WebSecurityConfigurerAdapter {
*/
private long tokenValidityInSeconds;

public NacosAuthConfig(Environment env, JwtTokenManager tokenProvider, AuthConfigs authConfigs,
NacosUserDetailsServiceImpl userDetailsService,
ObjectProvider<LdapAuthenticationProvider> ldapAuthenticationProvider,
ControllerMethodsCache methodsCache) {

this.env = env;
this.tokenProvider = tokenProvider;
this.authConfigs = authConfigs;
this.userDetailsService = userDetailsService;
this.ldapAuthenticationProvider = ldapAuthenticationProvider.getIfAvailable();
this.methodsCache = methodsCache;

}

/**
* Init.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.ObjectProvider;

import java.lang.reflect.Field;
import java.util.Properties;
Expand All @@ -39,6 +40,9 @@ public class JwtTokenManagerTest {
@Mock
private ControllerMethodsCache methodsCache;

@Mock
private ObjectProvider<LdapAuthenticationProvider> ldapAuthenticationProvider;

private NacosAuthConfig nacosAuthConfig;

@Test
Expand All @@ -57,9 +61,9 @@ private void createToken(String secretKey) throws NoSuchFieldException, IllegalA
properties.setProperty(AuthConstants.TOKEN_SECRET_KEY, secretKey);
properties.setProperty(AuthConstants.TOKEN_EXPIRE_SECONDS, "300");
when(authConfigs.getAuthPluginProperties(AuthConstants.AUTH_PLUGIN_TYPE)).thenReturn(properties);
nacosAuthConfig = new NacosAuthConfig();
injectProperty(nacosAuthConfig, "methodsCache", methodsCache);
injectProperty(nacosAuthConfig, "authConfigs", authConfigs);

nacosAuthConfig = new NacosAuthConfig(null, null, authConfigs, null,
ldapAuthenticationProvider, methodsCache);
nacosAuthConfig.init();
JwtTokenManager jwtTokenManager = new JwtTokenManager();
injectProperty(jwtTokenManager, "nacosAuthConfig", nacosAuthConfig);
Expand Down

0 comments on commit ecd8fa9

Please sign in to comment.