Revision 60080
Added by Katerina Iatropoulou over 3 years ago
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/test/java/eu/dnetlib/openaire/user/AppTest.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user; |
|
2 |
|
|
3 |
import junit.framework.Test; |
|
4 |
import junit.framework.TestCase; |
|
5 |
import junit.framework.TestSuite; |
|
6 |
|
|
7 |
/** |
|
8 |
* Unit test for simple App. |
|
9 |
*/ |
|
10 |
public class AppTest |
|
11 |
extends TestCase |
|
12 |
{ |
|
13 |
/** |
|
14 |
* Create the test case |
|
15 |
* |
|
16 |
* @param testName name of the test case |
|
17 |
*/ |
|
18 |
public AppTest( String testName ) |
|
19 |
{ |
|
20 |
super( testName ); |
|
21 |
} |
|
22 |
|
|
23 |
/** |
|
24 |
* @return the suite of tests being tested |
|
25 |
*/ |
|
26 |
public static Test suite() |
|
27 |
{ |
|
28 |
return new TestSuite( AppTest.class ); |
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* Rigourous Test :-) |
|
33 |
*/ |
|
34 |
public void testApp() |
|
35 |
{ |
|
36 |
assertTrue( true ); |
|
37 |
} |
|
38 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/test/java/eu/dnetlib/openaire/user/ldap/LDAPEnhancer.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.ldap; |
|
2 |
|
|
3 |
import com.unboundid.ldap.sdk.*; |
|
4 |
import eu.dnetlib.openaire.user.pojos.migration.LDAPUser; |
|
5 |
import org.junit.Before; |
|
6 |
import org.junit.Test; |
|
7 |
|
|
8 |
/** |
|
9 |
* Created by kiatrop on 27/9/2017. |
|
10 |
*/ |
|
11 |
public class LDAPEnhancer { |
|
12 |
|
|
13 |
LDAPConnection ldapConnector; |
|
14 |
String ldapUsersDN; |
|
15 |
|
|
16 |
@Before |
|
17 |
public void init() throws LDAPException { |
|
18 |
ldapConnector = new LDAPConnection("esperos.di.uoa.gr", 389, "cn=admin,dc=openaire,dc=eu", "serenata"); |
|
19 |
ldapUsersDN = "ou=users,dc=openaire,dc=eu"; |
|
20 |
} |
|
21 |
|
|
22 |
@Test |
|
23 |
public void enhance() throws LDAPSearchException { |
|
24 |
Filter filter = Filter.createEqualityFilter("ou", "users"); |
|
25 |
SearchRequest searchRequest = new SearchRequest(ldapUsersDN, SearchScope.SUBORDINATE_SUBTREE, filter); |
|
26 |
SearchResult searchResult = ldapConnector.search(searchRequest); |
|
27 |
|
|
28 |
for (SearchResultEntry entry : searchResult.getSearchEntries()) { |
|
29 |
System.out.println(entry.getAttribute("dn")); |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 |
@Test |
|
34 |
public void getUserTest() throws LDAPSearchException { |
|
35 |
String usersDN = "ou=users,dc=openaire,dc=eu"; |
|
36 |
|
|
37 |
Filter filter = Filter.createEqualityFilter("cn","kiatrop"); |
|
38 |
SearchRequest searchRequest = |
|
39 |
new SearchRequest(usersDN, SearchScope.SUB, filter, "mail", "displayName", "cn"); |
|
40 |
|
|
41 |
SearchResult searchResult = ldapConnector.search(searchRequest); |
|
42 |
LDAPUser user = new LDAPUser(); |
|
43 |
|
|
44 |
for (SearchResultEntry entry : searchResult.getSearchEntries()) { |
|
45 |
System.out.println(entry.getAttributeValue("cn")); |
|
46 |
System.out.println(entry.getAttributeValue("mail")); |
|
47 |
System.out.println(entry.getAttributeValue("displayName")); |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/resources/eu/dnetlib/openaire/user/springContext-userManagementService.properties | ||
---|---|---|
1 |
openaire.users.db.driverClassName = org.postgresql.Driver |
|
2 |
openaire.users.db.url = jdbc:postgresql://mpagasas.di.uoa.gr:5433/MigrationUser |
|
3 |
openaire.users.db.username = postgres |
|
4 |
openaire.users.db.password = 1@3$56213980 |
|
5 |
|
|
6 |
services.userman.ldap.address = esperos.di.uoa.gr |
|
7 |
services.userman.ldap.username = cn=admin,dc=openaire,dc=eu |
|
8 |
services.userman.ldap.usersDN = ou=users,dc=openaire,dc=eu |
|
9 |
services.userman.ldap.zombiesDN = ou=zombies,dc=openaire,dc=eu |
|
10 |
|
|
11 |
services.userman.ldap.password = serenata |
|
12 |
services.userman.ldap.port = 389 |
|
13 |
|
|
14 |
#email sender properties |
|
15 |
mail.smtp.host = smtp.gmail.com |
|
16 |
mail.smtp.port = 587 |
|
17 |
mail.smtp.auth = true |
|
18 |
mail.users.username = openaire.test@gmail.com |
|
19 |
#mail.users.password = P@ssw0rD |
|
20 |
mail.smtp.from = openaire.test@gmail.com |
|
21 |
|
|
22 |
mail.users.password = ^($*@$)*!$ |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/resources/eu/dnetlib/openaire/user/springContext-userManagementService.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
4 |
xmlns:context="http://www.springframework.org/schema/context" |
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd |
|
6 |
|
|
7 |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd" |
|
8 |
default-autowire="byType"> |
|
9 |
|
|
10 |
<bean id="ldapConnector" class="eu.dnetlib.openaire.user.store.LDAPConnector"> |
|
11 |
<property name="address" value="${services.userman.ldap.address}"/> |
|
12 |
<property name="username" value="${services.userman.ldap.username}"/> |
|
13 |
<property name="usersDN" value="${services.userman.ldap.usersDN}" /> |
|
14 |
<property name="zombiesDN" value="${services.userman.ldap.zombiesDN}" /> |
|
15 |
<property name="password" value="${services.userman.ldap.password}" /> |
|
16 |
<property name="port" value="${services.userman.ldap.port}" /> |
|
17 |
</bean> |
|
18 |
|
|
19 |
<bean id="ldapActions" class="eu.dnetlib.openaire.user.utils.LDAPActions"> |
|
20 |
<property name="ldapConnector" ref="ldapConnector"/> |
|
21 |
</bean> |
|
22 |
|
|
23 |
<bean id="emailSender" class="eu.dnetlib.openaire.user.utils.EmailSender" > |
|
24 |
<property name="username" value="${mail.users.username}"/> |
|
25 |
<property name="password" value="${mail.users.password}"/> |
|
26 |
<property name="host" value="${mail.smtp.host}" /> |
|
27 |
<property name="port" value="${mail.smtp.port}" /> |
|
28 |
<property name="from" value="${mail.smtp.from}" /> |
|
29 |
<property name="auth" value="${mail.smtp.auth}" /> |
|
30 |
</bean> |
|
31 |
|
|
32 |
<bean id="mUserActionsLDAP" class="eu.dnetlib.openaire.user.ldap.MUserActionsLDAP"/> |
|
33 |
|
|
34 |
<context:component-scan base-package="eu.dnetlib.openaire.user.*"/> |
|
35 |
<context:component-scan base-package="eu.dnetlib.openaire.usermanagement.*"/> |
|
36 |
<context:annotation-config></context:annotation-config> |
|
37 |
|
|
38 |
</beans> |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/pojos/RegisteredService.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.pojos; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
import java.sql.Timestamp; |
|
5 |
import java.util.Date; |
|
6 |
|
|
7 |
public class RegisteredService implements Serializable { |
|
8 |
private String id; |
|
9 |
private String client_id; |
|
10 |
private String name; |
|
11 |
private String owner; |
|
12 |
private Timestamp date; |
|
13 |
private String registration_access_token; |
|
14 |
private String keyType; |
|
15 |
|
|
16 |
public RegisteredService() { |
|
17 |
} |
|
18 |
|
|
19 |
public RegisteredService(String client_id, String owner, String name, String registration_access_token) { |
|
20 |
this.client_id = client_id; |
|
21 |
this.owner = owner; |
|
22 |
this.name = name; |
|
23 |
this.date = new Timestamp(new Date().getTime()); |
|
24 |
this.registration_access_token = registration_access_token; |
|
25 |
this.keyType = null; |
|
26 |
} |
|
27 |
|
|
28 |
public RegisteredService(String client_id, String owner, String name, String registration_access_token, String keyType) { |
|
29 |
this.client_id = client_id; |
|
30 |
this.owner = owner; |
|
31 |
this.name = name; |
|
32 |
this.date = new Timestamp(new Date().getTime()); |
|
33 |
this.registration_access_token = registration_access_token; |
|
34 |
this.keyType = keyType; |
|
35 |
} |
|
36 |
|
|
37 |
public String getId() { |
|
38 |
return id; |
|
39 |
} |
|
40 |
|
|
41 |
public void setId(String id) { |
|
42 |
this.id = id; |
|
43 |
} |
|
44 |
|
|
45 |
public String getClientId() { |
|
46 |
return client_id; |
|
47 |
} |
|
48 |
|
|
49 |
public void setClientId(String client_id) { |
|
50 |
this.client_id = client_id; |
|
51 |
} |
|
52 |
|
|
53 |
public String getName() { |
|
54 |
return name; |
|
55 |
} |
|
56 |
|
|
57 |
public void setName(String name) { |
|
58 |
this.name = name; |
|
59 |
} |
|
60 |
|
|
61 |
public String getOwner() { |
|
62 |
return owner; |
|
63 |
} |
|
64 |
|
|
65 |
public void setOwner(String owner) { |
|
66 |
this.owner = owner; |
|
67 |
} |
|
68 |
|
|
69 |
public Timestamp getDate() { |
|
70 |
return date; |
|
71 |
} |
|
72 |
|
|
73 |
public void setDate(Timestamp date) { |
|
74 |
this.date = date; |
|
75 |
} |
|
76 |
|
|
77 |
public String getRegistrationAccessToken() { |
|
78 |
return registration_access_token; |
|
79 |
} |
|
80 |
|
|
81 |
public void setRegistrationAccessToken(String registration_access_token) { |
|
82 |
this.registration_access_token = registration_access_token; |
|
83 |
} |
|
84 |
|
|
85 |
public String getKeyType() { |
|
86 |
return keyType; |
|
87 |
} |
|
88 |
|
|
89 |
public void setKeyType(String keyType) { |
|
90 |
this.keyType = keyType; |
|
91 |
} |
|
92 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/pojos/UserVerification.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.pojos; |
|
2 |
|
|
3 |
|
|
4 |
import java.sql.Timestamp; |
|
5 |
|
|
6 |
/** |
|
7 |
* Created by sofia on 3/10/2017. |
|
8 |
*/ |
|
9 |
public class UserVerification { |
|
10 |
|
|
11 |
private int id; |
|
12 |
private String username; |
|
13 |
private String verificationCode; |
|
14 |
private Timestamp date; |
|
15 |
|
|
16 |
public UserVerification() { |
|
17 |
|
|
18 |
} |
|
19 |
|
|
20 |
public UserVerification(String username) { |
|
21 |
this.username = username; |
|
22 |
} |
|
23 |
|
|
24 |
public int getId(){ |
|
25 |
return id; |
|
26 |
} |
|
27 |
|
|
28 |
public void setId(int id){ |
|
29 |
this.id = id; |
|
30 |
} |
|
31 |
|
|
32 |
public String getUsername() { |
|
33 |
return username; |
|
34 |
} |
|
35 |
|
|
36 |
public void setUsername(String username) { |
|
37 |
this.username = username; |
|
38 |
} |
|
39 |
|
|
40 |
public String getVerificationCode() { |
|
41 |
return verificationCode; |
|
42 |
} |
|
43 |
|
|
44 |
public void setVerificationCode(String verificationCode) { |
|
45 |
this.verificationCode = verificationCode; |
|
46 |
} |
|
47 |
|
|
48 |
public Timestamp getDate() { |
|
49 |
return date; |
|
50 |
} |
|
51 |
|
|
52 |
public void setDate(Timestamp date) { |
|
53 |
this.date = date; |
|
54 |
} |
|
55 |
|
|
56 |
} |
|
57 |
|
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/pojos/RoleVerification.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.pojos; |
|
2 |
|
|
3 |
|
|
4 |
import java.sql.Timestamp; |
|
5 |
|
|
6 |
public class RoleVerification { |
|
7 |
|
|
8 |
private String id; |
|
9 |
private String email; |
|
10 |
private String verificationCode; |
|
11 |
private String verificationType; |
|
12 |
private String type; |
|
13 |
private String entity; |
|
14 |
private Timestamp date; |
|
15 |
|
|
16 |
public RoleVerification() { } |
|
17 |
|
|
18 |
public String getId() { |
|
19 |
return id; |
|
20 |
} |
|
21 |
|
|
22 |
public void setId(String id) { |
|
23 |
this.id = id; |
|
24 |
} |
|
25 |
|
|
26 |
public String getEmail() { |
|
27 |
return email; |
|
28 |
} |
|
29 |
|
|
30 |
public void setEmail(String email) { |
|
31 |
this.email = email; |
|
32 |
} |
|
33 |
|
|
34 |
public String getVerificationCode() { |
|
35 |
return verificationCode; |
|
36 |
} |
|
37 |
|
|
38 |
public void setVerificationCode(String verificationCode) { |
|
39 |
this.verificationCode = verificationCode; |
|
40 |
} |
|
41 |
|
|
42 |
public String getVerificationType() { |
|
43 |
return verificationType; |
|
44 |
} |
|
45 |
|
|
46 |
public void setVerificationType(String verificationType) { |
|
47 |
this.verificationType = verificationType; |
|
48 |
} |
|
49 |
|
|
50 |
public String getType() { |
|
51 |
return type; |
|
52 |
} |
|
53 |
|
|
54 |
public void setType(String type) { |
|
55 |
this.type = type; |
|
56 |
} |
|
57 |
|
|
58 |
public String getEntity() { |
|
59 |
return entity; |
|
60 |
} |
|
61 |
|
|
62 |
public void setEntity(String entity) { |
|
63 |
this.entity = entity; |
|
64 |
} |
|
65 |
|
|
66 |
public Timestamp getDate() { |
|
67 |
return date; |
|
68 |
} |
|
69 |
|
|
70 |
public void setDate(Timestamp date) { |
|
71 |
this.date = date; |
|
72 |
} |
|
73 |
} |
|
74 |
|
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/pojos/Email.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.pojos; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sofia on 17/5/2018. |
|
5 |
*/ |
|
6 |
public class Email { |
|
7 |
|
|
8 |
String email; |
|
9 |
String type; |
|
10 |
String subject; |
|
11 |
String body; |
|
12 |
String signature; |
|
13 |
|
|
14 |
public String getEmail() { |
|
15 |
return email; |
|
16 |
} |
|
17 |
|
|
18 |
public void setEmail(String email) { |
|
19 |
this.email = email; |
|
20 |
} |
|
21 |
|
|
22 |
public String getType() { |
|
23 |
return type; |
|
24 |
} |
|
25 |
|
|
26 |
public void setType(String type) { |
|
27 |
this.type = type; |
|
28 |
} |
|
29 |
|
|
30 |
public String getSubject() { |
|
31 |
return subject; |
|
32 |
} |
|
33 |
|
|
34 |
public void setSubject(String subject) { |
|
35 |
this.subject = subject; |
|
36 |
} |
|
37 |
|
|
38 |
public String getBody() { |
|
39 |
return body; |
|
40 |
} |
|
41 |
|
|
42 |
public void setBody(String body) { |
|
43 |
this.body = body; |
|
44 |
} |
|
45 |
|
|
46 |
public String getSignature() { |
|
47 |
return signature; |
|
48 |
} |
|
49 |
|
|
50 |
public void setSignature(String signature) { |
|
51 |
this.signature = signature; |
|
52 |
} |
|
53 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/pojos/migration/MigrationUser.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.pojos.migration; |
|
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 username; // LDAP's cn, it is unique key |
|
12 |
private String fullname; // LDAP's display name |
|
13 |
private String email; |
|
14 |
private int roleId; |
|
15 |
|
|
16 |
public MigrationUser() { |
|
17 |
} |
|
18 |
|
|
19 |
public MigrationUser(String username) { |
|
20 |
this.username = username; |
|
21 |
} |
|
22 |
|
|
23 |
public MigrationUser(int id, String username, String fullname, String email, int roleId) { |
|
24 |
|
|
25 |
this.id = id; |
|
26 |
this.username = username; |
|
27 |
this.fullname = fullname; |
|
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 getUsername(){ |
|
42 |
return username; |
|
43 |
} |
|
44 |
|
|
45 |
public void setUsername(String username){ |
|
46 |
this.username = username; |
|
47 |
} |
|
48 |
|
|
49 |
public String getFullname(){ |
|
50 |
return fullname; |
|
51 |
} |
|
52 |
|
|
53 |
public void setFullname(String fullname){ |
|
54 |
this.fullname = fullname; |
|
55 |
} |
|
56 |
public String getEmail(){ |
|
57 |
return email; |
|
58 |
} |
|
59 |
|
|
60 |
public void setEmail(String email){ |
|
61 |
this.email = email; |
|
62 |
} |
|
63 |
|
|
64 |
public int getRoleId(){ |
|
65 |
return roleId; |
|
66 |
} |
|
67 |
|
|
68 |
public void setRoleId(int roleId){ |
|
69 |
this.roleId = roleId; |
|
70 |
} |
|
71 |
|
|
72 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/pojos/migration/User.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.pojos.migration; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
/** |
|
8 |
* Created by sofia on 15/6/2016. |
|
9 |
*/ |
|
10 |
public class User implements Serializable{ |
|
11 |
|
|
12 |
private String id; |
|
13 |
private String username; |
|
14 |
private String password; |
|
15 |
private String email; |
|
16 |
private String name; |
|
17 |
private String surname; |
|
18 |
private Map<String, List<String>> roles; |
|
19 |
|
|
20 |
//private int orcid; |
|
21 |
//private String affiliation; |
|
22 |
//private String profil_provenance; |
|
23 |
|
|
24 |
//Map<String, List<String>> roles = new HashMap<String, List<String>>(); |
|
25 |
|
|
26 |
|
|
27 |
public User(){ |
|
28 |
|
|
29 |
} |
|
30 |
|
|
31 |
public User(String username) { |
|
32 |
this.username = username; |
|
33 |
} |
|
34 |
|
|
35 |
public User(String id, String username, String password, String email, String name, String surname){ |
|
36 |
|
|
37 |
this.id = id; |
|
38 |
this.username = username; |
|
39 |
this.password = password; |
|
40 |
this.email = email; |
|
41 |
this.name = name; |
|
42 |
this.surname = surname; |
|
43 |
} |
|
44 |
|
|
45 |
public String getId(){ |
|
46 |
return id; |
|
47 |
} |
|
48 |
|
|
49 |
public void setId(String id){ |
|
50 |
this.id = id; |
|
51 |
} |
|
52 |
|
|
53 |
public String getUsername() { |
|
54 |
return username; |
|
55 |
} |
|
56 |
|
|
57 |
public void setUsername(String username) { |
|
58 |
this.username = username; |
|
59 |
} |
|
60 |
|
|
61 |
public String getPassword() { |
|
62 |
return password; |
|
63 |
} |
|
64 |
|
|
65 |
public void setPassword(String password) { |
|
66 |
this.password = password; |
|
67 |
} |
|
68 |
|
|
69 |
public String getEmail() { |
|
70 |
return email; |
|
71 |
} |
|
72 |
|
|
73 |
public void setEmail(String email) { |
|
74 |
this.email = email; |
|
75 |
} |
|
76 |
|
|
77 |
public String getName() { |
|
78 |
return name; |
|
79 |
} |
|
80 |
|
|
81 |
public void setName(String name) { |
|
82 |
this.name = name; |
|
83 |
} |
|
84 |
|
|
85 |
public String getSurname() { |
|
86 |
return surname; |
|
87 |
} |
|
88 |
|
|
89 |
public void setSurname(String surname) { |
|
90 |
this.surname = surname; |
|
91 |
} |
|
92 |
|
|
93 |
public void setRoles(Map<String, List<String>> map) |
|
94 |
{ |
|
95 |
this.roles = map; |
|
96 |
} |
|
97 |
|
|
98 |
public Map<String, List<String>> getValue() |
|
99 |
{ |
|
100 |
return this.roles; |
|
101 |
} |
|
102 |
|
|
103 |
|
|
104 |
public void register(){ |
|
105 |
|
|
106 |
} |
|
107 |
public void update(){ |
|
108 |
|
|
109 |
} |
|
110 |
public void login(){ |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
|
|
115 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/pojos/migration/LDAPUser.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.pojos.migration; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sofia on 29/11/2016. |
|
5 |
*/ |
|
6 |
public class LDAPUser { |
|
7 |
|
|
8 |
private String cn; |
|
9 |
private String displayName; |
|
10 |
private String email; |
|
11 |
|
|
12 |
public LDAPUser(){ |
|
13 |
} |
|
14 |
|
|
15 |
public LDAPUser(String cn, String displayName, String email) |
|
16 |
{ |
|
17 |
|
|
18 |
this.cn = cn; |
|
19 |
this.displayName = displayName; |
|
20 |
this.email = email; |
|
21 |
} |
|
22 |
|
|
23 |
public String getCn() { |
|
24 |
return cn; |
|
25 |
} |
|
26 |
|
|
27 |
public void setCn(String cn) { |
|
28 |
this.cn = cn; |
|
29 |
} |
|
30 |
|
|
31 |
public String getDisplayName() { |
|
32 |
return displayName; |
|
33 |
} |
|
34 |
|
|
35 |
public void setDisplayName(String displayName) { |
|
36 |
this.displayName = displayName; |
|
37 |
} |
|
38 |
|
|
39 |
public String getEmail() { |
|
40 |
return email; |
|
41 |
} |
|
42 |
|
|
43 |
public void setEmail(String email) { |
|
44 |
this.email = email; |
|
45 |
} |
|
46 |
|
|
47 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/pojos/migration/Role.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.pojos.migration; |
|
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/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/store/Statement.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.store; |
|
2 |
|
|
3 |
import java.sql.PreparedStatement; |
|
4 |
import java.sql.SQLException; |
|
5 |
|
|
6 |
/** |
|
7 |
* Created by sofia on 28/6/2016. |
|
8 |
*/ |
|
9 |
|
|
10 |
public class Statement |
|
11 |
{ |
|
12 |
public interface Initializer { |
|
13 |
void prepare(PreparedStatement stmt) throws SQLException; |
|
14 |
} |
|
15 |
|
|
16 |
private static final Initializer EMPTY = new Initializer() { |
|
17 |
|
|
18 |
@Override |
|
19 |
public void prepare(PreparedStatement stmt) throws SQLException {} |
|
20 |
}; |
|
21 |
|
|
22 |
public static Initializer emptyInitializer() { |
|
23 |
return EMPTY; |
|
24 |
} |
|
25 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/store/DataSourceConnector.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.store; |
|
2 |
|
|
3 |
import org.apache.commons.dbcp.BasicDataSource; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
import org.springframework.beans.factory.annotation.Value; |
|
6 |
import org.springframework.stereotype.Component; |
|
7 |
|
|
8 |
import javax.annotation.PostConstruct; |
|
9 |
import javax.sql.DataSource; |
|
10 |
import java.sql.Connection; |
|
11 |
import java.sql.DriverManager; |
|
12 |
import java.sql.SQLException; |
|
13 |
|
|
14 |
/** |
|
15 |
* Created by sofia on 31/10/2016. |
|
16 |
*/ |
|
17 |
@Component(value = "dataSourceConnector") |
|
18 |
public class DataSourceConnector { |
|
19 |
|
|
20 |
@Value("${openaire.users.db.username}") |
|
21 |
private String username; |
|
22 |
@Value("${openaire.users.db.password}") |
|
23 |
private String password; |
|
24 |
@Value("${openaire.users.db.url}") |
|
25 |
private String dbUrl; |
|
26 |
@Value("${openaire.users.db.driverClassName}") |
|
27 |
private String driver; |
|
28 |
|
|
29 |
private static boolean driverLoad = false; |
|
30 |
|
|
31 |
private DataSource datasource; |
|
32 |
|
|
33 |
private static final Logger logger = Logger.getLogger(DataSourceConnector.class); |
|
34 |
|
|
35 |
@PostConstruct |
|
36 |
public void init() { |
|
37 |
logger.info("Initializing data source"); |
|
38 |
|
|
39 |
try { |
|
40 |
Class.forName(driver); |
|
41 |
driverLoad = true; |
|
42 |
|
|
43 |
BasicDataSource bds = new BasicDataSource(); |
|
44 |
|
|
45 |
bds.setDriverClassName(driver); |
|
46 |
bds.setUrl(dbUrl); |
|
47 |
bds.setUsername(username); |
|
48 |
bds.setPassword(password); |
|
49 |
bds.setMaxIdle(10); |
|
50 |
bds.setMaxActive(100); |
|
51 |
bds.setMaxWait(10000); |
|
52 |
bds.setValidationQuery("select 1"); |
|
53 |
bds.setTestOnBorrow(true); |
|
54 |
bds.setTestWhileIdle(true); |
|
55 |
bds.setTimeBetweenEvictionRunsMillis(1200000); |
|
56 |
bds.setMinEvictableIdleTimeMillis(1800000); |
|
57 |
bds.setNumTestsPerEvictionRun(5); |
|
58 |
bds.setDefaultAutoCommit(true); |
|
59 |
|
|
60 |
this.datasource = bds; |
|
61 |
|
|
62 |
// Test Connection |
|
63 |
getConnection().close(); |
|
64 |
logger.info("Datasource " + datasource); |
|
65 |
logger.info(datasource.getConnection()); |
|
66 |
|
|
67 |
} catch (ClassNotFoundException | SQLException exc) { |
|
68 |
logger.error("Unable to connenct to the DB. ", exc); |
|
69 |
throw new RuntimeException(exc); |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
public Connection getConnection() throws SQLException { |
|
74 |
logger.debug("dbUrl " + dbUrl); |
|
75 |
return DriverManager.getConnection(dbUrl, username, password); |
|
76 |
//return DriverManager.getConnection("jdbc:postgresql://localhost:5433/MigrationUser?user=postgres&password=mypassword"); |
|
77 |
} |
|
78 |
|
|
79 |
public String getUsername() { |
|
80 |
return username; |
|
81 |
} |
|
82 |
|
|
83 |
public void setUsername(String username) { |
|
84 |
this.username = username; |
|
85 |
} |
|
86 |
|
|
87 |
public String getPassword() { |
|
88 |
return password; |
|
89 |
} |
|
90 |
|
|
91 |
public void setPassword(String password) { |
|
92 |
this.password = password; |
|
93 |
} |
|
94 |
|
|
95 |
public String getDbUrl() { |
|
96 |
return dbUrl; |
|
97 |
} |
|
98 |
|
|
99 |
public void setDbUrl(String dbUrl) { |
|
100 |
this.dbUrl = dbUrl; |
|
101 |
} |
|
102 |
|
|
103 |
public String getDriver() { |
|
104 |
return driver; |
|
105 |
} |
|
106 |
|
|
107 |
public void setDriver(String driver) { |
|
108 |
this.driver = driver; |
|
109 |
} |
|
110 |
|
|
111 |
public DataSource getDatasource() { |
|
112 |
return datasource; |
|
113 |
} |
|
114 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/store/Connector.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.store; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sofia on 29/6/2016. |
|
5 |
*/ |
|
6 |
public class Connector |
|
7 |
{ |
|
8 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/store/LDAPConnector.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.store; |
|
2 |
|
|
3 |
import com.unboundid.ldap.sdk.LDAPConnection; |
|
4 |
import com.unboundid.ldap.sdk.LDAPException; |
|
5 |
import org.apache.log4j.Logger; |
|
6 |
|
|
7 |
/** |
|
8 |
* Created by sofia on 3/10/2016. |
|
9 |
*/ |
|
10 |
public class LDAPConnector |
|
11 |
{ |
|
12 |
|
|
13 |
private String address; |
|
14 |
private String username; |
|
15 |
private String usersDN; |
|
16 |
private String zombiesDN; |
|
17 |
private String password; |
|
18 |
private int port; |
|
19 |
|
|
20 |
private static Logger logger = Logger.getLogger(LDAPConnector.class); |
|
21 |
|
|
22 |
|
|
23 |
public LDAPConnection getConnection() throws LDAPException { |
|
24 |
logger.debug("Getting ldap connection"); |
|
25 |
return new LDAPConnection(address, port, username, password); |
|
26 |
} |
|
27 |
|
|
28 |
public String getAddress() { |
|
29 |
return address; |
|
30 |
} |
|
31 |
|
|
32 |
public void setAddress(String address) { |
|
33 |
this.address = address; |
|
34 |
} |
|
35 |
|
|
36 |
public String getUsername() { |
|
37 |
return username; |
|
38 |
} |
|
39 |
|
|
40 |
public void setUsername(String username) { |
|
41 |
this.username = username; |
|
42 |
} |
|
43 |
|
|
44 |
public String getUsersDN() { |
|
45 |
return usersDN; |
|
46 |
} |
|
47 |
|
|
48 |
public void setUsersDN(String usersDN) { |
|
49 |
this.usersDN = usersDN; |
|
50 |
} |
|
51 |
|
|
52 |
public String getZombiesDN() { |
|
53 |
return zombiesDN; |
|
54 |
} |
|
55 |
|
|
56 |
public void setZombiesDN(String zombiesDN) { |
|
57 |
this.zombiesDN = zombiesDN; |
|
58 |
} |
|
59 |
|
|
60 |
public String getPassword() { |
|
61 |
return password; |
|
62 |
} |
|
63 |
|
|
64 |
public void setPassword(String password) { |
|
65 |
this.password = password; |
|
66 |
} |
|
67 |
|
|
68 |
public int getPort() { |
|
69 |
return port; |
|
70 |
} |
|
71 |
|
|
72 |
public void setPort(int port) { |
|
73 |
this.port = port; |
|
74 |
} |
|
75 |
} |
|
76 |
|
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/handler/UserHandler.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.handler; |
|
2 |
|
|
3 |
|
|
4 |
import eu.dnetlib.openaire.user.pojos.migration.User; |
|
5 |
|
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
/** |
|
9 |
* Created by sofia on 4/8/2016. |
|
10 |
*/ |
|
11 |
public interface UserHandler { |
|
12 |
public List<User> fetchAllUsers(int limit, int offset, String keyword, String orderby, boolean descending, List<String> listTypes); |
|
13 |
|
|
14 |
public List<User> fetchAllUsers(int limit, int offset); |
|
15 |
|
|
16 |
public int countAllUsers(String s, List<String> strings); |
|
17 |
|
|
18 |
public User fetchUserById(String userId); |
|
19 |
|
|
20 |
public List<User> fetchUsersByResult(String userId, int limit, int offset, String keyword, String orderby, boolean descending, List<String> listTypes); |
|
21 |
|
|
22 |
public int countUsersByResult(String userId, String keyword, List<String> listTypes); |
|
23 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/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/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/queries/UserVerificationQueries.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.queries; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sofia on 3/10/2017. |
|
5 |
*/ |
|
6 |
public interface UserVerificationQueries { |
|
7 |
|
|
8 |
String FETCH_ALL = "SELECT * FROM user_verification"; |
|
9 |
String FETCH_BY_ID = "SELECT * FROM user_verification WHERE id = ?"; |
|
10 |
String FETCH_BY_USERNAME = "SELECT * FROM user_verification WHERE username = ?"; |
|
11 |
String FETCH_BY_VERIFICATION_CODE = "SELECT * FROM user_verification WHERE verification_code = ?"; |
|
12 |
String FETCH_BY_DATE = "SELECT * FROM user_verification WHERE date = ?"; |
|
13 |
|
|
14 |
String COUNT_ALL = "SELECT COUNT(*) FROM user_verification"; |
|
15 |
|
|
16 |
String INSERT = "INSERT INTO user_verification (" + |
|
17 |
"username, " + |
|
18 |
"verification_code, " + |
|
19 |
"date " + |
|
20 |
") VALUES (?,?,?)"; |
|
21 |
|
|
22 |
String UPDATE = "UPDATE user_verification SET " + |
|
23 |
"username = ?, " + |
|
24 |
"verification_code = ?, " + |
|
25 |
"date = ? " + |
|
26 |
"WHERE id = ?"; |
|
27 |
|
|
28 |
String DELETE = "DELETE FROM user_verification WHERE username = ?"; |
|
29 |
|
|
30 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/queries/RoleVerificationQueries.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.queries; |
|
2 |
|
|
3 |
public interface RoleVerificationQueries { |
|
4 |
|
|
5 |
String FETCH_ALL = "SELECT * FROM role_verification"; |
|
6 |
String FETCH_BY_ID = "SELECT * FROM role_verification WHERE id = ?"; |
|
7 |
String FETCH_BY_EMAIL_TYPE_ENTITY_VERIFICATION_TYPE = "SELECT * FROM role_verification " + |
|
8 |
"WHERE email = ? AND type = ? AND entity = ? AND verification_type = ?"; |
|
9 |
String FETCH_BY_TYPE_ENTITY_VERIFICATION_TYPE = "SELECT DISTINCT email FROM role_verification " + |
|
10 |
"WHERE type = ? AND entity = ? AND verification_type = ?"; |
|
11 |
|
|
12 |
|
|
13 |
String COUNT_ALL = "SELECT COUNT(*) FROM role_verification"; |
|
14 |
|
|
15 |
String INSERT = "INSERT INTO role_verification (" + |
|
16 |
"id, " + |
|
17 |
"email, " + |
|
18 |
"verification_code, " + |
|
19 |
"verification_type, " + |
|
20 |
"type, " + |
|
21 |
"entity, " + |
|
22 |
"date " + |
|
23 |
") VALUES (?,?,?,?,?,?,?)"; |
|
24 |
|
|
25 |
String UPDATE = "UPDATE role_verification SET " + |
|
26 |
"id = ?, " + |
|
27 |
"username = ?, " + |
|
28 |
"verification_code = ?, " + |
|
29 |
"verification_type = ?, " + |
|
30 |
"type = ?, " + |
|
31 |
"entity = ?, " + |
|
32 |
"date = ? " + |
|
33 |
"WHERE id = ?"; |
|
34 |
|
|
35 |
String DELETE = "DELETE FROM role_verification WHERE id = ?"; |
|
36 |
|
|
37 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/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_USERNAME = "SELECT * FROM users WHERE username = ?"; |
|
12 |
String FETCH_BY_FULLNAME = "SELECT * FROM users WHERE fullname = ?"; |
|
13 |
String FETCH_BY_EMAIL = "SELECT * FROM users WHERE email = ?"; |
|
14 |
String FETCH_BY_ROLE_ID = "SELECT * FROM users WHERE role_id = ?"; |
|
15 |
|
|
16 |
String COUNT_ALL = "SELECT COUNT(*) FROM users"; |
|
17 |
|
|
18 |
String INSERT = "INSERT INTO users (" + |
|
19 |
"username, " + |
|
20 |
"fullname, " + |
|
21 |
"email, " + |
|
22 |
"role_id" + |
|
23 |
") VALUES (?,?,?,?)"; |
|
24 |
|
|
25 |
String UPDATE = "UPDATE users SET " + |
|
26 |
"username = ?, " + |
|
27 |
"fullname = ?, " + |
|
28 |
"email = ?, " + |
|
29 |
"role_id = ? " + |
|
30 |
"WHERE id = ?"; |
|
31 |
|
|
32 |
String DELETE = "DELETE FROM users WHERE id = ?"; |
|
33 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/registeredService/RegisteredServiceSQL.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.registeredService; |
|
2 |
|
|
3 |
import eu.dnetlib.openaire.user.pojos.RegisteredService; |
|
4 |
import eu.dnetlib.openaire.user.store.DataSourceConnector; |
|
5 |
import eu.dnetlib.openaire.user.store.Statement; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.stereotype.Component; |
|
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 |
@Component(value = "registeredServiceSQL") |
|
17 |
public class RegisteredServiceSQL implements RegisteredServiceDao { |
|
18 |
|
|
19 |
@Autowired |
|
20 |
DataSourceConnector dataSourceConnector; |
|
21 |
|
|
22 |
private final static String INSERT = "INSERT INTO registered_service (" + |
|
23 |
"client_id, " + |
|
24 |
"owner, " + |
|
25 |
"name, " + |
|
26 |
"creation_date, " + |
|
27 |
"registration_access_token," + |
|
28 |
"key_type" + |
|
29 |
") VALUES (?,?,?,?,?,?)"; |
|
30 |
|
|
31 |
private final static String UPDATE = "UPDATE registered_service SET " + |
|
32 |
"name = ?, key_type = ? " + |
|
33 |
"WHERE client_id = ?"; |
|
34 |
|
|
35 |
private final static String DELETE = "DELETE FROM registered_service WHERE id = ?"; |
|
36 |
|
|
37 |
private final static String SELECT = "SELECT * FROM registered_service WHERE owner = ? ORDER BY creation_date DESC"; |
|
38 |
|
|
39 |
private final static String COUNT = "SELECT COUNT(*) FROM registered_service WHERE owner = ?"; |
|
40 |
@Override |
|
41 |
public int insertRegisteredService(final RegisteredService registeredService) |
|
42 |
throws SQLException { |
|
43 |
return executeUpdate(INSERT, new Statement.Initializer() { |
|
44 |
@Override |
|
45 |
public void prepare(PreparedStatement stmt) |
|
46 |
throws SQLException { |
|
47 |
stmt.setString(1, registeredService.getClientId()); |
|
48 |
stmt.setString(2, registeredService.getOwner()); |
|
49 |
stmt.setString(3, registeredService.getName()); |
|
50 |
stmt.setTimestamp(4, registeredService.getDate()); |
|
51 |
stmt.setString(5, registeredService.getRegistrationAccessToken()); |
|
52 |
stmt.setString(6, registeredService.getKeyType()); |
|
53 |
} |
|
54 |
}); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public boolean update(final RegisteredService registeredService) throws SQLException { |
|
59 |
System.out.println("UPDATE registered_service SET " + |
|
60 |
"name = " + registeredService.getName() + |
|
61 |
", key_type = " + registeredService.getKeyType() + |
|
62 |
" WHERE client_id = " + registeredService.getClientId()); |
|
63 |
return executeUpdate(UPDATE, new Statement.Initializer() { |
|
64 |
|
|
65 |
@Override |
|
66 |
public void prepare(PreparedStatement stmt) |
|
67 |
throws SQLException { |
|
68 |
stmt.setString(1, registeredService.getName()); |
|
69 |
stmt.setString(2, registeredService.getKeyType()); |
|
70 |
stmt.setString(3, registeredService.getClientId()); |
|
71 |
} |
|
72 |
}) > 0; |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
public boolean delete(final int id) |
|
77 |
throws SQLException { |
|
78 |
System.out.println("DELETE FROM registered_service WHERE id = " + id); |
|
79 |
|
|
80 |
return executeUpdate(DELETE, new Statement.Initializer() { |
|
81 |
@Override |
|
82 |
public void prepare(PreparedStatement stmt) |
|
83 |
throws SQLException { |
|
84 |
stmt.setInt(1, id); |
|
85 |
} |
|
86 |
}) > 0; |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public RegisteredService fetchRegisteredServiceById(final int id) throws SQLException { |
|
91 |
System.out.println("SELECT * FROM registered_service WHERE id = " +id); |
|
92 |
|
|
93 |
List<RegisteredService> registeredServices = executeQuery("SELECT * FROM registered_service WHERE id = ? ", new Statement.Initializer() { |
|
94 |
@Override |
|
95 |
public void prepare(PreparedStatement stmt) throws SQLException { |
|
96 |
stmt.setInt(1, id); |
|
97 |
} |
|
98 |
}); |
|
99 |
|
|
100 |
if (registeredServices.isEmpty()) { |
|
101 |
return null; |
|
102 |
} |
|
103 |
|
|
104 |
return registeredServices.get(0); |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public List<RegisteredService> fetchAllRegisteredServicesByOwner(final String owner) throws SQLException { |
|
109 |
List<RegisteredService> registeredServices = executeQuery(SELECT, new Statement.Initializer() { |
|
110 |
@Override |
|
111 |
public void prepare(PreparedStatement stmt) throws SQLException { |
|
112 |
stmt.setString(1, owner); |
|
113 |
} |
|
114 |
}); |
|
115 |
return registeredServices; |
|
116 |
} |
|
117 |
|
|
118 |
|
|
119 |
protected List<RegisteredService> executeQuery(String sql, Statement.Initializer init) |
|
120 |
throws SQLException { |
|
121 |
Connection connection = dataSourceConnector.getDatasource().getConnection(); |
|
122 |
|
|
123 |
try { |
|
124 |
PreparedStatement stmt = connection.prepareStatement(sql); |
|
125 |
init.prepare(stmt); |
|
126 |
|
|
127 |
ResultSet set = stmt.executeQuery(); |
|
128 |
|
|
129 |
try { |
|
130 |
List<RegisteredService> results = new ArrayList<>(); |
|
131 |
|
|
132 |
while (set.next()) |
|
133 |
results.add(fromResultSet(set)); |
|
134 |
|
|
135 |
return results; |
|
136 |
} finally { |
|
137 |
set.close(); |
|
138 |
} |
|
139 |
} finally { |
|
140 |
connection.close(); |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
protected List<RegisteredService> executeQuery(String sql) |
|
145 |
throws SQLException { |
|
146 |
return executeQuery(sql, Statement.emptyInitializer()); |
|
147 |
} |
|
148 |
|
|
149 |
protected RegisteredService fromResultSet(ResultSet set) throws SQLException { |
|
150 |
RegisteredService registeredService = new RegisteredService(); |
|
151 |
|
|
152 |
registeredService.setId(set.getString("id")); |
|
153 |
registeredService.setClientId(set.getString("client_id")); |
|
154 |
registeredService.setOwner(set.getString("owner")); |
|
155 |
registeredService.setName(set.getString("name")); |
|
156 |
registeredService.setDate(set.getTimestamp("creation_date")); |
|
157 |
registeredService.setRegistrationAccessToken(set.getString("registration_access_token")); |
|
158 |
registeredService.setKeyType(set.getString("key_type")); |
|
159 |
|
|
160 |
return registeredService; |
|
161 |
} |
|
162 |
|
|
163 |
protected int executeUpdate(String sql, Statement.Initializer init) |
|
164 |
throws SQLException { |
|
165 |
Connection connection = dataSourceConnector.getDatasource().getConnection(); |
|
166 |
try { |
|
167 |
PreparedStatement stmt = connection.prepareStatement(sql); |
|
168 |
init.prepare(stmt); |
|
169 |
return stmt.executeUpdate(); |
|
170 |
} finally { |
|
171 |
connection.close(); |
|
172 |
} |
|
173 |
} |
|
174 |
|
|
175 |
public long countRegisteredServices(String owner) throws SQLException { |
|
176 |
long numberOfRegisteredServices = executeCount(COUNT, new Statement.Initializer() { |
|
177 |
@Override |
|
178 |
public void prepare(PreparedStatement stmt) throws SQLException { |
|
179 |
stmt.setString(1, owner); |
|
180 |
} |
|
181 |
}); |
|
182 |
|
|
183 |
return numberOfRegisteredServices; |
|
184 |
} |
|
185 |
|
|
186 |
public long executeCount(String sql, Statement.Initializer init) throws SQLException { |
|
187 |
Connection connection = dataSourceConnector.getDatasource().getConnection(); |
|
188 |
|
|
189 |
try { |
|
190 |
PreparedStatement stmt = connection.prepareStatement(sql); |
|
191 |
init.prepare(stmt); |
|
192 |
|
|
193 |
ResultSet set = stmt.executeQuery(); |
|
194 |
|
|
195 |
try { |
|
196 |
if (set.next()) |
|
197 |
return set.getLong(1); |
|
198 |
throw new IllegalArgumentException(stmt.toString()); |
|
199 |
} finally { |
|
200 |
set.close(); |
|
201 |
} |
|
202 |
} finally { |
|
203 |
connection.close(); |
|
204 |
} |
|
205 |
} |
|
206 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/registeredService/RegisteredServiceActions.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.registeredService; |
|
2 |
|
|
3 |
public class RegisteredServiceActions { |
|
4 |
|
|
5 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/registeredService/RegisteredServiceDao.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.registeredService; |
|
2 |
|
|
3 |
import eu.dnetlib.openaire.user.pojos.RegisteredService; |
|
4 |
|
|
5 |
import java.sql.SQLException; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
public interface RegisteredServiceDao { |
|
9 |
|
|
10 |
public int insertRegisteredService(RegisteredService registeredService) throws SQLException; |
|
11 |
|
|
12 |
public boolean update(final RegisteredService registeredService) throws SQLException; |
|
13 |
|
|
14 |
public boolean delete(int id) throws SQLException; |
|
15 |
|
|
16 |
public RegisteredService fetchRegisteredServiceById(int id) throws SQLException; |
|
17 |
|
|
18 |
public List<RegisteredService> fetchAllRegisteredServicesByOwner(String owner) throws SQLException; |
|
19 |
|
|
20 |
public long countRegisteredServices(String owner) throws SQLException; |
|
21 |
|
|
22 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/trunk/src/main/java/eu/dnetlib/openaire/user/actions/IUserActions.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.actions; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sofia on 31/10/2016. |
|
5 |
*/ |
|
6 |
public interface IUserActions { |
|
7 |
|
|
8 |
public String addUser(String email, String password) throws Exception; |
|
9 |
|
|
10 |
public boolean activateUser(String activationId) throws Exception; |
|
11 |
|
|
12 |
public boolean isUserActivated(String email) throws Exception; |
|
13 |
|
|
14 |
public boolean userExists(String email) throws Exception; |
|
15 |
|
|
16 |
public boolean usernameExists(String username) throws Exception; |
|
17 |
|
|
18 |
public boolean correctCreds(String email, String password) throws Exception; |
|
19 |
|
|
20 |
public String prepareResetPassword(String email) throws Exception; |
|
21 |
|
|
22 |
public void resetPassword(String uuid, String password) throws Exception; |
|
23 |
|
|
24 |
public boolean isAdmin(String email) throws Exception; |
|
25 |
|
|
26 |
public void editUser(String email, String fname, String lname, String inst) |
|
27 |
throws Exception; |
|
28 |
|
|
29 |
public String addUser(String username, String email, String password, |
|
30 |
String firstName, String lastName) throws Exception; |
|
31 |
|
|
32 |
public String getEmailFromUsername(String username) throws Exception; |
|
33 |
|
|
34 |
//public UserProfile getUser(String userIdentifier) throws Exception; |
|
35 |
|
|
36 |
} |
modules/uoa-user-management/tags/uoa-user-management-2.0.2/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.dao.RoleDAO; |
|
5 |
import eu.dnetlib.openaire.user.dao.SQLMigrationUserDAO; |
|
6 |
import eu.dnetlib.openaire.user.pojos.migration.LDAPUser; |
|
7 |
import eu.dnetlib.openaire.user.pojos.migration.MigrationUser; |
|
8 |
import eu.dnetlib.openaire.user.pojos.migration.Role; |
|
9 |
import eu.dnetlib.openaire.user.store.LDAPConnector; |
|
10 |
import org.apache.log4j.Logger; |
|
11 |
import org.springframework.beans.factory.annotation.Autowired; |
|
12 |
|
|
13 |
import java.sql.SQLException; |
|
14 |
|
|
15 |
/** |
|
16 |
* Created by sofia on 7/11/2016. |
|
17 |
*/ |
|
18 |
public class MUserActionsLDAP { |
|
19 |
|
|
20 |
@Autowired |
|
21 |
private LDAPConnector ldapConnector; |
Also available in: Unified diff
Deleting wrong release