2014-02-19 78 views
0

我想在我的spring web应用程序中阻止访问某些URL。我做了一些研究,发现了“标题”。我不知道如何使用它们。任何帮助将不胜感激。提前致谢。拒绝访问某些网址

+0

你在你的应用程序中使用弹簧安全? – rhinds

+0

@rhinds我使用弹簧安全 – Esseme

回答

0

我可以立即想到的最简单的方法之一就是拥有一个预先定义的被阻止的URL地址列表,并根据您的AbstractAuthenticationProcessingFilter的实施方法重写的requiresAuthentication()方法对照此列表检查请求URL 。

@Override  
protected boolean requiresAuthentication(final HttpServletRequest request, final HttpServletResponse response) { 
     List<String> blockedUrls = new Arraylist<>(); 
     list.add("/foo/"); 
     if(blockedUrls.contains(request.getRequestURI())) { 
      // go to blocked error page 
     } else { 
      // process the request normally 
     } 
    } 

Shishir

0

您是如何设定春季安全?你能告诉我们code/xml吗?

假设你已经为webapp配置了spring-security,那么很容易限制URL(包括基于角色的限制)。

<http auto-config="true" use-expressions="true"> 
    <intercept-url pattern="/restricted/**" access="isAuthenticated()" /> 
    <intercept-url pattern="/**" access="permitAll" /> 
    <form-login login-processing-url="/loginProcess" 
       login-page="/" 
       authentication-failure-url="/?loginFailure=true"/> 
    <logout logout-url="/static/j_spring_security_logout"/> 
</http> 

截取URL元素定义URL模式以及是否任何人/每个人都可以访问该模式。 Spring将从顶部匹配,因此最具体的身份验证应该位于列表的顶部。另外,在上例中,由于最终条目与所有URL匹配,这意味着任何未在其他URL模式中指定的内容都将打开。

从本文摘自 - 它也展示了如何实现相同的使用代码的配置,而不是在XML:http://automateddeveloper.blogspot.co.uk/2014/02/spring-4-xml-to-annotation-configuration.html

+0

我有这个设置。我在我的android应用程序中使用这些URL,是否必须在移动端上做一些额外的工作才能访问它们,因为Spring安全性被用来拒绝他们的访问。我如何去做这件事。谢谢 – Esseme

+0

你想只有你的移动应用程序可以使用某些网址吗? – rhinds

+0

是的,我希望仅在移动应用程序上提供一些URL – Esseme