Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think that the check be achieved by using <a href="http://static.springsource.org/spring-security/site/docs/3.0.x/reference/el-access.html" rel="noreferrer">hasIpAddress</a> http expression</p> <p>See section <a href="http://static.springsource.org/spring-security/site/docs/3.0.x/reference/el-access.html" rel="noreferrer"><em>15.2 Web Security Expressions</em></a> </p> <pre><code>&lt;http use-expressions="true"&gt; &lt;intercept-url pattern="/admin*" access="hasRole('admin') and hasIpAddress('192.168.1.0/24')"/&gt; ... &lt;/http&gt; </code></pre> <p>If you want more flexibility, you can implement your own IP address check service, based on IpAddressMatcher:</p> <pre><code>&lt;bean id="ipCheckService" class="my.IpCheckService"&gt; &lt;/bean&gt; &lt;security:http auto-config="false" access-denied-page="/accessDenied.jsp" use-expressions="true"&gt; &lt;security:intercept-url pattern="/login.jsp" access="@ipCheckService.isValid(request)" /&gt; </code></pre> <p>bean implementation:</p> <pre><code>public class IpCheckService { public boolean isValid(HttpServletRequest request) { //This service is a bean so you can inject other dependencies, //for example load the white list of IPs from the database IpAddressMatcher matcher = new IpAddressMatcher("192.168.1.0/24"); try { return matcher.matches(request); } catch (UnsupportedOperationException e) { return false; } } } </code></pre> <p><strong>update</strong>: you can try to get current user IP this way:</p> <pre><code> public static String getRequestRemoteAddr(){ HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()) .getRequest(); return request.getRemoteAddr(); } </code></pre> <p><strong>update</strong> The information about the relation between IP addresses and sessions can only be gathered from the different sources(like listening to AuthenticationSuccessEvent and SessionDestroyedEvent events, implementing a filter or using an AOP interceptor). Spring Security doesn't store such information because it's useless, as IP address has some meaning only while the server is processing a <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html" rel="noreferrer">ServletRequest</a>.</p> <p>IP address may change(user may be using a proxy), so we can only audit different kinds of events like logging in with some credentials, accessing a service from a different IP, or doing some suspicious activity.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload