View Javadoc

1   /*
2    * Copyright [2007] [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.config.security;
18  
19  import java.util.ArrayList;
20  
21  import org.opensaml.ws.security.SecurityPolicyRule;
22  import org.springframework.beans.factory.config.AbstractFactoryBean;
23  
24  import edu.internet2.middleware.shibboleth.common.security.ShibbolethSecurityPolicy;
25  
26  /**
27   * Spring factory bean for producing {@link ShibbolethSecurityPolicy}s.
28   */
29  public class ShibbolethSecurityPolicyFactoryBean extends AbstractFactoryBean {
30  
31      /** Unique ID of the policy. */
32      private String policyId;
33  
34      /** Rules that make up the policy. */
35      private ArrayList<SecurityPolicyRule> policyRules;
36  
37      /** {@inheritDoc} */
38      public Class getObjectType() {
39          return ShibbolethSecurityPolicy.class;
40      }
41  
42      /**
43       * Gets the unique ID of the policy.
44       * 
45       * @return unique ID of the policy
46       */
47      public String getPolicyId() {
48          return policyId;
49      }
50  
51      /**
52       * Sets the unique ID of the policy.
53       * 
54       * @param id unique ID of the policy
55       */
56      public void setPolicyId(String id) {
57          policyId = id;
58      }
59  
60      /**
61       * Gets the rules that make up the policy.
62       * 
63       * @return rules that make up the policy
64       */
65      public ArrayList<SecurityPolicyRule> getPolicyRules() {
66          return policyRules;
67      }
68  
69      /**
70       * Sets the rules that make up the policy.
71       * 
72       * @param rules rules that make up the policy
73       */
74      public void setPolicyRules(ArrayList<SecurityPolicyRule> rules) {
75          policyRules = rules;
76      }
77  
78      /** {@inheritDoc} */
79      protected Object createInstance() throws Exception {
80          ShibbolethSecurityPolicy policy = new ShibbolethSecurityPolicy(getPolicyId());
81          if (getPolicyRules() != null) {
82              policy.getPolicyRules().addAll(getPolicyRules());
83          }
84  
85          return policy;
86      }
87  }