View Javadoc

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