【问题标题】:Spring Security - display HTML page on expiredUrl in sessionManagementSpring Security - 在 sessionManagement 中的 expiredUrl 上显示 HTML 页面
【发布时间】:2016-11-01 16:43:09
【问题描述】:

我想在我的 java spring security 中配置expiredUrl(" ") 功能。
我想在并发会话过期时显示 HTML 页面
我尝试了以下方式:-

JAVA

@Override
public void configure(HttpSecurity http) throws Exception {
    http
            .sessionManagement()
            .sessionFixation()
            .changeSessionId()
            .maximumSessions(1)
            .expiredUrl("/session_expired.html")
}

我的上下文路径设置为localhost:8080/context_path 但是
我不知道如何在 expiredUrl 调用上显示 session_expired.html 页面
我在 Js 端使用 angularJs
请帮我在 expiredUrl 调用时显示 Html 页面

如果我在 Js 的帮助下尝试过,那么我的代码是:-

JAVA

@Override
public void configure(HttpSecurity http) throws Exception {
    http
            .sessionManagement()
            .sessionFixation()
            .changeSessionId()
            .maximumSessions(1)
            .expiredUrl("/access/session_expired")
}

ANGULARJS

$stateProvider.state('session_expired', {
     'url': '/session_expired',
     'templateUrl': '/session_expired.html',
     'controller': 'SessionExpiredController'
})

.factory('SessionService', function ($resource, restRoot, contextPath) {
return $resource({
    'session_expired': {
        'url': contextPath + '/access/session_expired'
    },
})

.controller('SessionExpiredController', function (SessionService, $state) {
     SessionService.session_expired(function () {
         $state.go("session_expired");
     });
 });

当会话过期时,它将继续链接localhost:8080/context_path/session_expired#/landing...
但我想继续链接
localhost:8080/context_path/#/session_expired

我想在expiredUrl上显示直接HTML页面
所以请指导我如何做到这一点。

【问题讨论】:

标签: java angularjs spring spring-mvc spring-security


【解决方案1】:

此配置对我有用:

 @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/", "/list")
                .access("hasRole('USER') or hasRole('ADMIN') or hasRole('DBA')")
                .antMatchers("/newuser/**", "/delete-user-*").access("hasRole('ADMIN')").antMatchers("/edit-user-*")
                .access("hasRole('ADMIN') or hasRole('DBA')").and().formLogin().loginPage("/login")
                .loginProcessingUrl("/login").usernameParameter("ssoId").passwordParameter("password").and()
                .rememberMe().rememberMeParameter("remember-me").tokenRepository(tokenRepository)
                .tokenValiditySeconds(86400).and().csrf().and().exceptionHandling().accessDeniedPage("/Access_Denied");
    }

【讨论】:

  • 是的,但我想在会话过期时显示 HTML 页面,所以当我的会话过期时它会继续路径 localhost:8080/context_path/session_expired#/... 而不是这个我想重定向到 localhost:8080/context_path/#/session_expired 我想在expiredUrl返回html页面
  • 好的,那是什么 /Access_Denied ?是链接还是别的?
  • 它是一个拒绝访问的页面,如果不允许用户访问某些 url,就会显示该页面..
  • 你能分享一下那个代码,你是如何显示 AccessDenied 页面的
  • 代码是共享的.. 例如,如果角色为“USER”的用户尝试在浏览器栏中键入删除 URL 并输入。他应该看到 AccessDenied 页面.. 只有具有“管理员”的用户在我的示例中,角色可以访问删除 URL..
猜你喜欢
  • 2016-01-02
  • 2018-01-20
  • 2018-10-02
  • 2022-07-01
  • 1970-01-01
  • 2014-03-21
  • 2017-07-31
  • 2018-03-06
  • 1970-01-01
相关资源
最近更新 更多