Using the hasIpAddress method

The hasIpAddress method is not quite as clear-cut as the request attribute. The hasIpAddress will easily match an exact IP address; for example, the following code would allow access if the current user's IP address was 192.168.1.93:

    hasIpAddress('192.168.1.93')

However, this is not all that useful. Instead, we can define the following code, which would also match our IP address and any other IP address in our subnet:

    hasIpAddress('192.168.1.0/24')

The question is: how is this calculated? The key is to understand how to calculate the network address and its mask. To learn how to do this, we can take a look at a concrete example. We launch ifconfig from our Linux Terminal to view our network information (Windows ...

Get Spring Security - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.