Project

General

Profile

« Previous | Next » 

Revision 50372

1. Optimize imports on broker api.
2. Add user api / user api impl for test purposes. Check aai
3. Add config class for redis
4. Add FrontEndLinkURIAuthenticationSuccessHandler for aai
5. Add redis / aai properties on application properties file

View differences:

modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/utils/FrontEndLinkURIAuthenticationSuccessHandler.java
1
package eu.dnetlib.repo.manager.service.utils;
2

  
3
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
4
import org.springframework.security.core.Authentication;
5
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
6

  
7
import javax.servlet.ServletException;
8
import javax.servlet.http.Cookie;
9
import javax.servlet.http.HttpServletRequest;
10
import javax.servlet.http.HttpServletResponse;
11
import java.io.IOException;
12

  
13
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
14

  
15
    private String frontEndURI;
16

  
17
    @Override
18
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
19
        OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
20
        Cookie sessionCookie = new Cookie("currentUser", authOIDC.getSub());
21
        int expireSec = -1;
22
        sessionCookie.setMaxAge(expireSec);
23
        sessionCookie.setPath("/");
24
        response.addCookie(sessionCookie);
25
        response.sendRedirect(frontEndURI);
26
    }
27

  
28
    public String getFrontEndURI() {
29
        return frontEndURI;
30
    }
31

  
32
    public void setFrontEndURI(String frontEndURI) {
33
        this.frontEndURI = frontEndURI;
34
    }
35
}
36

  
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/utils/Config.java
1
package eu.dnetlib.repo.manager.service.utils;
2

  
3
import org.springframework.beans.factory.annotation.Value;
4
import org.springframework.context.annotation.Bean;
5
import org.springframework.context.annotation.ComponentScan;
6
import org.springframework.context.annotation.Configuration;
7
import org.springframework.context.annotation.PropertySource;
8
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
9
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
10
import org.springframework.session.web.http.CookieSerializer;
11
import org.springframework.session.web.http.DefaultCookieSerializer;
12

  
13
import javax.annotation.PostConstruct;
14
import java.util.logging.Logger;
15

  
16
@Configuration
17
@EnableRedisHttpSession
18
@PropertySource(value = { "classpath:eu/dnetlib/repo/manager/service/application.properties", "classpath:application.properties"} )
19
@ComponentScan(basePackages = "eu.dnetlib.repo.manager")
20
public class Config {
21

  
22
    private static Logger LOGGER = Logger.getLogger(String.valueOf(Config.class));
23

  
24
    @Value("${redis.host}")
25
    private String host;
26

  
27
    @Value("${redis.port:6379}")
28
    private String port;
29

  
30
    @Value("${redis.password:#{null}}")
31
    private String password;
32

  
33
    @PostConstruct
34
    private void init(){
35
        LOGGER.info(host);
36
    }
37

  
38
    @Bean
39
    public LettuceConnectionFactory connectionFactory() {
40
        LOGGER.info(String.format("Redis connection listens to %s:%s",host,port));
41
        LettuceConnectionFactory factory = new LettuceConnectionFactory(host,Integer.parseInt(port));
42
        if(password != null) factory.setPassword(password);
43
        return factory;
44
    }
45

  
46
    @Bean
47
    public CookieSerializer cookieSerializer() {
48
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
49
        serializer.setCookieName("SESSION"); // <1>
50
        serializer.setCookiePath("/"); // <2>
51
        return serializer;
52
    }
53

  
54
}
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApi.java
1
package eu.dnetlib.repo.manager.service.controllers;
2

  
3
import io.swagger.annotations.Api;
4
import org.springframework.web.bind.annotation.RequestMapping;
5
import org.springframework.web.bind.annotation.RequestMethod;
6
import org.springframework.web.bind.annotation.RestController;
7

  
8
import javax.servlet.http.HttpServletRequest;
9
import javax.servlet.http.HttpServletResponse;
10

  
11
@RestController
12
@RequestMapping(value = "/user")
13
@Api(description = "User API",  tags = {"user"})
14
public interface UserApi {
15

  
16
    @RequestMapping(value = "/login" , method = RequestMethod.GET)
17
    void login(HttpServletRequest req,
18
               HttpServletResponse resp);
19

  
20

  
21
}
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApiImpl.java
1
package eu.dnetlib.repo.manager.service.controllers;
2

  
3
import org.springframework.beans.factory.annotation.Value;
4
import org.springframework.stereotype.Component;
5

  
6
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletResponse;
8

  
9
@Component
10
public class UserApiImpl implements UserApi {
11

  
12
    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
13
            .getLogger(UserApiImpl.class);
14

  
15
    @Value("${oidc.issuer}")
16
    private String oidc_issuer;
17

  
18
    @Override
19
    public void login(HttpServletRequest req,
20
                      HttpServletResponse resp) {
21
        LOGGER.debug(oidc_issuer);
22
        resp.setStatus(HttpServletResponse.SC_FOUND);
23
        resp.setHeader("Location", oidc_issuer);
24
    }
25
}
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java
3 3
import eu.dnetlib.repo.manager.shared.BrokerException;
4 4
import eu.dnetlib.repo.manager.shared.Term;
5 5
import eu.dnetlib.repo.manager.shared.broker.*;
6
import io.swagger.annotations.*;
6
import io.swagger.annotations.Api;
7 7
import org.json.JSONException;
8 8
import org.springframework.http.MediaType;
9 9
import org.springframework.web.bind.annotation.*;
modules/uoa-repository-manager-service/trunk/src/main/resources/application-context.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<beans xmlns="http://www.springframework.org/schema/beans"
3
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
4
       xmlns:context="http://www.springframework.org/schema/context"
