Example #1
0
  /**
   * Checks whether the client is authenticated.
   *
   * @param request client request
   * @return true if the client is authenticated, false if not
   */
  protected boolean isAuthenticated(HttpServletRequest request) throws ServletException {
    log.debug("Attempting to authenticate client '{}'", request.getRemoteAddr());
    try {
      InetAddress clientAddress = InetAddress.getByName(request.getRemoteAddr());

      for (IPRange range : allowedIPs) {
        if (range.contains(clientAddress)) {
          return true;
        }
      }

      return false;
    } catch (UnknownHostException e) {
      throw new ServletException(e);
    }
  }
Example #2
0
  /** {@inheritDoc} */
  public void init(ServletConfig config) throws ServletException {
    super.init(config);

    allowedIPs = new LazyList<IPRange>();

    String cidrBlocks = DatatypeHelper.safeTrimOrNullString(config.getInitParameter(IP_PARAM_NAME));
    if (cidrBlocks != null) {
      for (String cidrBlock : cidrBlocks.split(" ")) {
        allowedIPs.add(IPRange.parseCIDRBlock(cidrBlock));
      }
    }

    dateFormat = ISODateTimeFormat.dateTimeNoMillis();
    startTime = new DateTime(ISOChronology.getInstanceUTC());
    attributeResolver = HttpServletHelper.getAttributeResolver(config.getServletContext());
    rpConfigManager =
        HttpServletHelper.getRelyingPartyConfirmationManager(config.getServletContext());
  }