Coverage Summary for Class: SQLAccessControlContextFactory (com.acciente.oacc.sql)

Class Class, % Method, % Line, %
SQLAccessControlContextFactory 100% (1/ 1) 57.1% (4/ 7) 44.4% (4/ 9)


1 /* 2  * Copyright 2009-2018, Acciente LLC 3  * 4  * Acciente LLC licenses this file to you under the 5  * Apache License, Version 2.0 (the "License"); you 6  * may not use this file except in compliance with the 7  * 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 12  * writing, software distributed under the License is 13  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 14  * OR CONDITIONS OF ANY KIND, either express or implied. 15  * See the License for the specific language governing 16  * permissions and limitations under the License. 17  */ 18 package com.acciente.oacc.sql; 19  20 import com.acciente.oacc.AccessControlContext; 21 import com.acciente.oacc.AuthenticationProvider; 22 import com.acciente.oacc.encryptor.PasswordEncryptor; 23 import com.acciente.oacc.sql.internal.SQLAccessControlContext; 24  25 import javax.sql.DataSource; 26 import java.sql.Connection; 27  28 /** 29  * The factory that provides OACC's AccessControlContext implementation, which is backed by a database. 30  */ 31 public class SQLAccessControlContextFactory { 32  33  /** 34  * Creates an {@link AccessControlContext} instance backed by the specified database connection. A set of valid 35  * OACC database tables are expected to reside in the specified schema. The dialect of SQL supported by the database 36  * server for which the connection is provided is specified using the SQLProfile parameter. The access control 37  * context returned by this method uses the built-in authentication provider for resource authentication. The 38  * built-in authentication provider delegates all password encryption and decryption to the {@link PasswordEncryptor} 39  * instance provided -- therefore it is imperative that the {@link PasswordEncryptor} instance is able to decrypt 40  * existing resource passwords. 41  * 42  * @param connection a database connection with access to the required OACC tables 43  * @param schemaName the name of the schema in the database containing the OACC tables 44  * @param sqlProfile the database provider and dialect of SQL supported for the database server associated 45  * with the connection provided 46  * @param passwordEncryptor a {@link PasswordEncryptor} instance to which the built-in authentication provider 47  * delegates all password encryption and decryption 48  * @return an {@link AccessControlContext} instance ready to receive API calls 49  */ 50  public static AccessControlContext getAccessControlContext(Connection connection, 51  String schemaName, 52  SQLProfile sqlProfile, 53  PasswordEncryptor passwordEncryptor) { 54  return SQLAccessControlContext.getAccessControlContext(connection, 55  schemaName, 56  sqlProfile, 57  passwordEncryptor); 58  } 59  60  /** 61  * Creates an {@link AccessControlContext} instance backed by the specified database data source. A set of valid 62  * OACC database tables are expected to reside in the specified schema. The dialect of SQL supported by the database 63  * server for which the data source is provided is specified using the SQLProfile parameter. The access control 64  * context returned by this method uses the built-in authentication provider for resource authentication. The 65  * built-in authentication provider delegates all password encryption and decryption to the {@link PasswordEncryptor} 66  * instance provided -- therefore it is important that the {@link PasswordEncryptor} instance is able to decrypt 67  * existing resource passwords. 68  * 69  * @param dataSource a database data source with access to the required OACC tables 70  * @param schemaName the name of the schema in the database containing the OACC tables 71  * @param sqlProfile the database provider and dialect of SQL supported for the database server associated 72  * with the data source provided 73  * @param passwordEncryptor a {@link PasswordEncryptor} instance to which the built-in authentication provider 74  * delegates all password encryption and decryption 75  * @return an {@link AccessControlContext} instance ready to receive API calls 76  */ 77  public static AccessControlContext getAccessControlContext(DataSource dataSource, 78  String schemaName, 79  SQLProfile sqlProfile, 80  PasswordEncryptor passwordEncryptor) { 81  return SQLAccessControlContext.getAccessControlContext(dataSource, 82  schemaName, 83  sqlProfile, 84  passwordEncryptor); 85  } 86  87  /** 88  * Creates an {@link AccessControlContext} instance backed by the specified database connection. A set of valid 89  * OACC database tables are expected to reside in the specified schema. The dialect of SQL supported by the database 90  * server for which the connection is provided is specified using the SQLProfile parameter. The access control 91  * context returned by this method delegates all resource authentication to the specified custom authentication 92  * provider. 93  * 94  * @param connection a database connection with access to the required OACC tables 95  * @param schemaName the name of the schema in the database containing the OACC tables 96  * @param sqlProfile the database provider and dialect of SQL supported for the database server associated 97  * with the connection provided 98  * @param authenticationProvider an {@link AuthenticationProvider} instance to which all resource authentication is 99  * delegated 100  * @return an {@link AccessControlContext} instance ready to receive API calls 101  */ 102  public static AccessControlContext getAccessControlContext(Connection connection, 103  String schemaName, 104  SQLProfile sqlProfile, 105  AuthenticationProvider authenticationProvider) { 106  return SQLAccessControlContext.getAccessControlContext(connection, 107  schemaName, 108  sqlProfile, 109  authenticationProvider); 110  } 111  112  /** 113  * Creates an {@link AccessControlContext} instance backed by the specified database data source. A set of valid 114  * OACC database tables are expected to reside in the specified schema. The dialect of SQL supported by the database 115  * server for which the data source is provided is specified using the SQLProfile parameter. The access control 116  * context returned by this method delegates all resource authentication to the specified custom authentication 117  * provider. 118  * 119  * @param dataSource a database data source with access to the required OACC tables 120  * @param schemaName the name of the schema in the database containing the OACC tables 121  * @param sqlProfile the database provider and dialect of SQL supported for the database server associated 122  * with the connection provided 123  * @param authenticationProvider an {@link AuthenticationProvider} instance to which all resource authentication is 124  * delegated 125  * @return an {@link AccessControlContext} instance ready to receive API calls 126  */ 127  public static AccessControlContext getAccessControlContext(DataSource dataSource, 128  String schemaName, 129  SQLProfile sqlProfile, 130  AuthenticationProvider authenticationProvider) { 131  return SQLAccessControlContext.getAccessControlContext(dataSource, 132  schemaName, 133  sqlProfile, 134  authenticationProvider); 135  } 136  137  /** 138  * Re-initializes the specified deserialized accessControlContext with the specified connection. 139  * <p/> 140  * This method is only intended to be called after the specified accessControlContext was successfully 141  * deserialized, in order to reset a transient connection to a database that was not serialized. If the 142  * method is called when a data source or connection has already been initialized, the method may pass 143  * through an IllegalStateException from the accessControlContext. 144  * 145  * @param accessControlContext the accessControlContext on which to reset the database connection 146  * @param connection the database connection to be reset on the accessControlContext 147  */ 148  public static void postDeserialize(AccessControlContext accessControlContext, Connection connection) { 149  SQLAccessControlContext.postDeserialize(accessControlContext, connection); 150  } 151  152  /** 153  * Re-initializes the specified deserialized accessControlContext with the specified data source. 154  * <p/> 155  * This method is only intended to be called after the specified accessControlContext was successfully 156  * deserialized, in order to reset a transient dataSource to a database that was not serialized. If the 157  * method is called when a data source or connection has already been initialized, the method may pass 158  * through an IllegalStateException from the accessControlContext. 159  * 160  * @param accessControlContext the accessControlContext on which to reset the database connection 161  * @param dataSource the database dataSource to be reset on the accessControlContext 162  */ 163  public static void postDeserialize(AccessControlContext accessControlContext, DataSource dataSource) { 164  SQLAccessControlContext.postDeserialize(accessControlContext, dataSource); 165  } 166 }