1 /* 2 * Copyright (c) 2002-2017, Mairie de Paris 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice 10 * and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice 13 * and the following disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 * License 1.0 33 */ 34 package fr.paris.lutece.plugins.mylutece.modules.openiddatabase.authentication.business; 35 36 import fr.paris.lutece.portal.service.plugin.Plugin; 37 import fr.paris.lutece.portal.service.spring.SpringContextService; 38 39 import java.util.Collection; 40 import java.util.HashMap; 41 42 43 /** 44 * This class provides instances management methods (create, find, ...) for DatabaseUser objects 45 */ 46 public final class OpenIdDatabaseUserHome 47 { 48 // Static variable pointed at the DAO instance 49 private static IOpenIdDatabaseUserDAO _dao = (IOpenIdDatabaseUserDAO) SpringContextService.getPluginBean( "openiddatabase", 50 "openIdDatabaseUserDAO" ); 51 52 /** 53 * Private constructor - this class need not be instantiated 54 */ 55 private OpenIdDatabaseUserHome( ) 56 { 57 } 58 59 /** 60 * Creation of an instance of databaseUser 61 * 62 * @param databaseUser The instance of the DatabaseUser which contains the informations to store 63 * @param strPassword The user's password 64 * @param plugin The current plugin using this method 65 * @return The instance of DatabaseUser which has been created with its primary key. 66 */ 67 public static OpenIdDatabaseUser create( OpenIdDatabaseUser databaseUser, String strPassword, Plugin plugin ) 68 { 69 _dao.insert( databaseUser, strPassword, plugin ); 70 71 return databaseUser; 72 } 73 74 /** 75 * Update of the databaseUser which is specified in parameter 76 * 77 * @param databaseUser The instance of the DatabaseUser which contains the data to store 78 * @param plugin The current plugin using this method 79 * @return The instance of the DatabaseUser which has been updated 80 */ 81 public static OpenIdDatabaseUser update( OpenIdDatabaseUser databaseUser, Plugin plugin ) 82 { 83 _dao.store( databaseUser, plugin ); 84 85 return databaseUser; 86 } 87 88 /** 89 * Update of the databaseUser who updates profile 90 * 91 * @param databaseUser The instance of the DatabaseUser which contains the data to store 92 * @param plugin The current plugin using this method 93 * @return The instance of the DatabaseUser which has been updated 94 */ 95 public static OpenIdDatabaseUser updateByLogin( OpenIdDatabaseUser databaseUser, Plugin plugin ) 96 { 97 _dao.storeByLogin( databaseUser, plugin ); 98 99 return databaseUser; 100 } 101 102 /** 103 * Update of the databaseUser which is specified in parameter 104 * 105 * @param databaseUser The instance of the DatabaseUser which contains the data to store 106 * @param strNewPassword The new password to store 107 * @param plugin The current plugin using this method 108 * @return The instance of the DatabaseUser which has been updated 109 */ 110 public static OpenIdDatabaseUser updatePassword( OpenIdDatabaseUser databaseUser, String strNewPassword, 111 Plugin plugin ) 112 { 113 _dao.updatePassword( databaseUser, strNewPassword, plugin ); 114 115 return databaseUser; 116 } 117 118 /** 119 * Remove the databaseUser whose identifier is specified in parameter 120 * 121 * @param databaseUser The DatabaseUser object to remove 122 * @param plugin The current plugin using this method 123 */ 124 public static void remove( OpenIdDatabaseUser databaseUser, Plugin plugin ) 125 { 126 _dao.delete( databaseUser, plugin ); 127 } 128 129 /////////////////////////////////////////////////////////////////////////// 130 // Finders 131 132 /** 133 * Returns an instance of a DatabaseUser whose identifier is specified in parameter 134 * 135 * @param nKey The Primary key of the databaseUser 136 * @param plugin The current plugin using this method 137 * @return An instance of DatabaseUser 138 */ 139 public static OpenIdDatabaseUser findByPrimaryKey( int nKey, Plugin plugin ) 140 { 141 return _dao.load( nKey, plugin ); 142 } 143 144 /** 145 * Returns a collection of DatabaseUser objects 146 * @param plugin The current plugin using this method 147 * @return A collection of DatabaseUser 148 */ 149 public static Collection findDatabaseUsersList( Plugin plugin ) 150 { 151 return _dao.selectDatabaseUserList( plugin ); 152 } 153 154 /** 155 * Returns a collection of DatabaseUser objects for a login 156 * 157 * @param strLogin The login of the databseUser 158 * @param plugin The current plugin using this method 159 * @return A collection of DatabaseUser 160 */ 161 public static Collection findDatabaseUsersListForLogin( String strLogin, Plugin plugin ) 162 { 163 return _dao.selectDatabaseUserListForLogin( strLogin, plugin ); 164 } 165 166 /** 167 * Returns a DatabaseUser by email 168 * 169 * @param strEmail The email of the databaseUser 170 * @param plugin The current plugin using this method 171 * @return A collection of DatabaseUser 172 */ 173 public static OpenIdDatabaseUser selectDatabaseUserByEmail( String strEmail, Plugin plugin ) 174 { 175 return _dao.selectDatabaseUserByEmail( strEmail, plugin ); 176 } 177 178 /** 179 * Returns the password of the specified user 180 * 181 * @param nKey The Primary key of the databaseUser 182 * @param plugin The current plugin using this method 183 * @return An instance of DatabaseUser 184 */ 185 public static String findPasswordByPrimaryKey( int nKey, Plugin plugin ) 186 { 187 return _dao.selectPasswordByPrimaryKey( nKey, plugin ); 188 } 189 190 /** 191 * Check the password for a DatabaseUser 192 * 193 * @param strLogin The user login of DatabaseUser 194 * @param strPassword The password of DatabaseUser 195 * @param plugin The Plugin using this data access service 196 * @return true if password is ok 197 */ 198 public static boolean checkPassword( String strLogin, String strPassword, Plugin plugin ) 199 { 200 return _dao.checkPassword( strLogin, strPassword, plugin ); 201 } 202 203 public static boolean checkUserLogin( String strLogin, Plugin plugin ) 204 { 205 return _dao.checkUserLogin( strLogin, plugin ); 206 } 207 }