1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.mylutece.modules.database.authentication.business;
35
36 import fr.paris.lutece.portal.service.spring.SpringContextService;
37 import fr.paris.lutece.portal.service.util.AppLogService;
38
39 import org.springframework.beans.factory.BeanDefinitionStoreException;
40 import org.springframework.beans.factory.CannotLoadBeanClassException;
41 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
42
43
44
45
46
47
48 public final class DatabaseUserFactory
49 {
50 private static final String BEAN_DATABASE_USER_FACTORY = "mylutece-database.databaseUserFactory";
51 private String _strBeanDatabaseUser;
52 private boolean _bIsEmailUsedAsLogin;
53
54
55
56
57 private DatabaseUserFactory( )
58 {
59 }
60
61
62
63
64
65
66 public static DatabaseUserFactory getFactory( )
67 {
68 return SpringContextService.getBean( BEAN_DATABASE_USER_FACTORY );
69 }
70
71
72
73
74
75
76
77 public void setBeanDatabaseUser( String strBeanDatabaseUser )
78 {
79 _strBeanDatabaseUser = strBeanDatabaseUser;
80 }
81
82
83
84
85
86
87
88 public void setEmailUsedAsLogin( boolean bIsEmailUsedAsLogin )
89 {
90 _bIsEmailUsedAsLogin = bIsEmailUsedAsLogin;
91 }
92
93
94
95
96
97
98 public boolean isEmailUsedAsLogin( )
99 {
100 return _bIsEmailUsedAsLogin;
101 }
102
103
104
105
106
107
108 public DatabaseUser newDatabaseUser( )
109 {
110 DatabaseUser databaseUser = null;
111
112 try
113 {
114 databaseUser = SpringContextService.getBean( _strBeanDatabaseUser );
115 }
116 catch( BeanDefinitionStoreException e )
117 {
118 if ( AppLogService.isDebugEnabled( ) )
119 {
120 AppLogService.debug( "DatabaseUserFactory ERROR : could not load bean '" + e.getBeanName( ) + "' - CAUSE : " + e.getMessage( ) );
121 }
122 }
123 catch( NoSuchBeanDefinitionException e )
124 {
125 if ( AppLogService.isDebugEnabled( ) )
126 {
127 AppLogService.debug( "DatabaseUserFactory ERROR : could not load bean '" + e.getBeanName( ) + "' - CAUSE : " + e.getMessage( ) );
128 }
129 }
130 catch( CannotLoadBeanClassException e )
131 {
132 if ( AppLogService.isDebugEnabled( ) )
133 {
134 AppLogService.debug( "DatabaseUserFactory ERROR : could not load bean '" + e.getBeanName( ) + "' - CAUSE : " + e.getMessage( ) );
135 }
136 }
137
138
139 if ( databaseUser == null )
140 {
141 databaseUser = new DatabaseUser( );
142 }
143
144 return databaseUser;
145 }
146 }