小编Kha*_*oud的帖子

AuthenticationSuccessHandler在spring mvc基于java的配置中

我有三个角色,我想根据他们的角色在登录后将用户重定向到不同的页面.我知道这可以通过AuthenticationSuccessHandler来完成,但我在基于java的配置中声明它时遇到了麻烦.到目前为止我已经这样做了.

protected void configure(HttpSecurity http) throws Exception {

    http
    .authorizeRequests()                                                                
    .antMatchers("/resources/**", "/login").permitAll()                  
    .antMatchers("/admin/**").hasRole("USER")                           
    .and()

    .formLogin()
        .loginPage("/login")
        .defaultSuccessUrl("/")
        .successHandler(successHandler) //----- to handle user role
        .failureUrl("/loginfailed")             
        .permitAll()
        .and()

    .logout()
        .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
        .deleteCookies("JSESSIONID")
        .invalidateHttpSession( true )
        .and();                    
}
Run Code Online (Sandbox Code Playgroud)

我的问题是在哪里声明successHandler以及如何在这个类中自动装配它,或者如何在这个类中声明successHandler方法并使用它.

authentication spring spring-mvc spring-security

3
推荐指数
1
解决办法
8575
查看次数

spring security 使用 ROLE_USER 定义用户注册

我正在使用HibernateSpring SecuritySpring MVC 4 中创建一个项目。在这个项目中,我有 3 个角色:,和.ROLE_USERROLE_COMPANYROLE_ADMIN

用户将像常规注册站点一样注册,但我对如何通过注册过程在数据库中保存新用户、如何保存Spring Security定义的新用户和数据库以及如何使用 hibernate 获取该信息感到困惑。

谢谢你。

spring hibernate spring-mvc spring-security

1
推荐指数
1
解决办法
2031
查看次数

当网址更改时,弹簧mvc背景图像无法正常工作

我想提供背景资料.当网址为(在登录页面中)时图像正确加载

/jobsspectrum/login
Run Code Online (Sandbox Code Playgroud)

在个人资料页面中使用

<body background="resources/images/black.jpg">
Run Code Online (Sandbox Code Playgroud)

但是当URL更改时,图像不会加载.例如.

/jobsspectrum/user/profile
because there is /user in the url before the page where i am using image in profile page.
Run Code Online (Sandbox Code Playgroud)

错误是

message /jobsspectrum/user/resources/images/black.jpg
description The requested resource is not available.
Run Code Online (Sandbox Code Playgroud)

我的图像在资源/图像下

当网址不是/ jobsspectrum /时,它不会选择资源

我的资源处理类是:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

    registry.addResourceHandler("/resources/**").addResourceLocations("resources/");
    super.addResourceHandlers(registry);
}
Run Code Online (Sandbox Code Playgroud)

我简单的说法是只在前页中选取图像,当用户登录我的网址从/ jobsspectrum /更改为/ jobsspectrum/user/**时,资源图像部分未正确加载.

java jsp spring-mvc spring-boot

1
推荐指数
1
解决办法
6674
查看次数