这是我的 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/