春季安全性OAuth2错误:ERR_TOO_MANY_REDIRECTS

时间:2019-06-27 14:06:33

标签: java spring-boot spring-mvc spring-security oauth-2.0

您好,我尝试在我的网站上进行安全身份验证,但我拥有登录页面,但此后出现以下错误:ERR_TOO_MANY_REDIRECTS 我使用Spring Security b2c OAuth 2。 任何人都可以帮助我解决这个错误吗?

import com.microsoft.azure.spring.autoconfigure.b2c.AADB2CLogoutSuccessHandler;
import com.microsoft.azure.spring.autoconfigure.b2c.AADB2CProperties;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;

@EnableWebSecurity
public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {

private final ClientRegistrationRepository clientRegistrationRepository;
private final AADB2CProperties properties;
private final AADB2CLogoutSuccessHandler logoutSuccessHandler;

public OAuth2LoginSecurityConfig(
        ClientRegistrationRepository clientRegistrationRepository,
        AADB2CProperties properties,
        AADB2CLogoutSuccessHandler logoutSuccessHandler
) {
    this.clientRegistrationRepository = clientRegistrationRepository;
    this.properties = properties;
    this.logoutSuccessHandler = logoutSuccessHandler;
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
            .anyRequest().authenticated()
            .and()
            .logout().logoutSuccessHandler(this.logoutSuccessHandler)
            .and()
            .oauth2Login()
            .clientRegistrationRepository(clientRegistrationRepository);
}

}

控制器:

@Controller
public class DeviceController {

private final exakis.atlantis.admin.UserRepository userRepository;
private final DeviceRepository deviceRepository;

@Autowired
public DeviceController(DeviceRepository deviceRepository, UserRepository userRepository) {
    this.deviceRepository = deviceRepository;
    this.userRepository = userRepository;
}

@GetMapping("/")
public String showIndex(User user, Model model) {
    model.addAttribute("users", userRepository.findAll());
    model.addAttribute("devices", deviceRepository.findAll());
    return "index";
}

}

如果您需要更多信息或我的代码,请随时询问我。

0 个答案:

没有答案