Revision 44652
Added by Sofia Baltzi over 7 years ago
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/ldap/MUserActionsLDAP.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.ldap; |
|
2 |
|
|
3 |
import com.unboundid.ldap.sdk.*; |
|
4 |
import eu.dnetlib.openaire.user.MigrationUser; |
|
5 |
import eu.dnetlib.openaire.user.Role; |
|
6 |
import eu.dnetlib.openaire.user.dao.RoleDAO; |
|
7 |
import eu.dnetlib.openaire.user.dao.SQLMigrationUserDAO; |
|
8 |
import eu.dnetlib.openaire.user.store.LDAPConnector; |
|
9 |
import java.sql.SQLException; |
|
10 |
|
|
11 |
/** |
|
12 |
* Created by sofia on 7/11/2016. |
|
13 |
*/ |
|
14 |
public class MUserActionsLDAP |
|
15 |
{ |
|
16 |
public static boolean authenticateUser(String email, String password) throws LDAPException |
|
17 |
{ |
|
18 |
LDAPConnection connection = LDAPConnector.v().getConnection(); |
|
19 |
String usersDN = LDAPConnector.v().getUsersDN(); |
|
20 |
|
|
21 |
try { |
|
22 |
System.out.println("checking if user " + email + " entered a correct password when logging in"); |
|
23 |
|
|
24 |
Filter filter = Filter.createEqualityFilter("mail", email); |
|
25 |
|
|
26 |
SearchRequest searchRequest = new SearchRequest(usersDN, SearchScope.SUB, filter, "userPassword"); |
|
27 |
SearchResult searchResult = connection.search(searchRequest); |
|
28 |
|
|
29 |
for (SearchResultEntry entry : searchResult.getSearchEntries()) { |
|
30 |
if (Joomla15PasswordHash.check(password, entry.getAttributeValue("userPassword"))) |
|
31 |
return true; |
|
32 |
} |
|
33 |
|
|
34 |
return false; |
|
35 |
} |
|
36 |
finally { |
|
37 |
if (connection != null) |
|
38 |
connection.close(); |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
public static String getRole(String email, String password) throws LDAPException, SQLException { |
|
43 |
boolean authenticated = authenticateUser(email, password); |
|
44 |
|
|
45 |
if (authenticated) |
|
46 |
{ |
|
47 |
SQLMigrationUserDAO muDAO = new SQLMigrationUserDAO(); |
|
48 |
MigrationUser mUser = new MigrationUser(); |
|
49 |
mUser = muDAO.fetchByEmail(email); |
|
50 |
RoleDAO roleDAO = new RoleDAO(); |
|
51 |
Role role = roleDAO.fetchById(mUser.getRoleId()); |
|
52 |
return role.getRole(); |
|
53 |
} |
|
54 |
return null; |
|
55 |
} |
|
56 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/Role.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
/** |
|
6 |
* Created by sofia on 8/11/2016. |
|
7 |
*/ |
|
8 |
public class Role implements Serializable |
|
9 |
{ |
|
10 |
private int id; |
|
11 |
private String role; |
|
12 |
|
|
13 |
public Role() { |
|
14 |
|
|
15 |
} |
|
16 |
|
|
17 |
public Role(int id) { |
|
18 |
this.id = id; |
|
19 |
} |
|
20 |
|
|
21 |
public Role(String role) { |
|
22 |
this.role = role; |
|
23 |
} |
|
24 |
|
|
25 |
public Role(int id, String role){ |
|
26 |
|
|
27 |
this.id = id; |
|
28 |
this.role = role; |
|
29 |
} |
|
30 |
|
|
31 |
public int getId(){ |
|
32 |
return id; |
|
33 |
} |
|
34 |
|
|
35 |
public void setId(int id){ |
|
36 |
this.id = id; |
|
37 |
} |
|
38 |
|
|
39 |
public String getRole() { |
|
40 |
return role; |
|
41 |
} |
|
42 |
|
|
43 |
public void setRole(String role) { |
|
44 |
this.role = role; |
|
45 |
} |
|
46 |
|
|
47 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/dao/RoleDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.openaire.user.Role; |
|
4 |
import eu.dnetlib.openaire.user.store.DataSourceConnector; |
|
5 |
import eu.dnetlib.openaire.user.store.Statement; |
|
6 |
|
|
7 |
import javax.sql.DataSource; |
|
8 |
|
|
9 |
import java.sql.Connection; |
|
10 |
import java.sql.PreparedStatement; |
|
11 |
import java.sql.ResultSet; |
|
12 |
import java.sql.SQLException; |
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import static eu.dnetlib.openaire.user.queries.RoleQueries.*; |
|
17 |
|
|
18 |
/** |
|
19 |
* Created by sofia on 8/11/2016. |
|
20 |
*/ |
|
21 |
public class RoleDAO { |
|
22 |
|
|
23 |
private final DataSource ds; |
|
24 |
|
|
25 |
public RoleDAO() { |
|
26 |
this.ds = DataSourceConnector.v().getDatasource(); |
|
27 |
} |
|
28 |
|
|
29 |
// FETCH |
|
30 |
|
|
31 |
public List<Role> fetchAll() |
|
32 |
throws SQLException |
|
33 |
{ |
|
34 |
return (List<Role>) executeQuery(FETCH_ALL); |
|
35 |
} |
|
36 |
|
|
37 |
public Role fetchById(final int id) |
|
38 |
throws SQLException |
|
39 |
{ |
|
40 |
List<Role> roles = executeQuery(FETCH_BY_ID, new Statement.Initializer() { |
|
41 |
@Override |
|
42 |
public void prepare(PreparedStatement stmt) throws SQLException { |
|
43 |
stmt.setInt(1, id); |
|
44 |
} |
|
45 |
}); |
|
46 |
|
|
47 |
if (roles.isEmpty()) |
|
48 |
return null; |
|
49 |
|
|
50 |
return roles.get(0); |
|
51 |
} |
|
52 |
|
|
53 |
public Role fetchByRole(String role) |
|
54 |
throws SQLException |
|
55 |
{ |
|
56 |
List<Role> roles = executeQuery(FETCH_BY_ROLE); |
|
57 |
|
|
58 |
if (roles.isEmpty()) |
|
59 |
return null; |
|
60 |
|
|
61 |
return roles.get(0); |
|
62 |
} |
|
63 |
|
|
64 |
public long countAll() throws SQLException |
|
65 |
{ |
|
66 |
return executeCount(COUNT_ALL); |
|
67 |
} |
|
68 |
|
|
69 |
|
|
70 |
public boolean insert(final Role role) |
|
71 |
throws SQLException |
|
72 |
{ |
|
73 |
return executeUpdate(INSERT, new Statement.Initializer() { |
|
74 |
@Override |
|
75 |
public void prepare(PreparedStatement stmt) |
|
76 |
throws SQLException { |
|
77 |
stmt.setString(1, role.getRole()); |
|
78 |
} |
|
79 |
}) > 0; |
|
80 |
|
|
81 |
} |
|
82 |
|
|
83 |
public boolean delete(final String role) |
|
84 |
throws SQLException |
|
85 |
{ |
|
86 |
return executeUpdate(DELETE, new Statement.Initializer() { |
|
87 |
@Override |
|
88 |
public void prepare(PreparedStatement stmt) |
|
89 |
throws SQLException { |
|
90 |
stmt.setString(1, role); |
|
91 |
} |
|
92 |
}) > 0; |
|
93 |
} |
|
94 |
|
|
95 |
public boolean update(final Role role) |
|
96 |
throws SQLException |
|
97 |
{ |
|
98 |
return executeUpdate(UPDATE, new Statement.Initializer() { |
|
99 |
@Override |
|
100 |
public void prepare(PreparedStatement stmt) |
|
101 |
throws SQLException { |
|
102 |
stmt.setString(1, role.getRole()); |
|
103 |
} |
|
104 |
}) > 0; |
|
105 |
} |
|
106 |
|
|
107 |
protected Role fromResultSet(ResultSet set) |
|
108 |
throws SQLException |
|
109 |
{ |
|
110 |
Role role = new Role(set.getString("role")); |
|
111 |
|
|
112 |
role.setId(set.getInt("id")); |
|
113 |
|
|
114 |
return role; |
|
115 |
} |
|
116 |
|
|
117 |
protected int executeUpdate(String sql, Statement.Initializer init) |
|
118 |
throws SQLException |
|
119 |
{ |
|
120 |
Connection connection = ds.getConnection(); |
|
121 |
|
|
122 |
try { |
|
123 |
PreparedStatement stmt = connection.prepareStatement(sql); |
|
124 |
init.prepare(stmt); |
|
125 |
return stmt.executeUpdate(); |
|
126 |
} finally { |
|
127 |
connection.close(); |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
protected List<Role> executeQuery(String sql, Statement.Initializer init) |
|
132 |
throws SQLException |
|
133 |
{ |
|
134 |
Connection connection = ds.getConnection(); |
|
135 |
|
|
136 |
try { |
|
137 |
PreparedStatement stmt = connection.prepareStatement(sql); |
|
138 |
init.prepare(stmt); |
|
139 |
|
|
140 |
ResultSet set = stmt.executeQuery(); |
|
141 |
|
|
142 |
try { |
|
143 |
List<Role> results = new ArrayList<>(); |
|
144 |
|
|
145 |
while (set.next()) |
|
146 |
results.add(fromResultSet(set)); |
|
147 |
|
|
148 |
return results; |
|
149 |
} finally { |
|
150 |
set.close(); |
|
151 |
} |
|
152 |
} finally { |
|
153 |
connection.close(); |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
protected int executeUpdate(String sql) |
|
158 |
throws SQLException |
|
159 |
{ |
|
160 |
return executeUpdate(sql, Statement.emptyInitializer()); |
|
161 |
} |
|
162 |
|
|
163 |
protected List<Role> executeQuery(String sql) |
|
164 |
throws SQLException |
|
165 |
{ |
|
166 |
return executeQuery(sql, Statement.emptyInitializer()); |
|
167 |
} |
|
168 |
|
|
169 |
public long executeCount(String sql) |
|
170 |
throws SQLException |
|
171 |
{ |
|
172 |
return executeCount(sql, Statement.emptyInitializer()); |
|
173 |
} |
|
174 |
|
|
175 |
public long executeCount(String sql, Statement.Initializer init) |
|
176 |
throws SQLException |
|
177 |
{ |
|
178 |
Connection connection = ds.getConnection(); |
|
179 |
|
|
180 |
try { |
|
181 |
PreparedStatement stmt = connection.prepareStatement(sql); |
|
182 |
init.prepare(stmt); |
|
183 |
|
|
184 |
ResultSet set = stmt.executeQuery(); |
|
185 |
|
|
186 |
try { |
|
187 |
if (set.next()) |
|
188 |
return set.getLong(1); |
|
189 |
throw new IllegalArgumentException(stmt.toString()); |
|
190 |
} finally { |
|
191 |
set.close(); |
|
192 |
} |
|
193 |
} finally { |
|
194 |
connection.close(); |
|
195 |
} |
|
196 |
} |
|
197 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/dao/SQLMigrationUserDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.openaire.user.MigrationUser; |
|
4 |
import eu.dnetlib.openaire.user.store.DataSourceConnector; |
|
5 |
import eu.dnetlib.openaire.user.store.Statement; |
|
6 |
import org.apache.commons.dbcp.BasicDataSource; |
|
7 |
|
|
8 |
import javax.sql.DataSource; |
|
9 |
import java.sql.Connection; |
|
10 |
import java.sql.PreparedStatement; |
|
11 |
import java.sql.ResultSet; |
|
12 |
import java.sql.SQLException; |
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import static eu.dnetlib.openaire.user.queries.SQLMigrationUserQueries.*; |
|
17 |
|
|
18 |
|
|
19 |
/** |
|
20 |
* Created by sofia on 1/11/2016. |
|
21 |
*/ |
|
22 |
public class SQLMigrationUserDAO { |
|
23 |
|
|
24 |
private final DataSource ds; |
|
25 |
|
|
26 |
public SQLMigrationUserDAO() { |
|
27 |
this.ds = DataSourceConnector.v().getDatasource(); |
|
28 |
} |
|
29 |
|
|
30 |
// FETCH |
|
31 |
|
|
32 |
public List<MigrationUser> fetchAll() |
|
33 |
throws SQLException |
|
34 |
{ |
|
35 |
return (List<MigrationUser>) executeQuery(FETCH_ALL); |
|
36 |
} |
|
37 |
|
|
38 |
public MigrationUser fetchById(int id) |
|
39 |
throws SQLException |
|
40 |
{ |
|
41 |
List<MigrationUser> users = executeQuery(FETCH_BY_ID); |
|
42 |
|
|
43 |
if (users.isEmpty()) |
|
44 |
return null; |
|
45 |
|
|
46 |
return users.get(0); |
|
47 |
} |
|
48 |
|
|
49 |
public MigrationUser fetchByUid(String uid) |
|
50 |
throws SQLException |
|
51 |
{ |
|
52 |
List<MigrationUser> users = executeQuery(FETCH_BY_UID); |
|
53 |
|
|
54 |
if (users.isEmpty()) |
|
55 |
return null; |
|
56 |
|
|
57 |
return users.get(0); |
|
58 |
} |
|
59 |
|
|
60 |
public MigrationUser fetchByEmail(final String email) |
|
61 |
throws SQLException |
|
62 |
{ |
|
63 |
List<MigrationUser> users = executeQuery(FETCH_BY_EMAIL, new Statement.Initializer() { |
|
64 |
@Override |
|
65 |
public void prepare(PreparedStatement stmt) throws SQLException { |
|
66 |
stmt.setString(1, email); |
|
67 |
} |
|
68 |
}); |
|
69 |
|
|
70 |
if (users.isEmpty()) |
|
71 |
return null; |
|
72 |
System.out.println("tralal"); |
|
73 |
return users.get(0); |
|
74 |
} |
|
75 |
|
|
76 |
public List<MigrationUser> fetchByRoleId(String roleId) |
|
77 |
throws SQLException |
|
78 |
{ |
|
79 |
return executeQuery(FETCH_BY_ROLE_ID); |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
public long countAll() throws SQLException |
|
84 |
{ |
|
85 |
return executeCount(COUNT_ALL); |
|
86 |
} |
|
87 |
|
|
88 |
|
|
89 |
public boolean insert(final MigrationUser mUser) |
|
90 |
throws SQLException |
|
91 |
{ |
|
92 |
return executeUpdate(INSERT, new Statement.Initializer() { |
|
93 |
@Override |
|
94 |
public void prepare(PreparedStatement stmt) |
|
95 |
throws SQLException { |
|
96 |
stmt.setString(1, mUser.getUid()); |
|
97 |
stmt.setString(2, mUser.getEmail()); |
|
98 |
//stmt.setInt(3, mUser.getRoleId()); |
|
99 |
} |
|
100 |
}) > 0; |
|
101 |
|
|
102 |
} |
|
103 |
|
|
104 |
public boolean delete(final String uid) |
|
105 |
throws SQLException |
|
106 |
{ |
|
107 |
return executeUpdate(DELETE, new Statement.Initializer() { |
|
108 |
@Override |
|
109 |
public void prepare(PreparedStatement stmt) |
|
110 |
throws SQLException { |
|
111 |
stmt.setString(1, uid); |
|
112 |
} |
|
113 |
}) > 0; |
|
114 |
} |
|
115 |
|
|
116 |
|
|
117 |
public boolean update(final MigrationUser mUser) |
|
118 |
throws SQLException |
|
119 |
{ |
|
120 |
return executeUpdate(UPDATE, new Statement.Initializer() { |
|
121 |
@Override |
|
122 |
public void prepare(PreparedStatement stmt) |
|
123 |
throws SQLException { |
|
124 |
stmt.setString(1, mUser.getUid()); |
|
125 |
stmt.setString(2, mUser.getEmail()); |
|
126 |
stmt.setInt(3, mUser.getRoleId()); |
|
127 |
} |
|
128 |
}) > 0; |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
protected MigrationUser fromResultSet(ResultSet set) |
|
133 |
throws SQLException |
|
134 |
{ |
|
135 |
MigrationUser mUser = new MigrationUser(set.getString("uid")); |
|
136 |
|
|
137 |
mUser.setId(set.getInt("id")); |
|
138 |
mUser.setEmail(set.getString("email")); |
|
139 |
mUser.setRoleId(set.getInt("role_id")); |
|
140 |
|
|
141 |
return mUser; |
|
142 |
} |
|
143 |
|
|
144 |
protected int executeUpdate(String sql, Statement.Initializer init) |
|
145 |
throws SQLException |
|
146 |
{ |
|
147 |
Connection connection = ds.getConnection(); |
|
148 |
|
|
149 |
try { |
|
150 |
PreparedStatement stmt = connection.prepareStatement(sql); |
|
151 |
init.prepare(stmt); |
|
152 |
return stmt.executeUpdate(); |
|
153 |
} finally { |
|
154 |
connection.close(); |
|
155 |
} |
|
156 |
} |
|
157 |
|
|
158 |
|
|
159 |
protected List<MigrationUser> executeQuery(String sql, Statement.Initializer init) |
|
160 |
throws SQLException |
|
161 |
{ |
|
162 |
Connection connection = ds.getConnection(); |
|
163 |
|
|
164 |
try { |
|
165 |
PreparedStatement stmt = connection.prepareStatement(sql); |
|
166 |
init.prepare(stmt); |
|
167 |
|
|
168 |
ResultSet set = stmt.executeQuery(); |
|
169 |
|
|
170 |
try { |
|
171 |
List<MigrationUser> results = new ArrayList<>(); |
|
172 |
|
|
173 |
while (set.next()) |
|
174 |
results.add(fromResultSet(set)); |
|
175 |
|
|
176 |
return results; |
|
177 |
} finally { |
|
178 |
set.close(); |
|
179 |
} |
|
180 |
} finally { |
|
181 |
connection.close(); |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
protected int executeUpdate(String sql) |
|
186 |
throws SQLException |
|
187 |
{ |
|
188 |
return executeUpdate(sql, Statement.emptyInitializer()); |
|
189 |
} |
|
190 |
|
|
191 |
protected List<MigrationUser> executeQuery(String sql) |
|
192 |
throws SQLException |
|
193 |
{ |
|
194 |
return executeQuery(sql, Statement.emptyInitializer()); |
|
195 |
} |
|
196 |
|
|
197 |
public long executeCount(String sql) |
|
198 |
throws SQLException |
|
199 |
{ |
|
200 |
return executeCount(sql, Statement.emptyInitializer()); |
|
201 |
} |
|
202 |
|
|
203 |
public long executeCount(String sql, Statement.Initializer init) |
|
204 |
throws SQLException |
|
205 |
{ |
|
206 |
Connection connection = ds.getConnection(); |
|
207 |
|
|
208 |
try { |
|
209 |
PreparedStatement stmt = connection.prepareStatement(sql); |
|
210 |
init.prepare(stmt); |
|
211 |
|
|
212 |
ResultSet set = stmt.executeQuery(); |
|
213 |
|
|
214 |
try { |
|
215 |
if (set.next()) |
|
216 |
return set.getLong(1); |
|
217 |
throw new IllegalArgumentException(stmt.toString()); |
|
218 |
} finally { |
|
219 |
set.close(); |
|
220 |
} |
|
221 |
} finally { |
|
222 |
connection.close(); |
|
223 |
} |
|
224 |
} |
|
225 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/MigrationUser.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
/** |
|
6 |
* Created by sofia on 1/11/2016. |
|
7 |
*/ |
|
8 |
public class MigrationUser implements Serializable { |
|
9 |
|
|
10 |
private int id; |
|
11 |
private String uid; |
|
12 |
private String name; // TODO LDAP display name |
|
13 |
private String email; |
|
14 |
private int roleId; |
|
15 |
|
|
16 |
public MigrationUser() { |
|
17 |
|
|
18 |
} |
|
19 |
|
|
20 |
public MigrationUser(String uid) { |
|
21 |
this.uid = uid; |
|
22 |
} |
|
23 |
|
|
24 |
public MigrationUser(int id, String uid, String email, int roleId) { |
|
25 |
|
|
26 |
this.id = id; |
|
27 |
this.uid = uid; |
|
28 |
this.email = email; |
|
29 |
this.roleId = roleId; |
|
30 |
|
|
31 |
} |
|
32 |
|
|
33 |
public int getId(){ |
|
34 |
return id; |
|
35 |
} |
|
36 |
|
|
37 |
public void setId(int id){ |
|
38 |
this.id = id; |
|
39 |
} |
|
40 |
|
|
41 |
public String getUid(){ |
|
42 |
return uid; |
|
43 |
} |
|
44 |
|
|
45 |
public void setUid(String uid){ |
|
46 |
this.uid = uid; |
|
47 |
} |
|
48 |
|
|
49 |
public String getEmail(){ |
|
50 |
return email; |
|
51 |
} |
|
52 |
|
|
53 |
public void setEmail(String email){ |
|
54 |
this.email = email; |
|
55 |
} |
|
56 |
|
|
57 |
public int getRoleId(){ |
|
58 |
return roleId; |
|
59 |
} |
|
60 |
|
|
61 |
public void setRoleId(int roleId){ |
|
62 |
this.roleId = roleId; |
|
63 |
} |
|
64 |
|
|
65 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/migration/Migration.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.migration; |
|
2 |
|
|
3 |
import com.unboundid.ldap.sdk.*; |
|
4 |
import eu.dnetlib.openaire.user.MigrationUser; |
|
5 |
import eu.dnetlib.openaire.user.dao.SQLMigrationUserDAO; |
|
6 |
import eu.dnetlib.openaire.user.ldap.MUserActionsLDAP; |
|
7 |
import eu.dnetlib.openaire.user.ldap.UserActionsLDAP; |
|
8 |
import eu.dnetlib.openaire.user.store.LDAPConnector; |
|
9 |
import org.apache.commons.dbcp.BasicDataSource; |
|
10 |
|
|
11 |
import java.sql.SQLException; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
/** |
|
15 |
* Created by sofia on 31/10/2016. |
|
16 |
*/ |
|
17 |
public class Migration { |
|
18 |
|
|
19 |
public static void main(String[] args) throws LDAPException, SQLException { |
|
20 |
|
|
21 |
// // JDBC driver name and database URL |
|
22 |
// final String DRIVER = "com.mysql.jdbc.Driver"; |
|
23 |
// final String DB_URL = "jdbc:mysql://localhost:3306/migration"; |
|
24 |
// |
|
25 |
// // Database credentials |
|
26 |
// final String USERNAME = "root"; |
|
27 |
// final String PASSWORD = "1@3$56213980"; |
|
28 |
// |
|
29 |
// |
|
30 |
// BasicDataSource bds = new BasicDataSource(); |
|
31 |
// |
|
32 |
// bds.setDriverClassName(DRIVER); |
|
33 |
// bds.setUrl(DB_URL); |
|
34 |
// bds.setUsername(USERNAME); |
|
35 |
// bds.setPassword(PASSWORD); |
|
36 |
// |
|
37 |
// bds.setMaxIdle(10); |
|
38 |
// bds.setMaxActive(100); |
|
39 |
// bds.setMaxWait(10000); |
|
40 |
// bds.setValidationQuery("select 1"); |
|
41 |
// bds.setTestOnBorrow(true); |
|
42 |
// bds.setTestWhileIdle(true); |
|
43 |
// bds.setTimeBetweenEvictionRunsMillis(1200000); |
|
44 |
// bds.setMinEvictableIdleTimeMillis(1800000); |
|
45 |
// bds.setNumTestsPerEvictionRun(5); |
|
46 |
// bds.setDefaultAutoCommit(true); |
|
47 |
// |
|
48 |
// String ldapAddress = "esperos.di.uoa.gr"; |
|
49 |
// String ldapUsername = "cn=admin,dc=openaire,dc=eu"; |
|
50 |
// String ldapPassword = "serenata"; |
|
51 |
// String ldapUsersDN = "ou=users,dc=openaire,dc=eu"; |
|
52 |
// int ldapPort = 389; |
|
53 |
|
|
54 |
// Coppy all LDAP User to my local db |
|
55 |
LDAPConnection connection = LDAPConnector.v().getConnection(); |
|
56 |
// Filter filter = Filter.create("cn=*"); |
|
57 |
// |
|
58 |
// SearchRequest searchRequest = |
|
59 |
// new SearchRequest("ou=users,dc=openaire,dc=eu", SearchScope.SUB, filter, "mail", "uid"); |
|
60 |
// |
|
61 |
// SearchResult searchResult = connection.search(searchRequest); |
|
62 |
// |
|
63 |
// List<SearchResultEntry> searchEntries = searchResult.getSearchEntries(); |
|
64 |
// |
|
65 |
// if (searchEntries.size() != 1) { |
|
66 |
// SQLMigrationUserDAO muDAO = new SQLMigrationUserDAO(); |
|
67 |
// |
|
68 |
// for (SearchResultEntry entry : searchResult.getSearchEntries()) { |
|
69 |
// MigrationUser mUser = new MigrationUser(); |
|
70 |
// mUser.setUid(entry.getAttribute("uid").getValue()); |
|
71 |
// mUser.setEmail(entry.getAttribute("mail").getValue()); |
|
72 |
// |
|
73 |
// System.out.println("User: " + mUser.getUid() + " " + mUser.getEmail()); |
|
74 |
// |
|
75 |
// try { |
|
76 |
// boolean inserted = muDAO.insert(mUser); |
|
77 |
// System.out.println("Inserted user: " + inserted); |
|
78 |
// } catch (SQLException e) { |
|
79 |
// e.printStackTrace(); |
|
80 |
// throw e; |
|
81 |
// } |
|
82 |
// } |
|
83 |
// |
|
84 |
// for (MigrationUser mUser : muDAO.fetchAll()) { |
|
85 |
// System.out.println("Added User: " + mUser.getUid() + " " + mUser.getEmail()); |
|
86 |
// } |
|
87 |
// } |
|
88 |
MUserActionsLDAP mUserActionsLDAP = new MUserActionsLDAP(); |
|
89 |
boolean authenticated = mUserActionsLDAP.authenticateUser("sba@di.uoa.gr", "12345678"); |
|
90 |
System.out.println(authenticated); |
|
91 |
System.out.println(mUserActionsLDAP.getRole("sba@di.uoa.gr", "12345678")); |
|
92 |
|
|
93 |
} |
|
94 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/queries/RoleQueries.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.queries; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sofia on 8/11/2016. |
|
5 |
*/ |
|
6 |
public interface RoleQueries { |
|
7 |
|
|
8 |
// Queries (as prepared statements to avoid SQL-injection) |
|
9 |
String FETCH_ALL = "SELECT * FROM roles"; |
|
10 |
String FETCH_BY_ID = "SELECT * FROM roles WHERE id = ?"; |
|
11 |
String FETCH_BY_ROLE = "SELECT * FROM roles WHERE role = ?"; |
|
12 |
|
|
13 |
String COUNT_ALL = "SELECT COUNT(*) FROM role"; |
|
14 |
|
|
15 |
String INSERT = "INSERT INTO roles (" + |
|
16 |
"role" + |
|
17 |
") VALUES (?)"; |
|
18 |
|
|
19 |
String UPDATE = "UPDATE roles SET " + |
|
20 |
"role = ? " + |
|
21 |
"WHERE id = ?"; |
|
22 |
|
|
23 |
String DELETE = "DELETE FROM roles WHERE id = ?"; |
|
24 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/queries/SQLMigrationUserQueries.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.queries; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sofia on 1/11/2016. |
|
5 |
*/ |
|
6 |
public interface SQLMigrationUserQueries { |
|
7 |
|
|
8 |
// Queries (as prepared statements to avoid SQL-injection) |
|
9 |
String FETCH_ALL = "SELECT * FROM users"; |
|
10 |
String FETCH_BY_ID = "SELECT * FROM users WHERE id = ?"; |
|
11 |
String FETCH_BY_UID = "SELECT * FROM users WHERE uid = ?"; |
|
12 |
String FETCH_BY_EMAIL = "SELECT * FROM users WHERE email = ?"; |
|
13 |
String FETCH_BY_ROLE_ID = "SELECT * FROM users WHERE role_id = ?"; |
|
14 |
|
|
15 |
String COUNT_ALL = "SELECT COUNT(*) FROM users"; |
|
16 |
|
|
17 |
String INSERT = "INSERT INTO users (" + |
|
18 |
"uid, " + |
|
19 |
"email, " + |
|
20 |
"role_id" + |
|
21 |
") VALUES (?,?,1)"; |
|
22 |
|
|
23 |
String UPDATE = "UPDATE users SET " + |
|
24 |
"uid = ?, " + |
|
25 |
"email = ?, " + |
|
26 |
"role_id = ? " + |
|
27 |
"WHERE id = ?"; |
|
28 |
|
|
29 |
String DELETE = "DELETE FROM users WHERE id = ?"; |
|
30 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/user/UserProfile.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.user; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sofia on 31/10/2016. |
|
5 |
*/ |
|
6 |
public class UserProfile { |
|
7 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/user/UserProfileIS.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.user; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sofia on 31/10/2016. |
|
5 |
*/ |
|
6 |
public class UserProfileIS extends UserProfile { |
|
7 |
|
|
8 |
private String username, password; |
|
9 |
private String email; |
|
10 |
private String fname, lname; |
|
11 |
private String institution; |
|
12 |
|
|
13 |
public String getUsername() { |
|
14 |
return username; |
|
15 |
} |
|
16 |
|
|
17 |
public void setUsername(String username) { |
|
18 |
this.username = username; |
|
19 |
} |
|
20 |
|
|
21 |
public String getPassword() { |
|
22 |
return password; |
|
23 |
} |
|
24 |
|
|
25 |
public void setPassword(String password) { |
|
26 |
this.password = password; |
|
27 |
} |
|
28 |
|
|
29 |
public String getEmail() { |
|
30 |
return email; |
|
31 |
} |
|
32 |
|
|
33 |
public void setEmail(String email) { |
|
34 |
this.email = email; |
|
35 |
} |
|
36 |
|
|
37 |
public String getFname() { |
|
38 |
return fname; |
|
39 |
} |
|
40 |
|
|
41 |
public void setFname(String fname) { |
|
42 |
this.fname = fname; |
|
43 |
} |
|
44 |
|
|
45 |
public String getLname() { |
|
46 |
return lname; |
|
47 |
} |
|
48 |
|
|
49 |
public void setLname(String lname) { |
|
50 |
this.lname = lname; |
|
51 |
} |
|
52 |
|
|
53 |
public void setInstitution(String institution) { |
|
54 |
this.institution = institution; |
|
55 |
} |
|
56 |
|
|
57 |
public String getInstitution() { |
|
58 |
return institution; |
|
59 |
} |
|
60 |
} |
Also available in: Unified diff
Add MigrationUser (from LDAP to DB)