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