View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.idp.config.profile.authn;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.opensaml.xml.util.DatatypeHelper;
24  import org.opensaml.xml.util.XMLHelper;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
28  import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
29  import org.w3c.dom.Element;
30  
31  import edu.internet2.middleware.shibboleth.common.config.SpringConfigurationUtils;
32  import edu.internet2.middleware.shibboleth.idp.config.profile.ProfileHandlerNamespaceHandler;
33  
34  /**
35   * Base class for authentication handler definition parsers.
36   */
37  public abstract class AbstractLoginHandlerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
38  
39      /** Class logger. */
40      private static Logger log = LoggerFactory.getLogger(AbstractLoginHandlerBeanDefinitionParser.class);
41  
42      /** {@inheritDoc} */
43      protected void doParse(Element config, BeanDefinitionBuilder builder) {
44          log.debug("Parsing configuration for {} authentication handler.", XMLHelper.getXSIType(config).getLocalPart());
45  
46          long duration = 30 * 60 * 1000;
47          if (config.hasAttributeNS(null, "authenticationDuration")) {
48              duration = SpringConfigurationUtils.parseDurationToMillis("'authenticationDuration' on LoginHandler of type "
49                      + XMLHelper.getXSIType(config), config.getAttributeNS(null, "authenticationDuration"), 1000 * 60);
50          }
51          log.debug("Authentication duration: {}ms", duration);
52          builder.addPropertyValue("authenticationDuration", duration);
53  
54          String authnMethod;
55          ArrayList<String> authnMethods = new ArrayList<String>();
56          List<Element> authnMethodElems = XMLHelper.getChildElementsByTagNameNS(config,
57                  ProfileHandlerNamespaceHandler.NAMESPACE, "AuthenticationMethod");
58          for (Element authnMethodElem : authnMethodElems) {
59              authnMethod = DatatypeHelper.safeTrimOrNullString(authnMethodElem.getTextContent());
60              log.debug("Authentication handler declared support for authentication method {}", authnMethod);
61              authnMethods.add(authnMethod);
62          }
63          builder.addPropertyValue("authenticationMethods", authnMethods);
64      }
65  
66      /** {@inheritDoc} */
67      protected boolean shouldGenerateId() {
68          return true;
69      }
70  }