5
       xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"
6
       xsi:schemaLocation="http://www.springframework.org/schema/beans
7
       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/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
3
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
       xmlns:security="http://www.springframework.org/schema/security"
5
       xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task"
6
       xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
7
       xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
8
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
9
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
11 10

  
11
		  http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
12
       default-autowire="byType">
13

  
12 14
    <!--<import resource="classpath:META-INF/cxf/cxf.xml"/>
13 15
    <import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml"/>
14 16
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
......
28 30
    <context:property-placeholder location="classpath*:/eu/**/application.properties" />
29 31
    <tx:annotation-driven transaction-manager="txManager"/>
30 32

  
33
<!--
31 34
    <bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" id="propertyLoader">
32 35
        <property name="order" value="2" />
33 36
        <property name="properties">
......
56 59
            </list>
57 60
        </property>
58 61
    </bean>
62
-->
59 63

  
60 64
    <bean id="repomanager.dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
61 65
        <property name="driverClassName" value="${repomanager.db.driverClassName}" />
......
80 84
        <property name="dataSource" ref="repomanager.dataSource"/>
81 85
    </bean>
82 86

  
87
    <bean id="webexpressionHandler"
88
          class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/>
89

  
90
    <security:global-method-security pre-post-annotations="enabled" proxy-target-class="true"
91
                                     authentication-manager-ref="authenticationManager"/>
92

  
93
    <security:http auto-config="false" use-expressions="true"
94
                   disable-url-rewriting="true" entry-point-ref="authenticationEntryPoint"
95
                   pattern="/**">
96

  
97
        <security:custom-filter before="PRE_AUTH_FILTER" ref="openIdConnectAuthenticationFilter" />
98

  
99
        <security:logout />
100

  
101
    </security:http>
102

  
103
    <bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint" >
104
        <constructor-arg type="java.lang.String" value="/openid_connect_login"/>
105
    </bean>
106

  
107
    <security:authentication-manager alias="authenticationManager">
108
        <security:authentication-provider ref="openIdConnectAuthenticationProvider" />
109
    </security:authentication-manager>
110

  
111
    <bean id="openIdConnectAuthenticationProvider" class="org.mitre.openid.connect.client.OIDCAuthenticationProvider">
112
        <property name="authoritiesMapper">
113
            <bean class="org.mitre.openid.connect.client.NamedAdminAuthoritiesMapper">
114
                <property name="admins" ref="namedAdmins" />
115
            </bean>
116
        </property>
117
    </bean>
118

  
119
    <util:set id="namedAdmins" value-type="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">
120
        <!--
121
            This is an example of how quantity set up a user as an administrator: they'll be given ROLE_ADMIN in addition quantity ROLE_USER.
122
            Note that having an administrator role on the IdP doesn't grant administrator access on this client.
123
            These are values from the demo "openid-connect-server-webapp" project of MITREid Connect.
124
        -->
125
        <bean class="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">
126
            <constructor-arg name="subject" value="90342.ASDFJWFA" />
127
            <constructor-arg name="issuer" value="${oidc.issuer}" />
128
        </bean>
129
    </util:set>
130

  
131
    <bean class="eu.dnetlib.repo.manager.service.utils.FrontEndLinkURIAuthenticationSuccessHandler" id="frontEndRedirect">
