为什么我的spring控制器没有被调用?

j2qf4p5b  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(269)

我正在尝试使用Spring5针对openid连接身份验证提供程序配置身份验证。
这是我的configure()方法:

package my.pkg.security.spring.oidc;
...
@Configuration
@ComponentScan
@EnableWebSecurity
@PropertySource("classpath:application-spring-oidc.properties")
public class OidcSecurityConfig extends WebSecurityConfigurerAdapter {

    ...

    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/oauth_login").permitAll()
            .anyRequest().authenticated()
            .and()
            .oauth2Login()
            .clientRegistrationRepository(clientRegistrationRepository())
            .authorizedClientService(authorizedClientService())
            .loginPage("/oauth_login")
            .defaultSuccessUrl("/loginSuccess")
            .failureUrl("/loginFailure")
            .authorizationEndpoint()
            .baseUri("/oauth2/authorize-client")
            .authorizationRequestRepository(authorizationRequestRepository())
            .and()
            .tokenEndpoint()
            .accessTokenResponseClient(accessTokenResponseClient())
            .and()
            .redirectionEndpoint()
            .baseUri("/oauth2/redirect");
    }
...
}

我的控制器:

package my.pkg.security.spring.oidc;
...
@Controller
public class LoginController {

    @GetMapping(value = "/oauth_login")
    public String getLoginPage(Model model) {

        ...
    }
}

my application-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans 
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:security="http://www.springframework.org/schema/security" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security.xsd">

    <!-- context:component-scan base-package="org.keycloak.adapters.springsecurity" / -->

    <context:annotation-config/>
    <bean class="my.pkg.security.spring.oidc.OidcSecurityConfig"/>

</beans>

当我尝试访问应用程序的受保护资源时,请求会像我预期的那样重定向到/oauth\u login。然而,当这种情况发生时,我得到一个HTTP404。好像我的控制器Map被忽略了。
你能看到我的配置有什么问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题