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.attribute.resolver.dataConnector; 19 20 import javax.sql.DataSource; 21 22 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.StoredIDDataConnector; 23 24 /** Spring factory bean for {@link StoredIDDataConnector}s. */ 25 public class StoredIDDataConnectorBeanFactory extends BaseDataConnectorFactoryBean { 26 27 /** Datasource used to communicate with database. */ 28 private DataSource datasource; 29 30 /** SQL query timeout in milliseconds. */ 31 private long queryTimeout; 32 33 /** ID of the attribute generated by the connector. */ 34 private String generatedAttribute; 35 36 /** ID of the attribute whose first value is used when generating the computed ID. */ 37 private String sourceAttribute; 38 39 /** Salt used when computing the ID. */ 40 private byte[] salt; 41 42 /** {@inheritDoc} */ 43 public Class getObjectType() { 44 return StoredIDDataConnector.class; 45 } 46 47 /** 48 * Gets the datasource used to communicate with database. 49 * 50 * @return datasource used to communicate with database 51 */ 52 public DataSource getDatasource() { 53 return datasource; 54 } 55 56 /** 57 * Sets the datasource used to communicate with database. 58 * 59 * @param source datasource used to communicate with database 60 */ 61 public void setDatasource(DataSource source) { 62 datasource = source; 63 } 64 65 /** 66 * Gets the timeout, in milliseconds, of the SQL query. 67 * 68 * @return timeout, in milliseconds, of the SQL query. 69 */ 70 public long getQueryTimeout() { 71 return queryTimeout; 72 } 73 74 /** 75 * Sets the timeout, in milliseconds, of the SQL query. 76 * 77 * @param timeout timeout, in milliseconds, of the SQL query. 78 */ 79 public void setQueryTimeout(long timeout) { 80 queryTimeout = timeout; 81 } 82 83 /** 84 * Gets the ID of the attribute generated by the connector. 85 * 86 * @return ID of the attribute generated by the connector 87 */ 88 public String getGeneratedAttribute() { 89 return generatedAttribute; 90 } 91 92 /** 93 * Sets the ID of the attribute generated by the connector. 94 * 95 * @param id ID of the attribute generated by the connector 96 */ 97 public void setGeneratedAttribute(String id) { 98 generatedAttribute = id; 99 } 100 101 /** 102 * Gets the ID of the attribute whose first value is used when generating the computed ID. 103 * 104 * @return ID of the attribute whose first value is used when generating the computed ID 105 */ 106 public String getSourceAttribute() { 107 return sourceAttribute; 108 } 109 110 /** 111 * Sets the ID of the attribute whose first value is used when generating the computed ID. 112 * 113 * @param id ID of the attribute whose first value is used when generating the computed ID 114 */ 115 public void setSourceAttribute(String id) { 116 this.sourceAttribute = id; 117 } 118 119 /** 120 * Gets the salt used when computing the ID. 121 * 122 * @return salt used when computing the ID 123 */ 124 public byte[] getSalt() { 125 return salt; 126 } 127 128 /** 129 * Sets the salt used when computing the ID. 130 * 131 * @param salt salt used when computing the ID 132 */ 133 public void setSalt(byte[] salt) { 134 this.salt = salt; 135 } 136 137 /** {@inheritDoc} */ 138 protected Object createInstance() throws Exception { 139 StoredIDDataConnector connector = new StoredIDDataConnector(getDatasource(), (int) (queryTimeout / 1000), 140 getGeneratedAttribute(), getSourceAttribute(), getSalt()); 141 populateDataConnector(connector); 142 return connector; 143 } 144 }