java - 拒绝 Spring Security 中所有角色对特定 URL 的访问

标签 java spring-mvc spring-security

这是我的 spring-security.xml

  <beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" 
    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-3.1.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <http auto-config="true" use-expressions="true">
        <intercept-url pattern="/dashboard.htm"  access="hasAnyRole('ROLE_USER','ROLE_ADMIN','ROLE_DEMO')"/>
        <intercept-url pattern="/dash/*" access="hasAnyRole('ROLE_USER','ROLE_ADMIN','ROLE_DEMO')"/>

        <form-login login-page="/index.htm" 
        default-target-url="/dashboard.htm"
            authentication-failure-url="/loginfailed.htm" />

        <logout logout-success-url="/logout.htm" invalidate-session="true" />
    </http>

    <beans:bean id="customUserService" class="edu.am.bigdata.web.service.impl.CustomUserServiceImpl"></beans:bean>

    <authentication-manager>
        <authentication-provider user-service-ref="customUserService">
        <password-encoder hash="md5"> </password-encoder>
        </authentication-provider>
    </authentication-manager>
 </beans:beans>

如何阻止访问某一特定网址??? 我有一些 Controller 功能(即)网址 - /dash/* 、/algo/*

即使用户拥有任何角色,我也需要阻止此网址,并且仅当他直接访问这些网址时才将其显示为访问被拒绝。但我的 Web 应用程序在内部使用此 URL。 如果我手动输入此网址(如 localhost:8080/MyApp/dash/viz.htm),则应显示访问被拒绝。对于任何角色,不应访问这些网址。我该如何执行此操作???

最佳答案

使用access =“denyAll”。例如:

<intercept-url pattern="/admin/*" access="denyAll" />

关于java - 拒绝 Spring Security 中所有角色对特定 URL 的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19449968/

相关文章:

java - eclipse- "show in project explorer"选项不起作用

java - 如何优化和循环包含至少 1000 个对象的 2D 列表

java - Webdriver 不支持以其他用户身份运行

java - 如何在java中更新浏览器缓存

java - Spring MVC中如何返回JSP选择框的值?

spring - 一次只有一个用户使用整个 Web 应用程序 - Spring boot

java - MongoDB 映射缩减,给出错误 "No converter found capable of converting from type java.lang.Boolean to type int"

spring - Spring Mock MVC 测试的时区

java - 尽管有 web.ignoring().antMatchers(),为什么我的过滤器仍在该端点上被调用?

java - Spring 安全: How to get the automatically rendered login page code?