View Javadoc

    1   /*
    2    * Copyright 2008 University Corporation for Advanced Internet Development, Inc.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    * http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16
    17  package edu.internet2.middleware.shibboleth.idp.config.profile.authn;
    18
    19  import java.util.ArrayList;
    20  import java.util.List;
    21  import java.util.Map;
    22
    23  import javax.xml.namespace.QName;
    24
    25  import org.opensaml.xml.util.DatatypeHelper;
    26  import org.opensaml.xml.util.XMLHelper;
    27  import org.slf4j.Logger;
    28  import org.slf4j.LoggerFactory;
    29  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
    30  import org.w3c.dom.Element;
    31
    32  import edu.internet2.middleware.shibboleth.idp.config.profile.ProfileHandlerNamespaceHandler;
    33
    34  /**
    35   * Spring bean definition parser for IP address authentication handlers.
    36   */
    37  public class IPAddressLoginHandlerBeanDefinitionParser extends AbstractLoginHandlerBeanDefinitionParser {
    38
    39      /** Schema type. */
    40      public static final QName SCHEMA_TYPE = new QName(ProfileHandlerNamespaceHandler.NAMESPACE, "IPAddress");
    41
    42      /** Name of ip entry elements. */
    43      public static final QName IP_ENTRY_ELEMENT_NAME = new QName(ProfileHandlerNamespaceHandler.NAMESPACE, "IPEntry");
    44
    45      /** Class logger. */
    46      private final Logger log = LoggerFactory.getLogger(IPAddressLoginHandlerBeanDefinitionParser.class);
    47
    48      /** {@inheritDoc} */
    49      protected Class getBeanClass(Element element) {
    50          return IPAddressLoginHandlerFactoryBean.class;
    51      }
    52
    53      /** {@inheritDoc} */
    54      protected void doParse(Element config, BeanDefinitionBuilder builder) {
    55          super.doParse(config, builder);
    56
    57          boolean defaultDeny = XMLHelper.getAttributeValueAsBoolean(config.getAttributeNodeNS(null, "defaultDeny"));
    58          log.debug("Setting defaultDeny to: {}", defaultDeny);
    59          builder.addPropertyValue("defaultDeny", defaultDeny);
    60
    61          String username = DatatypeHelper.safeTrim(config.getAttributeNS(null, "username"));
    62          log.debug("Setting username to: {}", username);
    63          builder.addPropertyValue("username", username);
    64
    65          Map<QName, List<Element>> children = XMLHelper.getChildElements(config);
    66          List<Element> ipEntries = children.get(IP_ENTRY_ELEMENT_NAME);
    67          List<String> addresses = new ArrayList<String>();
    68
    69          for (Element element : ipEntries) {
    70              String address = DatatypeHelper.safeTrimOrNullString(element.getTextContent());
    71              if (address != null) {
    72                  log.debug("Adding IP Address: {}", address);
    73                  addresses.add(address);
    74              }
    75          }
    76          builder.addPropertyValue("addresses", addresses);
    77      }
    78  }