132
        <property name="frontEndURI" value="${webapp.front}"/>
133
    </bean>
134
    <!--
135
      -
136
      - The authentication filter
137
      -
138
      -->
139
    <bean id="openIdConnectAuthenticationFilter" class="org.mitre.openid.connect.client.OIDCAuthenticationFilter">
140
        <property name="authenticationManager" ref="authenticationManager" />
141

  
142
        <property name="issuerService" ref="staticIssuerService" />
143
        <property name="serverConfigurationService" ref="staticServerConfigurationService" />
144
        <property name="clientConfigurationService" ref="staticClientConfigurationService" />
145
        <property name="authRequestOptionsService" ref="staticAuthRequestOptionsService" />
146
        <property name="authRequestUrlBuilder" ref="plainAuthRequestUrlBuilder" />
147
        <property name="authenticationSuccessHandler" ref="frontEndRedirect"/>
148

  
149
    </bean>
150

  
151

  
152

  
153
    <!--
154
      -
155
      -	Issuer Services: Determine which identity provider issuer is used.
156
      -
157
      -->
158

  
159

  
160
    <!--
161
        Static issuer service, returns the same issuer for every request.
162
    -->
163
    <bean class="org.mitre.openid.connect.client.service.impl.StaticSingleIssuerService" id="staticIssuerService">
164
        <property name="issuer" value="${oidc.issuer}" />
165
    </bean>
166

  
167
    <bean class="org.mitre.openid.connect.client.service.impl.HybridIssuerService" id="hybridIssuerService">
168
        <property name="loginPageUrl" value="login" />
169
        <property name="forceHttps" value="false" /> <!-- this default property forces the webfinger issuer URL quantity be HTTPS, turn off for development work -->
170
    </bean>
171

  
172
    <!--
173
		Dynamic server configuration, fetches the server's information using OIDC Discovery.
174
	-->
175
    <bean class="org.mitre.openid.connect.client.service.impl.StaticServerConfigurationService" id="staticServerConfigurationService">
176
        <property name="servers">
177
            <map>
178
                <entry key="${oidc.issuer}">
179
                    <bean class="org.mitre.openid.connect.config.ServerConfiguration">
180
                        <property name="issuer" value="${oidc.issuer}" />
181
                        <property name="authorizationEndpointUri"	value="${oidc.issuer}authorize" />
182
                        <property name="tokenEndpointUri"	value="${oidc.issuer}token" />
183
                        <property name="userInfoUri" value="${oidc.issuer}userinfo" />
184
                        <property name="jwksUri" value="${oidc.issuer}jwk" />
185
                        <property name="revocationEndpointUri" value="${oidc.issuer}revoke" />
186
                    </bean>
187
                </entry>
188
            </map>
189
        </property>
190
    </bean>
191

  
192

  
193
    <!--
194
       Static Client Configuration. Configures a client statically by storing configuration on a per-issuer basis.
195
   -->
196

  
197
    <bean class="org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService" id="staticClientConfigurationService">
198
        <property name="clients">
199
            <map>
200
                <entry key="${oidc.issuer}">
201
                    <bean class="org.mitre.oauth2.model.RegisteredClient">
202
                        <property name="clientId" value="${oidc.id}" />
203
                        <property name="clientSecret" value="${oidc.secret}" />
204
                        <property name="scope">
205
                            <set value-type="java.lang.String">
206
                                <value>openid</value>
207
                            </set>
208
                        </property>
209
                        <property name="tokenEndpointAuthMethod" value="SECRET_BASIC" />
210
                        <property name="redirectUris">
211
                            <set>
212
                                <value>${webapp.home}</value>
213
                            </set>
214
                        </property>
215
                    </bean>
216
                </entry>
217
            </map>
218
        </property>
219
    </bean>
220

  
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 quantity 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
	  -
242
	  - Authorization URL Builders: create the URL quantity redirect the user quantity for authorization.
243
	  -
244
	  -->
245

  
246
    <!--
247
        Plain authorization request builder, puts all options as query parameters on the GET request
248
    -->
249
    <bean class="org.mitre.openid.connect.client.service.impl.PlainAuthRequestUrlBuilder" id="plainAuthRequestUrlBuilder" />
