简体   繁体   English

Spring 安全登录未显示

[英]Spring security login not showing

I'm adding Spring Security on a Spring MVC app;我在 Spring MVC 应用程序上添加 Spring 安全性; however, when I run the application, the Spring Security default login does not show up (not even when I browse to a link which is supposed to be "secured").但是,当我运行应用程序时,Spring 安全默认登录不显示(即使我浏览到应该是“安全”的链接时也不显示)。

Configuration class (forgive the indentation):配置class(请原谅缩进):

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConf extends WebSecurityConfigurerAdapter {

@Autowired
private UserService userDetailsService;

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable();
    http.authorizeRequests()
            .antMatchers("**/secured/**").authenticated()
            .anyRequest().permitAll()
            .and()
            .formLogin().permitAll();
}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(getPasswordEncoder());
}

private PasswordEncoder getPasswordEncoder() {
    return new PasswordEncoder() {

        @Override
        public boolean matches(CharSequence rawPassword, String encodedPassword) {
            return encode(rawPassword).equals(encodedPassword);
        }

        @Override
        public String encode(CharSequence rawPassword) {
            return rawPassword.toString();
        }
    };
}   }

I also tried adding a custom login, but it does not seem to find the page (which is otherwise reachable):我也尝试添加自定义登录,但似乎找不到页面(否则可以访问):

http.authorizeRequests()
            .antMatchers("**/secured/**").authenticated()
            .anyRequest().permitAll()
            .and()
            .formLogin().loginPage('/login').permitAll();

Summing up, I need the default Spring Security login page to be displayed first, so I can test the authentication, then I need to be able to add a new login form to be displayed instead.总结一下,我需要先显示默认的 Spring 安全登录页面,所以我可以测试身份验证,然后我需要能够添加一个新的登录表单来代替显示。 What should I do?我应该怎么办?

EDIT: I figured out the configuration problem which prevented the Spring login to be displayed.编辑:我发现了阻止显示 Spring 登录的配置问题。 The following tags had to be added in the web.xml file in order to integrate Spring Security with Spring MVC.必须在 web.xml 文件中添加以下标签,以便将 Spring 安全性与 Z38008MD81C2FCEAFD1D17 集成。 Now the login is succesfully displayed.现在登录成功显示。

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

I figured out the configuration problem which prevented the Spring login to be displayed.我发现了阻止显示 Spring 登录的配置问题。 The following tags had to be added in the web.xml file in order to integrate Spring Security with Spring MVC.必须在 web.xml 文件中添加以下标签,以便将 Spring 安全性与 Z38008MD81C2FCEAFD1D17 集成。 Now the login is succesfully displayed.现在登录成功显示。

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM