Attribute release based on IP address

Robert Führicht Robert.Fuehricht at jku.at
Thu Oct 20 14:57:49 EDT 2016


We use this groovy script to get the client's IP address:

package at.jku
      
      import org.springframework.web.context.request.AbstractRequestAttributes
      import org.springframework.web.context.request.ServletRequestAttributes
      import org.springframework.web.context.request.RequestContextHolder
      import org.slf4j.*
      import net.shibboleth.idp.attribute.*
      
logger = LoggerFactory.getLogger("at.jku.script.ipaddr")
      logger.debug("script start")
      
// Lookup the ServletContext through Spring
      def req = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()
      def addr = req.getRemoteAddr()
      def host = req.getRemoteHost()

        logger.info("$host = $addr")
      ipaddr.getValues().add(addr)
      logger.debug("value: {}", ipaddr.getValues())
      logger.debug("script stop")
      
        ipaddr

Another groovy script evaluates the ip like this:

def onCampus(ip) {
  addr = (Inet4Address) InetAddress.getByName(ip)
     b = addr.getAddress()
  i = ((b[0] & 0xFF) << 24) |
    ((b[1] & 0xFF) << 16) |
    ((b[2] & 0xFF) << 8)  |
    ((b[3] & 0xFF) << 0);
  i &= 0xFFFFFFFF
  assert i > 0
  logger.debug("IP: {}.{}.{}.{}", b[0] & 0xFF,b[1] & 0xFF,b[2] & 0xFF,b[3] & 0xFF)
  local = (i & (-1 << 24))  == 0x7F000000
  // More options omitted
  local || hostels || ...
}

I can send you the complete scripts and config, if you need help connecting the dots :-)



More information about the users mailing list