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