Revision 48342
Added by Katerina Iatropoulou almost 7 years ago
modules/uoa-user-management/uoa-user-management/trunk/deploy.info | ||
---|---|---|
1 |
{ |
|
2 |
"type_source": "SVN", |
|
3 |
"goal": "package -U -T 4C source:jar", |
|
4 |
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-user-management/trunk", |
|
5 |
"deploy_repository": "dnet4-snapshots", |
|
6 |
"version": "4", |
|
7 |
"mail": "antleb@di.uoa.gr, kiatrop@di.uoa.gr, sbaltzi@di.uoa.gr", |
|
8 |
"deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", |
|
9 |
"name": "uoa-user-management" |
|
10 |
} |
|
11 |
|
modules/uoa-user-management/uoa-user-management/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/uoa-user-management/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 |
oidc.secret = U_gLOupYu2trYIOwfxGgZkkZoOHG_zGfaViOUsXcZ7qVQuF1rcJeQYKIDX1TY3z27CIoHaqq9ht2rmAiUmBRYQ |
|
7 |
oidc.id = 24e83176-1312-4ba3-bc0b-ffeebea1603e |
|
8 |
oidc.issuer = https://aai.openminted.eu/oidc/ |
|
9 |
oidc.home = http://mpagasas.di.uoa.gr:8080/uoa-user-management-1.0.0-SNAPSHOT/openid_connect_login |
|
10 |
webbapp.front = http://scoobydoo.di.uoa.gr:5000/search/find |
|
11 |
webbapp.front.path = / |
|
12 |
#webbapp.front.path = /search/ |
|
13 |
webbapp.front.domain = .di.uoa.gr |
|
14 |
|
|
15 |
services.userman.ldap.address = esperos.di.uoa.gr |
|
16 |
services.userman.ldap.username = cn=admin,dc=openaire,dc=eu |
|
17 |
services.userman.ldap.usersDN = ou=users,dc=openaire,dc=eu |
|
18 |
services.userman.ldap.password = serenata |
|
19 |
services.userman.ldap.port = 389 |
modules/uoa-user-management/uoa-user-management/trunk/src/main/resources/eu/dnetlib/openaire/user/springContext-userManagementService.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<!--<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xmlns:context="http://www.springframework.org/schema/context" |
|
4 |
xmlns="http://www.springframework.org/schema/beans" |
|
5 |
xmlns:security="http://www.springframework.org/schema/security" |
|
6 |
xmlns:util="http://www.springframework.org/schema/util" |
|
7 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd |
|
8 |
http://www.springframework.org/schema/context |
|
9 |
http://www.springframework.org/schema/context/spring-context-4.0.xsd |
|
10 |
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd |
|
11 |
http://www.springframework.org/schema/util |
|
12 |
http://www.springframework.org/schema/util/spring-util.xsd" |
|
13 |
default-autowire="byName"> --> |
|
14 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
15 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
16 |
xmlns:context="http://www.springframework.org/schema/context" |
|
17 |
xmlns:security="http://www.springframework.org/schema/security" |
|
18 |
xmlns:util="http://www.springframework.org/schema/util" |
|
19 |
xsi:schemaLocation=" |
|
20 |
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd |
|
21 |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd |
|
22 |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd |
|
23 |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd" |
|
24 |
default-autowire="byType"> |
|
25 |
|
|
26 |
|
|
27 |
<bean id="dataSourceConnector" class="eu.dnetlib.openaire.user.store.DataSourceConnector" init-method="init" autowire="byName"> |
|
28 |
<property name="username" value="${openaire.users.db.username}"/> |
|
29 |
<property name="password" value="${openaire.users.db.password}"/> |
|
30 |
<property name="dbUrl" value="${openaire.users.db.url}" /> |
|
31 |
<property name="driver" value="${openaire.users.db.driverClassName}" /> |
|
32 |
</bean> |
|
33 |
|
|
34 |
<bean id="sqlMigrationUserDAO" class="eu.dnetlib.openaire.user.dao.SQLMigrationUserDAO" autowire="byName"/> |
|
35 |
|
|
36 |
<bean id="ldapConnector" class="eu.dnetlib.openaire.user.store.LDAPConnector"> |
|
37 |
<property name="address" value="${services.userman.ldap.address}"/> |
|
38 |
<property name="username" value="${services.userman.ldap.username}"/> |
|
39 |
<property name="usersDN" value="${services.userman.ldap.usersDN}" /> |
|
40 |
<property name="password" value="${services.userman.ldap.password}" /> |
|
41 |
<property name="port" value="${services.userman.ldap.port}" /> |
|
42 |
</bean> |
|
43 |
|
|
44 |
<bean id="mUserActionsLDAP" class="eu.dnetlib.openaire.user.ldap.MUserActionsLDAP"/> |
|
45 |
|
|
46 |
<security:global-method-security pre-post-annotations="enabled" proxy-target-class="true" authentication-manager-ref="authenticationManager"/> |
|
47 |
|
|
48 |
|
|
49 |
<security:http auto-config="false" use-expressions="true" |
|
50 |
disable-url-rewriting="true" entry-point-ref="authenticationEntryPoint" |
|
51 |
pattern="/**"> |
|
52 |
|
|
53 |
<security:custom-filter before="PRE_AUTH_FILTER" ref="openIdConnectAuthenticationFilter" /> |
|
54 |
|
|
55 |
<!--<security:logout />--> |
|
56 |
|
|
57 |
</security:http> |
|
58 |
|
|
59 |
<bean id="requestContextFilter" class="org.springframework.web.filter.RequestContextFilter"/> |
|
60 |
|
|
61 |
<bean id="webexpressionHandler" |
|
62 |
class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/> |
|
63 |
|
|
64 |
|
|
65 |
<bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint" > |
|
66 |
<constructor-arg type="java.lang.String" value="/openid_connect_login"/> |
|
67 |
</bean> |
|
68 |
|
|
69 |
<security:authentication-manager alias="authenticationManager"> |
|
70 |
<security:authentication-provider ref="openIdConnectAuthenticationProvider" /> |
|
71 |
</security:authentication-manager> |
|
72 |
|
|
73 |
<bean id="openIdConnectAuthenticationProvider" class="org.mitre.openid.connect.client.OIDCAuthenticationProvider"> |
|
74 |
<property name="authoritiesMapper"> |
|
75 |
<bean class="org.mitre.openid.connect.client.NamedAdminAuthoritiesMapper"> |
|
76 |
<property name="admins" ref="namedAdmins" /> |
|
77 |
</bean> |
|
78 |
</property> |
|
79 |
</bean> |
|
80 |
|
|
81 |
<util:set id="namedAdmins" value-type="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority"> |
|
82 |
<!-- |
|
83 |
This is an example of how to set up a user as an administrator: they'll be given ROLE_ADMIN in addition to ROLE_USER. |
|
84 |
Note that having an administrator role on the IdP doesn't grant administrator access on this client. |
|
85 |
|
|
86 |
These are values from the demo "openid-connect-server-webapp" project of MITREid Connect. |
|
87 |
--> |
|
88 |
<bean class="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority"> |
|
89 |
<constructor-arg name="subject" value="subject_value" /> |
|
90 |
<constructor-arg name="issuer" value="${oidc.issuer}" /> |
|
91 |
</bean> |
|
92 |
</util:set> |
|
93 |
|
|
94 |
|
|
95 |
<bean class="eu.dnetlib.openaire.user.security.FrontEndLinkURIAuthenticationSuccessHandler" id="frontEndRedirect"> |
|
96 |
<property name="frontEndURI" value="${webbapp.front}"/> |
|
97 |
<property name="frontPath" value="${webbapp.front.path}"/> |
|
98 |
<property name="frontDomain" value="${webbapp.front.domain}"/> |
|
99 |
</bean> |
|
100 |
|
|
101 |
<bean id="securityContextLogoutHandler" class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/> |
|
102 |
<!--<bean id="logoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">--> |
|
103 |
<!--<property name="filterProcessesUrl" value="/logout"/>--> |
|
104 |
<!--<constructor-arg index="0" value="/"/>--> |
|
105 |
<!--<constructor-arg index="1">--> |
|
106 |
<!--<list>--> |
|
107 |
<!--<ref bean="securityContextLogoutHandler"/>--> |
|
108 |
<!--<!–ref bean="myLogoutHandler"/–>--> |
|
109 |
<!--</list>--> |
|
110 |
<!--</constructor-arg>--> |
|
111 |
<!--</bean>--> |
|
112 |
|
|
113 |
<bean class="eu.dnetlib.openaire.user.security.FrontEndLinkURILogoutSuccessHandler" id="frontEndRedirectLogout"/> |
|
114 |
<bean id="logoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter"> |
|
115 |
<property name="filterProcessesUrl" value="/logout"/> |
|
116 |
<constructor-arg index="0" value="/"/> |
|
117 |
<constructor-arg index="1"> |
|
118 |
<list> |
|
119 |
<ref bean="securityContextLogoutHandler"/> |
|
120 |
<!--ref bean="myLogoutHandler"/--> |
|
121 |
</list> |
|
122 |
</constructor-arg> |
|
123 |
</bean> |
|
124 |
<!-- |
|
125 |
- |
|
126 |
- The authentication filter |
|
127 |
- |
|
128 |
--> |
|
129 |
<bean id="openIdConnectAuthenticationFilter" class="org.mitre.openid.connect.client.OIDCAuthenticationFilter"> |
|
130 |
<property name="authenticationManager" ref="authenticationManager" /> |
|
131 |
<property name="issuerService" ref="staticIssuerService" /> |
|
132 |
<property name="serverConfigurationService" ref="staticServerConfigurationService" /> |
|
133 |
<property name="clientConfigurationService" ref="staticClientConfigurationService" /> |
|
134 |
<property name="authRequestOptionsService" ref="staticAuthRequestOptionsService" /> |
|
135 |
<property name="authRequestUrlBuilder" ref="plainAuthRequestUrlBuilder" /> |
|
136 |
<property name="authenticationSuccessHandler" ref="frontEndRedirect"/> |
|
137 |
|
|
138 |
</bean> |
|
139 |
|
|
140 |
<!-- |
|
141 |
Static issuer service, returns the same issuer for every request. |
|
142 |
--> |
|
143 |
<bean class="org.mitre.openid.connect.client.service.impl.StaticSingleIssuerService" id="staticIssuerService"> |
|
144 |
<property name="issuer" value="${oidc.issuer}" /> |
|
145 |
</bean> |
|
146 |
|
|
147 |
<!-- |
|
148 |
Dynamic server configuration, fetches the server's information using OIDC Discovery. |
|
149 |
--> |
|
150 |
<bean class="org.mitre.openid.connect.client.service.impl.StaticServerConfigurationService" id="staticServerConfigurationService"> |
|
151 |
<property name="servers"> |
|
152 |
<map> |
|
153 |
<entry key="${oidc.issuer}"> |
|
154 |
<bean class="org.mitre.openid.connect.config.ServerConfiguration"> |
|
155 |
<property name="issuer" value="${oidc.issuer}" /> |
|
156 |
<property name="authorizationEndpointUri" value="${oidc.issuer}authorize" /> |
|
157 |
<property name="tokenEndpointUri" value="${oidc.issuer}token" /> |
|
158 |
<property name="userInfoUri" value="${oidc.issuer}userinfo" /> |
|
159 |
<property name="jwksUri" value="${oidc.issuer}jwk" /> |
|
160 |
<property name="revocationEndpointUri" value="${oidc.issuer}revoke" /> |
|
161 |
</bean> |
|
162 |
</entry> |
|
163 |
</map> |
|
164 |
</property> |
|
165 |
</bean> |
|
166 |
|
|
167 |
|
|
168 |
<!-- |
|
169 |
Static Client Configuration. Configures a client statically by storing configuration on a per-issuer basis. |
|
170 |
|
|
171 |
<bean class="org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService" id="staticClientConfigurationService"> |
|
172 |
<property name="clients"> |
|
173 |
<map> |
|
174 |
<entry key="${oidc.issuer}"> |
|
175 |
<bean class="org.mitre.oauth2.model.RegisteredClient"> |
|
176 |
<property name="clientId" value="${oidc.id}" /> |
|
177 |
<property name="clientSecret" value="${oidc.secret}" /> |
|
178 |
<property name="scope"> |
|
179 |
<set value-type="java.lang.String"> |
|
180 |
<value>openid</value> |
|
181 |
</set> |
|
182 |
</property> xmlns:oauth="http://www.springframework.org/schema/security/oauth2" |
|
183 |
|
|
184 |
<property name="tokenEndpointAuthMethod" value="SECRET_BASIC" /> |
|
185 |
<property name="redirectUris"> |
|
186 |
<set> |
|
187 |
<value>${oidc.home}</value> |
|
188 |
</set> |
|
189 |
</property> |
|
190 |
</bean> |
|
191 |
</entry> |
|
192 |
</map> |
|
193 |
</property> |
|
194 |
</bean> |
|
195 |
--> |
|
196 |
|
|
197 |
|
|
198 |
<bean class="org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService" id="staticClientConfigurationService"> |
|
199 |
<property name="clients"> |
|
200 |
<map> |
|
201 |
<entry key="${oidc.issuer}"> |
|
202 |
<bean class="org.mitre.oauth2.model.RegisteredClient"> |
|
203 |
<property name="clientId" value="${oidc.id}" /> |
|
204 |
<property name="clientSecret" value="${oidc.secret}" /> |
|
205 |
<property name="scope"> |
|
206 |
<set value-type="java.lang.String"> |
|
207 |
<value>openid</value> |
|
208 |
</set> |
|
209 |
</property> |
|
210 |
<property name="tokenEndpointAuthMethod" value="SECRET_BASIC" /> |
|
211 |
<property name="redirectUris"> |
|
212 |
<set> |
|
213 |
<value>${oidc.home}</value> |
|
214 |
</set> |
|
215 |
</property> |
|
216 |
</bean> |
|
217 |
</entry> |
|
218 |
</map> |
|
219 |
</property> |
|
220 |
</bean> |
|
221 |
|
|
222 |
<!-- |
|
223 |
- |
|
224 |
- Auth request options service: returns the optional components of the request |
|
225 |
- |
|
226 |
--> |
|
227 |
<bean class="org.mitre.openid.connect.client.service.impl.StaticAuthRequestOptionsService" id="staticAuthRequestOptionsService"> |
|
228 |
<property name="options"> |
|
229 |
<map> |
|
230 |
<!-- Entries in this map are sent as key-value parameters to the auth request --> |
|
231 |
<!-- |
|
232 |
<entry key="display" value="page" /> |
|
233 |
<entry key="max_age" value="30" /> |
|
234 |
<entry key="prompt" value="none" /> |
|
235 |
--> |
|
236 |
</map> |
|
237 |
</property> |
|
238 |
</bean> |
|
239 |
|
|
240 |
<!-- |
|
241 |
Plain authorization request builder, puts all options as query parameters on the GET request |
|
242 |
--> |
|
243 |
<bean class="org.mitre.openid.connect.client.service.impl.PlainAuthRequestUrlBuilder" id="plainAuthRequestUrlBuilder" /> |
|
244 |
|
|
245 |
|
|
246 |
<context:component-scan base-package="eu.dnetlib.openaire.user.api.services" /> |
|
247 |
|
|
248 |
</beans> |
modules/uoa-user-management/uoa-user-management/trunk/src/main/webapp/WEB-INF/applicationContext.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
4 |
xmlns:context="http://www.springframework.org/schema/context" |
|
5 |
xmlns="http://www.springframework.org/schema/beans" |
|
6 |
xsi:schemaLocation="http://www.springframework.org/schema/beans |
|
7 |
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd |
|
8 |
http://www.springframework.org/schema/context |
|
9 |
http://www.springframework.org/schema/context/spring-context-4.2.xsd"> |
|
10 |
|
|
11 |
<import resource="classpath*:/eu/dnetlib/openaire/user/springContext-userManagementService.xml" /> |
|
12 |
|
|
13 |
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> |
|
14 |
<property name="order" value="2" /> |
|
15 |
<property name="ignoreUnresolvablePlaceholders" value="true" /> |
|
16 |
<property name="properties"> |
|
17 |
<bean class="eu.dnetlib.conf.WebappContextProperyFactory"> |
|
18 |
<property name="propertyFetcher"> |
|
19 |
<bean class="eu.dnetlib.conf.PropertyFetcher" /> |
|
20 |
</property> |
|
21 |
</bean> |
|
22 |
</property> |
|
23 |
<property name="locations"> |
|
24 |
<list> |
|
25 |
<value>classpath*:/eu/**/applicationContext*.properties</value> |
|
26 |
<value>classpath*:/eu/dnetlib/applicationContext-defaultProperties.properties</value> |
|
27 |
<value>classpath*:/eu/**/springContext-userManagementService.properties</value> |
|
28 |
|
|
29 |
<value>classpath*:/uoa-override.properties</value> |
|
30 |
<value>classpath*:/dnet-override.properties</value> |
|
31 |
</list> |
|
32 |
</property> |
|
33 |
</bean> |
|
34 |
|
|
35 |
<context:annotation-config /> |
|
36 |
|
|
37 |
</beans> |
modules/uoa-user-management/uoa-user-management/trunk/src/main/webapp/WEB-INF/dispatcher-servlet.xml | ||
---|---|---|
1 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
2 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xsi:schemaLocation="http://www.springframework.org/schema/beans |
|
4 |
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> |
|
5 |
|
|
6 |
</beans> |
modules/uoa-user-management/uoa-user-management/trunk/src/main/webapp/WEB-INF/security-context.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans:beans xmlns="http://www.springframework.org/schema/security" |
|
3 |
xmlns:beans="http://www.springframework.org/schema/beans" |
|
4 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
5 |
xmlns:security="http://www.springframework.org/schema/security" |
|
6 |
xsi:schemaLocation=" |
|
7 |
http://www.springframework.org/schema/beans |
|
8 |
http://www.springframework.org/schema/beans/spring-beans.xsd |
|
9 |
|
|
10 |
http://www.springframework.org/schema/security |
|
11 |
http://www.springframework.org/schema/security/spring-security.xsd"> |
|
12 |
|
|
13 |
<!-- Stateless RESTful services use BASIC authentication --> |
|
14 |
<!--<security:http create-session="stateless" pattern="/rest/**"> |
|
15 |
<security:intercept-url pattern="/**" access="ROLE_REST"/> |
|
16 |
<security:http-basic/> |
|
17 |
</security:http> |
|
18 |
|
|
19 |
|
|
20 |
<security:authentication-manager> |
|
21 |
<security:authentication-provider> |
|
22 |
<security:user-service> |
|
23 |
<security:user name="rest" password="rest" authorities="ROLE_REST"/> |
|
24 |
</security:user-service> |
|
25 |
</security:authentication-provider> |
|
26 |
</security:authentication-manager> |
|
27 |
--> |
|
28 |
<!-- |
|
29 |
<authentication-manager alias="authenticationManager"> |
|
30 |
<authentication-provider ref="jwtAuthenticationProvider" /> (8) |
|
31 |
</authentication-manager> |
|
32 |
|
|
33 |
--> |
|
34 |
</beans:beans> |
modules/uoa-user-management/uoa-user-management/trunk/src/main/webapp/WEB-INF/log4j.properties | ||
---|---|---|
1 |
log4j.rootLogger = DEBUG, R |
|
2 |
|
|
3 |
log4j.logger.eu.dnetlib = DEBUG |
|
4 |
log4j.logger.org.mitre.openid = DEBUG |
|
5 |
log4j.logger.org.springframework = DEBUG, S |
|
6 |
|
|
7 |
#log4j.additivity.org.springframework = false |
|
8 |
|
|
9 |
log4j.appender.R=org.apache.log4j.RollingFileAppender |
|
10 |
log4j.appender.R.File=/var/log/dnet/user-management/user-management.log |
|
11 |
log4j.appender.R.MaxFileSize=10MB |
|
12 |
log4j.appender.R.MaxBackupIndex=10 |
|
13 |
log4j.appender.R.layout=org.apache.log4j.PatternLayout |
|
14 |
log4j.appender.R.layout.ConversionPattern= %d %p %t [%c] - %m%n |
|
15 |
|
|
16 |
log4j.appender.S=org.apache.log4j.RollingFileAppender |
|
17 |
log4j.appender.S.File=/var/log/dnet/user-management/user-management-spring.log |
|
18 |
log4j.appender.S.MaxFileSize=10MB |
|
19 |
log4j.appender.S.MaxBackupIndex=10 |
|
20 |
log4j.appender.S.layout=org.apache.log4j.PatternLayout |
|
21 |
log4j.appender.S.layout.ConversionPattern= %d %p %t [%c] - %m%n |
modules/uoa-user-management/uoa-user-management/trunk/src/main/webapp/WEB-INF/web.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<web-app> |
|
3 |
|
|
4 |
<display-name>uoa-user-management</display-name> |
|
5 |
<context-param> |
|
6 |
<param-name>webAppRootKey</param-name> |
|
7 |
<param-value>uoa-user-management</param-value> |
|
8 |
</context-param> |
|
9 |
<context-param> |
|
10 |
<param-name>contextConfigLocation</param-name> |
|
11 |
<param-value> |
|
12 |
/WEB-INF/applicationContext.xml |
|
13 |
/WEB-INF/security-context.xml |
|
14 |
</param-value> |
|
15 |
</context-param> |
|
16 |
<context-param> |
|
17 |
<param-name>log4jConfigLocation</param-name> |
|
18 |
<param-value>/WEB-INF/log4j.properties</param-value> |
|
19 |
</context-param> |
|
20 |
|
|
21 |
<listener> |
|
22 |
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> |
|
23 |
</listener> |
|
24 |
<listener> |
|
25 |
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> |
|
26 |
</listener> |
|
27 |
|
|
28 |
|
|
29 |
<servlet> |
|
30 |
<servlet-name>User API</servlet-name> |
|
31 |
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class> |
|
32 |
<init-param> |
|
33 |
<param-name>com.sun.jersey.config.property.packages</param-name> |
|
34 |
<param-value>eu.dnetlib.openaire.user.api.services</param-value> |
|
35 |
</init-param> |
|
36 |
</servlet> |
|
37 |
<servlet-mapping> |
|
38 |
<servlet-name>User API</servlet-name> |
|
39 |
<url-pattern>/api/*</url-pattern> |
|
40 |
</servlet-mapping> |
|
41 |
|
|
42 |
|
|
43 |
<filter> |
|
44 |
<filter-name>CorsFilter</filter-name> |
|
45 |
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class> |
|
46 |
<init-param> |
|
47 |
<param-name>cors.allowed.origins</param-name> |
|
48 |
<param-value>*</param-value> |
|
49 |
</init-param> |
|
50 |
<init-param> |
|
51 |
<param-name>cors.allowed.methods</param-name> |
|
52 |
<param-value>GET, POST</param-value> |
|
53 |
</init-param> |
|
54 |
<init-param> |
|
55 |
<param-name>cors.exposed.headers</param-name> |
|
56 |
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials,Access-Control-Allow-Methods</param-value> |
|
57 |
</init-param> |
|
58 |
<init-param> |
|
59 |
<param-name>cors.support.credentials</param-name> |
|
60 |
<param-value>true</param-value> |
|
61 |
</init-param> |
|
62 |
</filter> |
|
63 |
<filter-mapping> |
|
64 |
<filter-name>CorsFilter</filter-name> |
|
65 |
<url-pattern>/*</url-pattern> |
|
66 |
</filter-mapping> |
|
67 |
|
|
68 |
<!-- |
|
69 |
<filter> |
|
70 |
<filter-name>requestContextFilter</filter-name> |
|
71 |
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> |
|
72 |
</filter> |
|
73 |
|
|
74 |
<filter-mapping> |
|
75 |
<filter-name>requestContextFilter</filter-name> |
|
76 |
<url-pattern>/*</url-pattern> |
|
77 |
</filter-mapping> |
|
78 |
--> |
|
79 |
<filter> |
|
80 |
<filter-name>springSecurityFilterChain</filter-name> |
|
81 |
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> |
|
82 |
</filter> |
|
83 |
|
|
84 |
<filter-mapping> |
|
85 |
<filter-name>springSecurityFilterChain</filter-name> |
|
86 |
<url-pattern>/*</url-pattern> |
|
87 |
</filter-mapping> |
|
88 |
|
|
89 |
</web-app> |
modules/uoa-user-management/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/IUserActions.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user; |
|
2 |
|
|
3 |
import eu.dnetlib.openaire.user.user.UserProfile; |
|
4 |
|
|
5 |
/** |
|
6 |
* Created by sofia on 31/10/2016. |
|
7 |
*/ |
|
8 |
public interface IUserActions { |
|
9 |
|
|
10 |
public String addUser(String email, String password) throws Exception; |
|
11 |
|
|
12 |
public boolean activateUser(String activationId) throws Exception; |
|
13 |
|
|
14 |
public boolean isUserActivated(String email) throws Exception; |
|
15 |
|
|
16 |
public boolean userExists(String email) throws Exception; |
|
17 |
|
|
18 |
public boolean usernameExists(String username) throws Exception; |
|
19 |
|
|
20 |
public boolean correctCreds(String email, String password) throws Exception; |
|
21 |
|
|
22 |
public String prepareResetPassword(String email) throws Exception; |
|
23 |
|
|
24 |
public void resetPassword(String uuid, String password) throws Exception; |
|
25 |
|
|
26 |
public boolean isAdmin(String email) throws Exception; |
|
27 |
|
|
28 |
public void editUser(String email, String fname, String lname, String inst) |
|
29 |
throws Exception; |
|
30 |
|
|
31 |
public String addUser(String username, String email, String password, |
|
32 |
String firstName, String lastName) throws Exception; |
|
33 |
|
|
34 |
public String getEmailFromUsername(String username) throws Exception; |
|
35 |
|
|
36 |
public UserProfile getUser(String userIdentifier) throws Exception; |
|
37 |
|
|
38 |
} |
modules/uoa-user-management/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 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/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/api/services/Test3Service.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.api.services; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.core.JsonProcessingException; |
|
4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
5 |
import com.google.gson.Gson; |
|
6 |
import com.google.gson.JsonObject; |
|
7 |
import com.google.gson.JsonParser; |
|
8 |
import com.unboundid.ldap.sdk.LDAPException; |
|
9 |
import eu.dnetlib.openaire.user.LDAPUser; |
|
10 |
import eu.dnetlib.openaire.user.MigrationUser; |
|
11 |
import eu.dnetlib.openaire.user.Role; |
|
12 |
import eu.dnetlib.openaire.user.dao.RoleDAO; |
|
13 |
import eu.dnetlib.openaire.user.dao.SQLMigrationUserDAO; |
|
14 |
import eu.dnetlib.openaire.user.ldap.MUserActionsLDAP; |
|
15 |
import eu.dnetlib.openaire.user.security.JWTGenerator; |
|
16 |
import eu.dnetlib.openaire.user.store.DataSourceConnector; |
|
17 |
import org.apache.log4j.Logger; |
|
18 |
import org.mitre.openid.connect.model.UserInfo; |
|
19 |
import org.springframework.beans.factory.annotation.Autowired; |
|
20 |
import org.springframework.http.*; |
|
21 |
import org.springframework.http.HttpMethod; |
|
22 |
import org.springframework.stereotype.Component; |
|
23 |
import org.springframework.web.client.RestTemplate; |
|
24 |
|
|
25 |
import javax.ws.rs.*; |
|
26 |
import javax.ws.rs.core.MediaType; |
|
27 |
import javax.ws.rs.core.Response; |
|
28 |
import java.io.OutputStream; |
|
29 |
import java.sql.SQLException; |
|
30 |
|
|
31 |
/** |
|
32 |
* Created by sofia on 24/11/2016. |
|
33 |
*/ |
|
34 |
@Component |
|
35 |
@Path("/users") |
|
36 |
public class Test3Service { |
|
37 |
|
|
38 |
private static final Logger logger = Logger.getLogger(Test3Service.class); |
|
39 |
|
|
40 |
@Autowired |
|
41 |
private SQLMigrationUserDAO sqlMigrationUserDAO; |
|
42 |
|
|
43 |
@Autowired |
|
44 |
private MUserActionsLDAP mUserActionsLDAP; |
|
45 |
|
|
46 |
@Autowired |
|
47 |
private DataSourceConnector dataSourceConnector; |
|
48 |
|
|
49 |
@GET |
|
50 |
@Path("/{userId}") |
|
51 |
@Produces(MediaType.APPLICATION_JSON) |
|
52 |
public Response getUserById(@PathParam("userId") int userId) { |
|
53 |
try { |
|
54 |
MigrationUser mUser = sqlMigrationUserDAO.fetchById(userId); |
|
55 |
|
|
56 |
// Invalide user ID |
|
57 |
if (mUser == null) { |
|
58 |
String errorMessageJson = compose404Message("Cannot find user with id " + userId + "."); |
|
59 |
|
|
60 |
return Response |
|
61 |
.status(Response.Status.NOT_FOUND) |
|
62 |
.entity(errorMessageJson) |
|
63 |
.type(MediaType.APPLICATION_JSON) |
|
64 |
.build(); |
|
65 |
} |
|
66 |
|
|
67 |
return Response.status(200).entity(composeDataResponse(mUser)).build(); |
|
68 |
} |
|
69 |
catch (SQLException e) { |
|
70 |
return Response |
|
71 |
.status(Response.Status.INTERNAL_SERVER_ERROR) |
|
72 |
.entity(compose500Message("Fail to fetch users.", e)) |
|
73 |
.type(MediaType.APPLICATION_JSON) |
|
74 |
.build(); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
/* How to check @browser ../authenticate/?username=MY_USERNAME&password=MY_PASSWORD |
|
79 |
* http://localhost:8080/uoa-user-management-1.0.0-SNAPSHOT/api/users/authenticate?username=sba&password=12345678 |
|
80 |
@GET |
|
81 |
@Path("/authenticate") |
|
82 |
@Produces(MediaType.APPLICATION_JSON) |
|
83 |
public Response authenticateUserGET(@QueryParam("username") String username, @QueryParam("password") String password) |
|
84 |
{ |
|
85 |
return commonAuthenticateFunction(username, password); |
|
86 |
|
|
87 |
}*/ |
|
88 |
|
|
89 |
@POST |
|
90 |
@Path("/authenticates") |
|
91 |
@Produces(MediaType.APPLICATION_JSON) |
|
92 |
@Consumes(MediaType.APPLICATION_JSON) |
|
93 |
public Response authenticateUserPOST(String input) { |
|
94 |
JsonObject jsonObject = new JsonParser().parse(input).getAsJsonObject(); |
|
95 |
|
|
96 |
String username = jsonObject.get("username").getAsString(); |
|
97 |
String password = jsonObject.get("password").getAsString(); |
|
98 |
|
|
99 |
return commonAuthenticateFunction(username, password); |
|
100 |
} |
|
101 |
|
|
102 |
private Response commonAuthenticateFunction(String username, String password) |
|
103 |
{ |
|
104 |
try { |
|
105 |
boolean usernameExists = mUserActionsLDAP.usernameExists(username); |
|
106 |
|
|
107 |
// if user was not found |
|
108 |
if (!usernameExists) { |
|
109 |
String errorMessageJson = compose401Message("Wrong credentials."); |
|
110 |
|
|
111 |
return Response |
|
112 |
.status(Response.Status.UNAUTHORIZED) |
|
113 |
.entity(errorMessageJson) |
|
114 |
.type(MediaType.APPLICATION_JSON) |
|
115 |
.build(); |
|
116 |
} |
|
117 |
|
|
118 |
boolean authenticated = mUserActionsLDAP.authenticate(username, password); |
|
119 |
|
|
120 |
// if user was not authenticated |
|
121 |
if (!authenticated) { |
|
122 |
return Response |
|
123 |
.status(Response.Status.UNAUTHORIZED) |
|
124 |
.entity(compose401Message("User " + username + " could not be authenticated.")) |
|
125 |
.type(MediaType.APPLICATION_JSON) |
|
126 |
.build(); |
|
127 |
} |
|
128 |
|
|
129 |
MigrationUser mUser = sqlMigrationUserDAO.fetchByUsername(username); |
|
130 |
|
|
131 |
// if user was not found in my db |
|
132 |
LDAPUser ldapUser = null; |
|
133 |
if (mUser == null) { |
|
134 |
mUser = new MigrationUser(username); |
|
135 |
ldapUser = mUserActionsLDAP.getUser(username); |
|
136 |
mUser.setFullname(ldapUser.getDisplayName()); |
|
137 |
mUser.setEmail(ldapUser.getEmail()); |
|
138 |
mUser.setRoleId(2); |
|
139 |
|
|
140 |
|
|
141 |
sqlMigrationUserDAO.insert(mUser); |
|
142 |
} |
|
143 |
return Response.status(200).entity(composeDataResponse(mUser)).type(MediaType.APPLICATION_JSON).build(); |
|
144 |
|
|
145 |
} catch (LDAPException exc) { |
|
146 |
logger.error("Fail to connect to LDAP. ", exc); |
|
147 |
return Response |
|
148 |
.status(Response.Status.INTERNAL_SERVER_ERROR) |
|
149 |
.entity(compose500Message("LDAP error.", exc)) |
|
150 |
.type(MediaType.APPLICATION_JSON) |
|
151 |
.build(); |
|
152 |
|
|
153 |
} catch (SQLException exc) { |
|
154 |
logger.error("Fail to fetch users. ", exc); |
|
155 |
return Response |
|
156 |
.status(Response.Status.INTERNAL_SERVER_ERROR) |
|
157 |
.entity(compose500Message("Fail to fetch users.", exc)) |
|
158 |
.type(MediaType.APPLICATION_JSON) |
|
159 |
.build(); |
|
160 |
} |
|
161 |
|
|
162 |
} |
|
163 |
|
|
164 |
@GET |
|
165 |
@Path("/changeRole") |
|
166 |
@Produces(MediaType.APPLICATION_JSON) |
|
167 |
public Response changeRole(@QueryParam("roleId") int roleId, @QueryParam("userId") int userId) |
|
168 |
{ |
|
169 |
RoleDAO roleDAO = new RoleDAO(); |
|
170 |
try |
|
171 |
{ |
|
172 |
Role role = roleDAO.fetchById(roleId); |
|
173 |
if (role == null) |
|
174 |
{ |
|
175 |
//fetch all roleids TODO |
|
176 |
String errorMessageJson = compose404Message("Cannot find role with id" + roleId + "."); |
|
177 |
|
|
178 |
return Response |
|
179 |
.status(Response.Status.NOT_FOUND) |
|
180 |
.entity(errorMessageJson) |
|
181 |
.type(MediaType.APPLICATION_JSON) |
|
182 |
.build(); |
|
183 |
} |
|
184 |
|
|
185 |
MigrationUser mUser = sqlMigrationUserDAO.fetchById(userId); |
|
186 |
|
|
187 |
if (mUser == null) |
|
188 |
{ |
|
189 |
String errorMessageJson = compose404Message("Cannot find user with id " + userId + "."); |
|
190 |
|
|
191 |
return Response |
|
192 |
.status(Response.Status.NOT_FOUND) |
|
193 |
.entity(errorMessageJson) |
|
194 |
.type(MediaType.APPLICATION_JSON) |
|
195 |
.build(); |
|
196 |
} |
|
197 |
|
|
198 |
mUser.setRoleId(roleId); |
|
199 |
sqlMigrationUserDAO.update(mUser); |
|
200 |
|
|
201 |
return Response.status(200).entity(composeDataResponse(mUser)).build(); |
|
202 |
} |
|
203 |
catch (SQLException exc) |
|
204 |
{ |
|
205 |
return Response |
|
206 |
.status(Response.Status.INTERNAL_SERVER_ERROR) |
|
207 |
.entity(compose500Message("Fail to fetch users.", exc)) |
|
208 |
.type(MediaType.APPLICATION_JSON) |
|
209 |
.build(); |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
@GET |
|
214 |
@Path("/getUserInfo") |
|
215 |
@Produces(MediaType.APPLICATION_JSON) |
|
216 |
public Response getUserInfo(@QueryParam("accessToken") String accessToken) throws JsonProcessingException { |
|
217 |
|
|
218 |
//return Response.status(404).entity(compose404Message("This is a test message.")).type(MediaType.APPLICATION_JSON).build(); |
|
219 |
|
|
220 |
// call aai with accessToken |
|
221 |
RestTemplate restTemplate = new RestTemplate(); |
|
222 |
HttpHeaders headers = new HttpHeaders(); |
|
223 |
headers.add("Authorization","Bearer " + accessToken); |
|
224 |
HttpEntity request = new HttpEntity(null, headers); |
|
225 |
String fooResourceUrl = "https://aai.openminted.eu/oidc/userinfo"; |
|
226 |
logger.info(restTemplate.exchange(fooResourceUrl, HttpMethod.GET, request, Object.class)); |
|
227 |
ResponseEntity response1 = restTemplate.exchange(fooResourceUrl, HttpMethod.GET, request, Object.class); |
|
228 |
logger.info(response1.getBody().toString()); |
|
229 |
ObjectMapper mapper = new ObjectMapper(); |
|
230 |
|
|
231 |
return Response.status(response1.getStatusCode().value()).entity(mapper.writeValueAsString(response1.getBody())).type(MediaType.APPLICATION_JSON).build(); |
|
232 |
|
|
233 |
} |
|
234 |
|
|
235 |
/* JSON Utility Methods */ |
|
236 |
|
|
237 |
private String compose401Message(String message) { |
|
238 |
return "{ \"status\" : \"error\", \"code\" : \"401\", \"message\" : \" " + message +" \" }"; |
|
239 |
} |
|
240 |
|
|
241 |
private String compose404Message(String message) { |
|
242 |
return "{ \"status\" : \"error\", \"code\" : \"404\", \"message\" : \" " + message +" \" }"; |
|
243 |
} |
|
244 |
|
|
245 |
private String compose500Message(String message, Exception exception) { |
|
246 |
return "{ \"status\" : \"fail\", \"code\" : \"500\", \"message\" : \" " + message + "\", " + |
|
247 |
"\"description\" : \""+ exception.getMessage() +"\" }"; |
|
248 |
} |
|
249 |
|
|
250 |
private String composeDataResponse(UserInfo user) { |
|
251 |
return "{ \"status\" : \"success\", \"code\": \"200\", " + "\"data\" : \"" + JWTGenerator.generateToken(user, "my-very-secret") + "\" }"; |
|
252 |
} |
|
253 |
|
|
254 |
private String composeDataResponse(MigrationUser user) { |
|
255 |
//return "{ \"status\" : \"success\", \"code\": \"200\", " + "\"data\" : " + new Gson().toJson(user) + " }"; |
|
256 |
return "{ \"status\" : \"success\", \"code\": \"200\", " + "\"data\" : \"" + JWTGenerator.generateToken(user, "my-very-secret") + "\" }"; |
|
257 |
} |
|
258 |
|
|
259 |
private String composeDataResponse(LDAPUser user) { |
|
260 |
return " { \"status\" : \"success\", \"code\": \"200\", " + "\"data\" : " + new Gson().toJson(user) + " }"; |
|
261 |
} |
|
262 |
|
|
263 |
// private String composeDataResponse(String username) { |
|
264 |
// return " { \"status\" : \"success\", \"code\": \"200\", " + "\"data\" : " + new Gson().toJson(username) + " }"; |
|
265 |
// } |
|
266 |
|
|
267 |
private String composeDataResponse(String fullname) { |
|
268 |
return " { \"status\" : \"success\", \"code\": \"200\", " + "\"data\" : " + new Gson().toJson(fullname) + " }"; |
|
269 |
} |
|
270 |
} |
modules/uoa-user-management/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/migration/Tester.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user.migration; |
|
2 |
|
|
3 |
import com.sun.org.apache.xpath.internal.SourceTree; |
|
4 |
import com.unboundid.ldap.sdk.*; |
|
5 |
import eu.dnetlib.openaire.user.ldap.Joomla15PasswordHash; |
|
6 |
import eu.dnetlib.openaire.user.ldap.MUserActionsLDAP; |
|
7 |
import eu.dnetlib.openaire.user.ldap.UserActionsLDAP; |
|
8 |
|
|
9 |
import java.sql.SQLException; |
|
10 |
import java.util.UUID; |
|
11 |
|
|
12 |
/** |
|
13 |
* Created by sofia on 25/4/2017. |
|
14 |
*/ |
|
15 |
public class Tester { |
|
16 |
|
|
17 |
public static void main(String[] args) throws LDAPException, SQLException { |
|
18 |
|
|
19 |
// ldapsearch -x -LLL -h beta.openaire.eu -b cn=admin,dc=openaire,dc=eu |
|
20 |
// ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1) |
|
21 |
|
|
22 |
// String ldapAddress = "beta.openaire.eu"; |
|
23 |
// String ldapUsername = "cn=admin,dc=openaire,dc=eu"; |
|
24 |
// String ldapPassword = ""; |
|
25 |
String ldapUsersDN = "ou=users,dc=openaire,dc=eu"; |
|
26 |
// int ldapPort = 389; |
|
27 |
// |
|
28 |
// LDAPConnection connection = new LDAPConnection(ldapAddress, ldapPort, ldapUsername, ldapPassword); |
|
29 |
|
|
30 |
LDAPConnection connection = new LDAPConnection("beta.openaire.eu", 389, "cn=admin,dc=openaire,dc=eu", ""); |
|
31 |
System.out.println("Hi"); |
|
32 |
String email = "sbaltzi@di.uoa.gr"; |
|
33 |
String password = ""; |
|
34 |
|
|
35 |
try { |
|
36 |
System.out.println("checking if user " + email + " entered a correct password when logging in"); |
|
37 |
|
|
38 |
Filter filter = Filter.createEqualityFilter("mail", email); |
|
39 |
|
|
40 |
SearchRequest searchRequest = new SearchRequest(ldapUsersDN, SearchScope.SUB, filter, "userPassword"); |
|
41 |
SearchResult searchResult = connection.search(searchRequest); |
|
42 |
|
|
43 |
for (SearchResultEntry entry : searchResult.getSearchEntries()) { |
|
44 |
if (Joomla15PasswordHash.check(password, entry.getAttributeValue("userPassword"))) |
|
45 |
System.out.println("true"); |
|
46 |
} |
|
47 |
|
|
48 |
System.out.println("false"); |
|
49 |
} |
|
50 |
finally { |
|
51 |
if (connection != null) |
|
52 |
connection.close(); |
|
53 |
} |
|
54 |
} |
|
55 |
} |
modules/uoa-user-management/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.ldap.Joomla15PasswordHash; |
|
5 |
import eu.dnetlib.openaire.user.ldap.MUserActionsLDAP; |
|
6 |
import eu.dnetlib.openaire.user.ldap.UserActionsLDAP; |
|
7 |
import eu.dnetlib.openaire.user.store.LDAPConnector; |
|
8 |
|
|
9 |
import java.sql.SQLException; |
|
10 |
import java.util.UUID; |
|
11 |
|
|
12 |
/** |
|
13 |
* Created by sofia on 31/10/2016. |
|
14 |
*/ |
|
15 |
public class Migration { |
|
16 |
|
|
17 |
public static void main(String[] args) throws LDAPException, SQLException { |
|
18 |
|
|
19 |
//MUserActionsLDAP mUserActionsLDAP = new MUserActionsLDAP(); |
|
20 |
// UserActionsLDAP UserActionsLDAP = new UserActionsLDAP(); |
|
21 |
// try { |
|
22 |
// UserActionsLDAP.addUser("Argiro", "argiro@gmail.com", "12345678", "Argiro", "Kokogianaki"); |
|
23 |
// } catch (Exception e) { |
|
24 |
// e.printStackTrace(); |
|
25 |
// } |
|
26 |
//boolean authenticated = mUserActionsLDAP.authenticateUser("sba@di.uoa.gr", "12345678"); |
|
27 |
//System.out.println(authenticated); |
|
28 |
//System.out.println(mUserActionsLDAP.getRole("sba@di.uoa.gr", "12345678")); |
|
29 |
|
|
30 |
|
|
31 |
Attribute cn = new Attribute("cn", "Argiro"); |
|
32 |
Attribute displayName = new Attribute("displayName", "Argiro" + " " + "Kokogianaki"); |
|
33 |
Attribute mail = new Attribute("mail", "argiro@gmail.com"); |
|
34 |
Attribute givenName = new Attribute("givenName", "Argiro"); |
|
35 |
Attribute joomlaBlockUser = new Attribute("JoomlaBlockUser", "1"); |
|
36 |
Attribute joomlaGroup = new Attribute("JoomlaGroup", "Registered"); |
|
37 |
Attribute objectClass = new Attribute("objectClass", "top", "inetOrgPerson", "JoomlaUser"); |
|
38 |
Attribute userPassword = new Attribute("userPassword", Joomla15PasswordHash.create("12345678")); |
|
39 |
Attribute sn = new Attribute("sn", "Kokogianaki"); |
|
40 |
Attribute uid = new Attribute("uid", "Argiro"); |
|
41 |
// Attribute joomlaUserParams = new Attribute("JoomlaUserParams", ""); |
|
42 |
String activationId = UUID.randomUUID().toString(); |
|
43 |
Attribute x500UniqueIdentifier = new Attribute("employeeNumber", activationId); |
|
44 |
LDAPConnection connection = null; |
|
45 |
try { |
|
46 |
DN dn = new DN("uid=" + "Argiro" + "," + "ou=users,dc=openaire,dc=eu"); |
|
47 |
System.out.println("cn: " + cn + " displayName: " + displayName + " mail: " + mail + " givenName: " + givenName + " joomlaBlockUser: " + joomlaBlockUser + " joomlaGroup: " + joomlaGroup + " objectClass: " + objectClass + " userPassword: " + userPassword + " sn: " + sn + " uid: " + uid + " x500UniqueIdentifier: " + x500UniqueIdentifier); |
|
48 |
Entry entry = new Entry(dn.toNormalizedString(), cn, displayName, mail, givenName, joomlaBlockUser, joomlaGroup, objectClass, userPassword, sn, uid/* |
|
49 |
* , |
|
50 |
* joomlaUserParams |
|
51 |
*/, x500UniqueIdentifier); |
|
52 |
connection = new LDAPConnection("esperos.di.uoa.gr", 389, "cn=admin,dc=openaire,dc=eu", "serenata"); |
|
53 |
connection.add(entry); |
|
54 |
|
|
55 |
} catch (Exception e) { |
|
56 |
throw e; |
|
57 |
} finally { |
|
58 |
if (connection != null) |
|
59 |
connection.close(); |
|
60 |
} |
|
61 |
} |
|
62 |
} |
modules/uoa-user-management/uoa-user-management/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/uoa-user-management/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 |
|
|
6 |
import javax.sql.DataSource; |
|
7 |
import java.sql.Connection; |
|
8 |
import java.sql.DriverManager; |
|
9 |
import java.sql.SQLException; |
|
10 |
|
|
11 |
/** |
|
12 |
* Created by sofia on 31/10/2016. |
|
13 |
*/ |
|
14 |
public class DataSourceConnector { |
|
15 |
|
|
16 |
private String username; |
|
17 |
private String password; |
|
18 |
private String dbUrl; |
|
19 |
private String driver; |
|
20 |
|
|
21 |
private static boolean driverLoad = false; |
|
22 |
private DataSource datasource; |
|
23 |
|
|
24 |
private static final Logger logger = Logger.getLogger(DataSourceConnector.class); |
|
25 |
|
|
26 |
public void init() { |
|
27 |
logger.info("Initializing data source"); |
|
28 |
|
|
29 |
try { |
|
30 |
Class.forName(driver); |
|
31 |
driverLoad = true; |
|
32 |
|
|
33 |
BasicDataSource bds = new BasicDataSource(); |
|
34 |
|
|
35 |
bds.setDriverClassName(driver); |
|
36 |
bds.setUrl(dbUrl); |
|
37 |
bds.setUsername(username); |
|
38 |
bds.setPassword(password); |
|
39 |
bds.setMaxIdle(10); |
|
40 |
bds.setMaxActive(100); |
|
41 |
bds.setMaxWait(10000); |
|
42 |
bds.setValidationQuery("select 1"); |
|
43 |
bds.setTestOnBorrow(true); |
|
44 |
bds.setTestWhileIdle(true); |
|
45 |
bds.setTimeBetweenEvictionRunsMillis(1200000); |
|
46 |
bds.setMinEvictableIdleTimeMillis(1800000); |
|
47 |
bds.setNumTestsPerEvictionRun(5); |
|
48 |
bds.setDefaultAutoCommit(true); |
|
49 |
|
|
50 |
this.datasource = bds; |
|
51 |
|
|
52 |
// Test Connection |
|
53 |
getConnection().close(); |
|
54 |
|
|
55 |
logger.info("Datasource " + datasource); |
|
56 |
logger.info(datasource.getConnection()); |
|
57 |
|
|
58 |
} catch (ClassNotFoundException | SQLException exc) { |
|
59 |
logger.error("Unable to connenct to the DB. ", exc); |
|
60 |
throw new RuntimeException(exc); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
public Connection getConnection() throws SQLException { |
|
65 |
logger.debug("dbUrl " + dbUrl); |
|
66 |
return DriverManager.getConnection(dbUrl, username, password); |
|
67 |
//return DriverManager.getConnection("jdbc:postgresql://localhost:5433/MigrationUser?user=postgres&password=mypassword"); |
|
68 |
} |
|
69 |
|
|
70 |
public String getUsername() { |
|
71 |
return username; |
|
72 |
} |
|
73 |
|
|
74 |
public void setUsername(String username) { |
|
75 |
this.username = username; |
|
76 |
} |
|
77 |
|
|
78 |
public String getPassword() { |
|
79 |
return password; |
|
80 |
} |
|
81 |
|
|
82 |
public void setPassword(String password) { |
|
83 |
this.password = password; |
|
84 |
} |
|
85 |
|
|
86 |
public String getDbUrl() { |
|
87 |
return dbUrl; |
|
88 |
} |
|
89 |
|
|
90 |
public void setDbUrl(String dbUrl) { |
|
91 |
this.dbUrl = dbUrl; |
|
92 |
} |
|
93 |
|
|
94 |
public String getDriver() { |
|
95 |
return driver; |
|
96 |
} |
|
97 |
|
|
98 |
public void setDriver(String driver) { |
|
99 |
this.driver = driver; |
|
100 |
} |
|
101 |
|
|
102 |
public DataSource getDatasource() { |
|
103 |
return datasource; |
|
104 |
} |
|
105 |
} |
modules/uoa-user-management/uoa-user-management/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/uoa-user-management/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 password; |
|
17 |
private int port; |
|
18 |
|
|
19 |
private static Logger logger = Logger.getLogger(LDAPConnector.class); |
|
20 |
|
|
21 |
|
|
22 |
public LDAPConnection getConnection() throws LDAPException { |
|
23 |
logger.debug("Getting ldap connection"); |
|
24 |
return new LDAPConnection(address, port, username, password); |
|
25 |
} |
|
26 |
|
|
27 |
public String getAddress() { |
|
28 |
return address; |
|
29 |
} |
|
30 |
|
|
31 |
public void setAddress(String address) { |
|
32 |
this.address = address; |
|
33 |
} |
|
34 |
|
|
35 |
public String getUsername() { |
|
36 |
return username; |
|
37 |
} |
|
38 |
|
|
39 |
public void setUsername(String username) { |
|
40 |
this.username = username; |
|
41 |
} |
|
42 |
|
|
43 |
public String getUsersDN() { |
|
44 |
return usersDN; |
|
45 |
} |
|
46 |
|
|
47 |
public void setUsersDN(String usersDN) { |
|
48 |
this.usersDN = usersDN; |
|
49 |
} |
|
50 |
|
|
51 |
public String getPassword() { |
|
52 |
return password; |
|
53 |
} |
|
54 |
|
|
55 |
public void setPassword(String password) { |
|
56 |
this.password = password; |
|
57 |
} |
|
58 |
|
|
59 |
public int getPort() { |
|
60 |
return port; |
|
61 |
} |
|
62 |
|
|
63 |
public void setPort(int port) { |
|
64 |
this.port = port; |
|
65 |
} |
|
66 |
} |
|
67 |
|
modules/uoa-user-management/uoa-user-management/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.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/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_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/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/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/User.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.user; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
import java.util.HashMap; |
|
8 |
|
|
9 |
/** |
|
10 |
* Created by sofia on 15/6/2016. |
|
11 |
*/ |
|
12 |
public class User implements Serializable{ |
|
13 |
|
|
14 |
private String id; |
|
15 |
private String username; |
|
16 |
private String password; |
|
17 |
private String email; |
|
18 |
private String name; |
|
19 |
private String surname; |
|
20 |
private Map<String, List<String>> roles; |
|
21 |
|
|
22 |
//private int orcid; |
|
23 |
//private String affiliation; |
|
24 |
//private String profil_provenance; |
|
25 |
|
|
26 |
//Map<String, List<String>> roles = new HashMap<String, List<String>>(); |
|
27 |
|
|
28 |
|
|
29 |
public User(){ |
|
30 |
|
|
31 |
} |
|
32 |
|
|
33 |
public User(String username) { |
|
34 |
this.username = username; |
|
35 |
} |
|
36 |
|
|
37 |
public User(String id, String username, String password, String email, String name, String surname){ |
|
38 |
|
|
39 |
this.id = id; |
|
40 |
this.username = username; |
|
41 |
this.password = password; |
|
42 |
this.email = email; |
|
43 |
this.name = name; |
|
44 |
this.surname = surname; |
|
45 |
} |
|
46 |
|
|
47 |
public String getId(){ |
|
48 |
return id; |
|
49 |
} |
|
50 |
|
|
51 |
public void setId(String id){ |
|
52 |
this.id = id; |
|
53 |
} |
|
54 |
|
|
55 |
public String getUsername() { |
|
56 |
return username; |
|
57 |
} |
|
58 |
|
|
59 |
public void setUsername(String username) { |
|
60 |
this.username = username; |
|
61 |
} |
|
62 |
|
|
63 |
public String getPassword() { |
|
64 |
return password; |
|
65 |
} |
|
66 |
|
|
67 |
public void setPassword(String password) { |
|
68 |
this.password = password; |
|
69 |
} |
|
70 |
|
|
71 |
public String getEmail() { |
|
72 |
return email; |
|
73 |
} |
|
74 |
|
|
75 |
public void setEmail(String email) { |
|
76 |
this.email = email; |
|
77 |
} |
|
78 |
|
|
79 |
public String getName() { |
|
80 |
return name; |
|
81 |
} |
|
82 |
|
|
83 |
public void setName(String name) { |
|
84 |
this.name = name; |
|
85 |
} |
|
86 |
|
|
87 |
public String getSurname() { |
|
88 |
return surname; |
|
89 |
} |
|
90 |
|
|
91 |
public void setSurname(String surname) { |
|
92 |
this.surname = surname; |
|
93 |
} |
|
94 |
|
|
95 |
public void setRoles(Map<String, List<String>> map) |
|
96 |
{ |
|
97 |
this.roles = map; |
|
98 |
} |
|
99 |
|
|
100 |
public Map<String, List<String>> getValue() |
|
101 |
{ |
Also available in: Unified diff
Delete wrong copy from dnet40