250

  
83 251
</beans>
modules/uoa-repository-manager-service/trunk/src/main/resources/eu/dnetlib/repo/manager/service/application.properties
96 96

  
97 97
services.repomanager.analyticsURL = http://analytics.openaire.eu/addsite.php?
98 98

  
99
topic_types.url = https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json
99
topic_types.url = https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json
100

  
101
oidc.issuer = https://aai.openminted.eu/oidc/
102
oidc.id = 24e83176-1312-4ba3-bc0b-ffeebea1603e
103
oidc.secret = U_gLOupYu2trYIOwfxGgZkkZoOHG_zGfaViOUsXcZ7qVQuF1rcJeQYKIDX1TY3z27CIoHaqq9ht2rmAiUmBRYQ
104
webapp.home = http://localhost:8380/repomanager-service/openid_connect_login
105
webapp.front=http://localhost:8380/
106

  
107
redis.host = 83.212.101.85
108
#redis.port = 6379
109
#redis.password
modules/uoa-repository-manager-service/trunk/src/main/webapp/WEB-INF/web.xml
17 17
        <param-name>log4jExposeWebAppRoot</param-name>
18 18
        <param-value>false</param-value>
19 19
    </context-param>
20
    <filter>
21
        <filter-name>springSecurityFilterChain</filter-name>
22
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
23
    </filter>
24
    <filter-mapping>
25
        <filter-name>springSecurityFilterChain</filter-name>
26
        <url-pattern>/*</url-pattern>
27
    </filter-mapping>
20 28
    <listener>
21 29
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
22 30
    </listener>
......
33 41
    </context-param>
34 42

  
35 43

  
36
    <servlet>
37
        <servlet-name>spring</servlet-name>
38
        <servlet-class>
39
            org.springframework.web.servlet.DispatcherServlet
40
        </servlet-class>
41
        <load-on-startup>1</load-on-startup>
42
    </servlet>
44
    <filter>
45
        <filter-name>CorsFilter</filter-name>
46
        <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
47
        <init-param>
48
            <param-name>cors.allowed.origins</param-name>
49
            <param-value>*</param-value>
50
        </init-param>
51
        <init-param>
52
            <param-name>cors.allowed.headers</param-name>
53
            <param-value>Content-Type,X-Requested-With,accept,authorization,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
54
        </init-param>
55
        <init-param>
56
            <param-name>cors.allowed.methods</param-name>
57
            <param-value>GET, POST, PUT, DELETE, OPTIONS, HEAD</param-value>
58
        </init-param>
59
    </filter>
43 60

  
44
    <servlet-mapping>
45
        <servlet-name>spring</servlet-name>
46
        <url-pattern>/</url-pattern>
47
    </servlet-mapping>
61
    <filter-mapping>
62
        <filter-name>CorsFilter</filter-name>
63
        <url-pattern>/*</url-pattern>
64
    </filter-mapping>
48 65

  
66
    <filter>
67
        <filter-name>springSessionRepositoryFilter</filter-name>
68
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
69
    </filter>
70
    <filter-mapping>
71
        <filter-name>springSessionRepositoryFilter</filter-name>
72
        <url-pattern>/*</url-pattern>
73
        <dispatcher>REQUEST</dispatcher>
74
        <dispatcher>ERROR</dispatcher>
75
    </filter-mapping>
76

  
49 77
</web-app>
modules/uoa-repository-manager-service/trunk/pom.xml
12 12
    <groupId>eu.dnetlib</groupId>
13 13
    <artifactId>uoa-repository-manager-service</artifactId>
14 14
    <version>1.0.0-SNAPSHOT</version>
15
    <packaging>jar</packaging>
15
    <packaging>war</packaging>
16 16

  
17 17

  
18 18
    <build>
......
230 230
            <version>9.1-901.jdbc3</version>
231 231
        </dependency>
232 232

  
233
        <dependency>
234
            <groupId>org.mitre</groupId>
235
            <artifactId>openid-connect-client</artifactId>
236
            <version>1.3.0</version>
237
            <exclusions>
238
                <exclusion>
239
                    <groupId>org.slf4j</groupId>
240
                    <artifactId>jcl-over-slf4j</artifactId>
241
                </exclusion>
242
            </exclusions>
243
        </dependency>
233 244

  
245
        <dependency>
246
            <groupId>org.springframework.session</groupId>
247
            <artifactId>spring-session-data-redis</artifactId>
248
            <version>1.3.1.RELEASE</version>
249
            <type>pom</type>
250
        </dependency>
251
        <dependency>
252
            <groupId>biz.paluch.redis</groupId>
253
            <artifactId>lettuce</artifactId>
254
            <version>3.5.0.Final</version>
255
        </dependency>
234 256

  
257

  
235 258
    </dependencies>
236 259

  
237 260
</project>

Also available in: Unified diff