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.common.attribute.resolver.provider.principalConnector;
19  
20  import java.util.List;
21  import java.util.Set;
22  
23  import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
24  import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.ShibbolethResolutionContext;
25  
26  /**
27   * Wrapper for a {@link PrincipalConnector} within a resolution context. This wrapper ensures that the connector is
28   * resolved only once per context.
29   */
30  public class ContextualPrincipalConnector implements PrincipalConnector {
31  
32      /** Wrapped principal connector. */
33      private PrincipalConnector connector;
34  
35      /** Cached result of resolving the connector. */
36      private String principal;
37  
38      /**
39       * Constructor.
40       * 
41       * @param newConnector principal connector to wrap
42       */
43      public ContextualPrincipalConnector(PrincipalConnector newConnector) {
44          this.connector = newConnector;
45      }
46  
47      /** {@inheritDoc} */
48      public List<String> getDependencyIds() {
49          return connector.getDependencyIds();
50      }
51  
52      /** {@inheritDoc} */
53      public String getFormat() {
54          return connector.getFormat();
55      }
56  
57      /** {@inheritDoc} */
58      public String getId() {
59          return connector.getId();
60      }
61  
62      /** {@inheritDoc} */
63      public Set<String> getRelyingParties() {
64          return connector.getRelyingParties();
65      }
66  
67      /** {@inheritDoc} */
68      public String resolve(ShibbolethResolutionContext resolutionContext) throws AttributeResolutionException {
69          if (principal == null) {
70              principal = connector.resolve(resolutionContext);
71          }
72  
73          return principal;
74      }
75  
76      /** {@inheritDoc} */
77      public void validate() throws AttributeResolutionException {
78          connector.validate();
79      }
80  
81  }