【问题标题】:How to get URL hit by user in Spring security config file如何在 Spring 安全配置文件中获取用户点击的 URL
【发布时间】:2016-07-19 05:35:17
【问题描述】:

我正在使用自定义安全评估器方法在 java-springs Web 应用程序中工作, 我需要将用户点击的 URL 作为参数传递给方法 permissionEvaluator.canUserAccessPage(URLHitByUser)。

如何获取用户点击的 URL。

@Override
protected void configure(HttpSecurity http) throws Exception {

        http
    .authorizeRequests()
        //.antMatchers("/view/**").permitAll()
        .antMatchers("/assets/**").permitAll()
        .antMatchers("/view/admin.html").access("@permissionEvaluator.canUserAccessPage(URLHitByUser)")
        .anyRequest().authenticated()
        .and()
    .formLogin()
        .loginPage("/login").usernameParameter("username").passwordParameter("password")
        .defaultSuccessUrl("/index") 
        .permitAll() 

    // [...]
}

【问题讨论】:

    标签: java spring spring-mvc web-applications spring-security


    【解决方案1】:

    如果您打算控制对某些角色的访问,这可以通过在 applicationContext-security-preauth.xml 中使用 sec:intercept-url 来实现。

    谢谢

    【讨论】:

    • 但我有 70 个 html 文件和 60 个角色。角色和访问权限可以动态修改,并且可以在 DB 中使用。所以我写了一个方法 boolean canUserAccessPage(StringURL);此方法通过使用登录的用户代码和用户点击的 URL 查询数据库来返回 true 或 false。因此,如果可以检索到 URL,将很有帮助。谢谢。
    猜你喜欢
    • 2018-09-02
    • 1970-01-01
    • 2022-01-15
    • 2011-09-01
    • 2021-01-12
    • 2020-06-01
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多