blob: 9eac9d40810d3a35fd6968cdd14326d5489e480d [file] [log] [blame]
margarethad3c0fc92017-10-25 15:03:32 +02001package de.ids_mannheim.korap.web.controller;
Michael Hanlfb839b92015-09-19 21:32:34 +02002
margaretha894a7d72017-11-08 19:24:20 +01003import java.util.HashMap;
margaretha894a7d72017-11-08 19:24:20 +01004import java.util.List;
5import java.util.Locale;
6import java.util.Map;
7
8import javax.ws.rs.Consumes;
9import javax.ws.rs.GET;
10import javax.ws.rs.HeaderParam;
11import javax.ws.rs.POST;
12import javax.ws.rs.Path;
13import javax.ws.rs.Produces;
14import javax.ws.rs.QueryParam;
15import javax.ws.rs.core.Context;
16import javax.ws.rs.core.HttpHeaders;
17import javax.ws.rs.core.MediaType;
margaretha894a7d72017-11-08 19:24:20 +010018import javax.ws.rs.core.Response;
19import javax.ws.rs.core.SecurityContext;
20
margaretha49cb6882018-07-04 04:19:54 +020021import org.apache.logging.log4j.LogManager;
22import org.apache.logging.log4j.Logger;
margarethabc3d3f72023-02-15 15:34:12 +010023import org.glassfish.jersey.server.ContainerRequest;
margaretha894a7d72017-11-08 19:24:20 +010024import org.springframework.beans.factory.annotation.Autowired;
25import org.springframework.stereotype.Controller;
26
margaretha34954472018-10-24 20:05:17 +020027import de.ids_mannheim.korap.authentication.AuthenticationManager;
margaretha56e8e552017-12-05 16:31:21 +010028import de.ids_mannheim.korap.authentication.http.AuthorizationData;
29import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
Michael Hanl00b64e02016-05-24 20:24:27 +020030import de.ids_mannheim.korap.config.Attributes;
Michael Hanldaf86602016-05-12 14:31:52 +020031import de.ids_mannheim.korap.config.BeansFactory;
margaretha0e8f4e72018-04-05 14:11:52 +020032import de.ids_mannheim.korap.constant.AuthenticationMethod;
33import de.ids_mannheim.korap.constant.AuthenticationScheme;
34import de.ids_mannheim.korap.constant.TokenType;
Michael Hanlfb839b92015-09-19 21:32:34 +020035import de.ids_mannheim.korap.exceptions.KustvaktException;
36import de.ids_mannheim.korap.exceptions.StatusCodes;
margaretha0e8f4e72018-04-05 14:11:52 +020037import de.ids_mannheim.korap.security.context.TokenContext;
margaretha894a7d72017-11-08 19:24:20 +010038import de.ids_mannheim.korap.user.User;
Michael Hanlfb839b92015-09-19 21:32:34 +020039import de.ids_mannheim.korap.utils.JsonUtils;
Michael Hanldaf86602016-05-12 14:31:52 +020040import de.ids_mannheim.korap.utils.ServiceInfo;
margarethada3c7852018-06-14 20:35:11 +020041import de.ids_mannheim.korap.web.KustvaktResponseHandler;
margaretha398f4722019-01-09 19:07:20 +010042import de.ids_mannheim.korap.web.filter.APIVersionFilter;
margarethafde771a2017-11-14 15:02:10 +010043import de.ids_mannheim.korap.web.filter.AuthenticationFilter;
margaretha894a7d72017-11-08 19:24:20 +010044import de.ids_mannheim.korap.web.filter.BlockingFilter;
45import de.ids_mannheim.korap.web.filter.DemoUserFilter;
46import de.ids_mannheim.korap.web.filter.PiwikFilter;
margarethabc3d3f72023-02-15 15:34:12 +010047import de.ids_mannheim.korap.web.utils.ResourceFilters;
Bodmo3d6bd352017-04-25 11:31:39 +020048
margaretha139d0f72017-11-14 18:56:22 +010049// import com.sun.xml.internal.messaging.saaj.util.Base64;
Michael Hanlfb839b92015-09-19 21:32:34 +020050
51/**
52 * @author hanl
53 * @date 24/01/2014
margarethaee0cbfe2018-08-28 17:47:14 +020054 *
55 * @author margaretha
margaretha47a72a82019-07-03 16:00:54 +020056 * @last-update 01/07/2019
margarethaee0cbfe2018-08-28 17:47:14 +020057 *
58 * - added user authentication time in token context
59 * - added api version filter
margaretha47a72a82019-07-03 16:00:54 +020060 * - changed the response media-type
Michael Hanlfb839b92015-09-19 21:32:34 +020061 */
margaretha894a7d72017-11-08 19:24:20 +010062@Controller
margarethaee0cbfe2018-08-28 17:47:14 +020063@Path("/{version}/auth")
64@ResourceFilters({APIVersionFilter.class, PiwikFilter.class })
margaretha47a72a82019-07-03 16:00:54 +020065@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
margarethad3c0fc92017-10-25 15:03:32 +020066public class AuthenticationController {
Michael Hanlfb839b92015-09-19 21:32:34 +020067
margaretha894a7d72017-11-08 19:24:20 +010068 @Autowired
margarethada3c7852018-06-14 20:35:11 +020069 private KustvaktResponseHandler kustvaktResponseHandler;
margaretha4b5c1412017-11-15 20:55:04 +010070
71 @Autowired
72 private HttpAuthorizationHandler authorizationHandler;
margaretha139d0f72017-11-14 18:56:22 +010073
margarethabc3d3f72023-02-15 15:34:12 +010074 private static Boolean DEBUG_LOG = true;
margarethaf18298b2017-09-14 22:14:32 +020075
Michael Hanlfb839b92015-09-19 21:32:34 +020076 //todo: bootstrap function to transmit certain default configuration settings and examples (example user queries,
77 // default usersettings, etc.)
margaretha139d0f72017-11-14 18:56:22 +010078 private static Logger jlog =
margaretha49cb6882018-07-04 04:19:54 +020079 LogManager.getLogger(AuthenticationController.class);
Michael Hanlfb839b92015-09-19 21:32:34 +020080
margaretha894a7d72017-11-08 19:24:20 +010081 @Autowired
margaretha34954472018-10-24 20:05:17 +020082 private AuthenticationManager controller;
Michael Hanl8abaf9e2016-05-23 16:46:35 +020083
Michael Hanlfb839b92015-09-19 21:32:34 +020084 // private SendMail mail;
85
Michael Hanlfb839b92015-09-19 21:32:34 +020086 /**
Michael Hanl8abaf9e2016-05-23 16:46:35 +020087 * represents json string with data. All GUI clients can access
88 * this method to get certain default values
Michael Hanlfb839b92015-09-19 21:32:34 +020089 * --> security checks?
Michael Hanl8abaf9e2016-05-23 16:46:35 +020090 *
Michael Hanlfb839b92015-09-19 21:32:34 +020091 * @return String
92 */
Michael Hanl25aac542016-02-01 18:16:44 +010093 @Deprecated
Michael Hanlfb839b92015-09-19 21:32:34 +020094 @GET
95 @Path("bootstrap")
96 @Produces(MediaType.APPLICATION_JSON)
Michael Hanl8abaf9e2016-05-23 16:46:35 +020097 public Response bootstrap () {
Michael Hanlfb839b92015-09-19 21:32:34 +020098 Map m = new HashMap();
Michael Hanl8abaf9e2016-05-23 16:46:35 +020099 // m.put("settings", new UserSettings().toObjectMap());
Michael Hanldaf86602016-05-12 14:31:52 +0200100 m.put("ql", BeansFactory.getKustvaktContext().getConfiguration()
Michael Hanlfb839b92015-09-19 21:32:34 +0200101 .getQueryLanguages());
102 m.put("SortTypes", null); // types of sorting that are supported!
Michael Hanldaf86602016-05-12 14:31:52 +0200103 m.put("version", ServiceInfo.getInfo().getVersion());
margarethad4796662017-11-09 16:11:40 +0100104 try {
105 return Response.ok(JsonUtils.toJSON(m)).build();
106 }
107 catch (KustvaktException e) {
margarethada3c7852018-06-14 20:35:11 +0200108 throw kustvaktResponseHandler.throwit(e);
margarethad4796662017-11-09 16:11:40 +0100109 }
Michael Hanlfb839b92015-09-19 21:32:34 +0200110 }
111
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200112
Michael Hanl19390652016-01-16 11:01:24 +0100113 // fixme: moved to user
Michael Hanlfb839b92015-09-19 21:32:34 +0200114 @GET
115 @Path("status")
margarethafde771a2017-11-14 15:02:10 +0100116 @ResourceFilters({ AuthenticationFilter.class, DemoUserFilter.class,
margarethaf18298b2017-09-14 22:14:32 +0200117 BlockingFilter.class })
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200118 public Response getStatus (@Context SecurityContext context,
Michael Hanlfb839b92015-09-19 21:32:34 +0200119 @HeaderParam(ContainerRequest.USER_AGENT) String agent,
120 @HeaderParam(ContainerRequest.HOST) String host,
121 @Context Locale locale) {
122 TokenContext ctx = (TokenContext) context.getUserPrincipal();
margarethad4796662017-11-09 16:11:40 +0100123 try {
124 return Response.ok(ctx.toJson()).build();
125 }
126 catch (KustvaktException e) {
margarethada3c7852018-06-14 20:35:11 +0200127 throw kustvaktResponseHandler.throwit(e);
margarethad4796662017-11-09 16:11:40 +0100128 }
Michael Hanlfb839b92015-09-19 21:32:34 +0200129 }
margaretha2afb97d2017-12-07 19:18:44 +0100130
131 // EM: testing using spring security authentication manager
margarethaa2ce63d2018-06-28 10:11:43 +0200132// @Deprecated
133// @GET
134// @Path("ldap/token")
135// public Response requestToken (@Context HttpHeaders headers,
136// @Context Locale locale,
137// @HeaderParam(ContainerRequest.USER_AGENT) String agent,
138// @HeaderParam(ContainerRequest.HOST) String host,
139// @HeaderParam("referer-url") String referer,
140// @QueryParam("scope") String scopes,
141// // @Context WebServiceContext wsContext, // FB
142// @Context SecurityContext securityContext) {
143//
144// Map<String, Object> attr = new HashMap<>();
145// if (scopes != null && !scopes.isEmpty())
146// attr.put(Attributes.SCOPES, scopes);
147// attr.put(Attributes.HOST, host);
148// attr.put(Attributes.USER_AGENT, agent);
149//
150// User user = new KorAPUser();
151// user.setUsername(securityContext.getUserPrincipal().getName());
152// controller.setAccessAndLocation(user, headers);
153// if (DEBUG_LOG == true) System.out.printf(
154// "Debug: /token/: location=%s, access='%s'.\n",
155// user.locationtoString(), user.accesstoString());
156// attr.put(Attributes.LOCATION, user.getLocation());
157// attr.put(Attributes.CORPUS_ACCESS, user.getCorpusAccess());
158//
159// try {
160// TokenContext context = controller.createTokenContext(user, attr,
161// TokenType.API);
162// return Response.ok(context.toJson()).build();
163// }
164// catch (KustvaktException e) {
165// throw kustvaktResponseHandler.throwit(e);
166// }
167// }
Michael Hanlfb839b92015-09-19 21:32:34 +0200168
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200169
margarethabc3d3f72023-02-15 15:34:12 +0100170 @Deprecated
Michael Hanlfb839b92015-09-19 21:32:34 +0200171 @GET
172 @Path("apiToken")
Michael Hanl9be4e422016-07-21 14:13:27 +0200173 //@ResourceFilters({HeaderFilter.class})
margarethaf18298b2017-09-14 22:14:32 +0200174 public Response requestAPIToken (@Context HttpHeaders headers,
Michael Hanlfb839b92015-09-19 21:32:34 +0200175 @Context Locale locale,
176 @HeaderParam(ContainerRequest.USER_AGENT) String agent,
177 @HeaderParam(ContainerRequest.HOST) String host,
178 @HeaderParam("referer-url") String referer,
Bodmo3d6bd352017-04-25 11:31:39 +0200179 @QueryParam("scope") String scopes,
margarethaf18298b2017-09-14 22:14:32 +0200180 // @Context WebServiceContext wsContext, // FB
Bodmo3d6bd352017-04-25 11:31:39 +0200181 @Context SecurityContext secCtx) {
margaretha4b5c1412017-11-15 20:55:04 +0100182
margarethaf18298b2017-09-14 22:14:32 +0200183 if (DEBUG_LOG == true) {
margarethabc3d3f72023-02-15 15:34:12 +0100184 String warning = "Access to API token (JWT) web service";
margarethaa2ce63d2018-06-28 10:11:43 +0200185
margarethabc3d3f72023-02-15 15:34:12 +0100186 List<String> auth =
187 headers.getRequestHeader(ContainerRequest.AUTHORIZATION);
188 if (auth != null && !auth.isEmpty()) {
189 try {
190 AuthorizationData authorizationData = authorizationHandler
191 .parseAuthorizationHeaderValue(auth.get(0));
192 if (authorizationData.getAuthenticationScheme()
193 .equals(AuthenticationScheme.BASIC)) {
194 authorizationData = authorizationHandler
195 .parseBasicToken(authorizationData);
196 jlog.warn(warning + " with username:"+authorizationData.getUsername());
197 }
198 }
199 catch (KustvaktException e) {}
200 }
201 else {
202 jlog.warn(warning);
203 }
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200204 }
margarethabc3d3f72023-02-15 15:34:12 +0100205 throw kustvaktResponseHandler.throwit(new KustvaktException(
206 StatusCodes.DEPRECATED,
207 "API token is no longer supported. Please use OAuth2 procedure instead."));
Michael Hanlfb839b92015-09-19 21:32:34 +0200208 }
209
margarethabc3d3f72023-02-15 15:34:12 +0100210// List<String> auth =
211// headers.getRequestHeader(ContainerRequest.AUTHORIZATION);
212// if (auth == null || auth.isEmpty()) {
213// throw kustvaktResponseHandler
214// .throwit(new KustvaktException(StatusCodes.MISSING_PARAMETER,
215// "Authorization header is missing.",
216// "Authorization header"));
217// }
218//
219// AuthorizationData authorizationData;
220// try {
221// authorizationData = authorizationHandler.
222// parseAuthorizationHeaderValue(auth.get(0));
223// if (authorizationData.getAuthenticationScheme().equals(AuthenticationScheme.BASIC)){
224// authorizationData = authorizationHandler.parseBasicToken(authorizationData);
225// }
226// else {
227// // EM: throw exception that auth scheme is not supported?
228// }
229//
230// }
231// catch (KustvaktException e) {
232// throw kustvaktResponseHandler.throwit(e);
233// }
234//
235// if (DEBUG_LOG == true) {
236// System.out.printf("Debug: AuthService.requestAPIToken...:\n");
237// System.out.printf("Debug: auth.size=%d\n", auth.size());
238// System.out.printf("auth.get(0)='%s'\n", auth.get(0));
239// /* hide password etc. - FB
240// if( auth.size() > 0 )
241// {
242// Iterator it = auth.iterator();
243// while( it.hasNext() )
244// System.out.printf(" header '%s'\n", it.next());
245// }
246// if( values.length > 0 )
247// {
248// for(int i=0; i< values.length; i++)
249// {
250// System.out.printf(" values[%d]='%s'\n", i, values[i]);
251// }
252// }
253// */
254// MultivaluedMap<String, String> headerMap =
255// headers.getRequestHeaders();
256// if (headerMap != null && headerMap.size() > 0) {
257// Iterator<String> it = headerMap.keySet().iterator();
258// while (it.hasNext()) {
259// String key = (String) it.next();
260// List<String> vals = headerMap.get(key);
261//// System.out.printf("Debug: requestAPIToken: '%s' = '%s'\n",
262//// key, vals);
263// }
264//
265// }
266//// System.out.printf("Debug: requestAPIToken: isSecure = %s.\n",
267//// secCtx.isSecure() ? "yes" : "no");
268// } // DEBUG_LOG
269//
270// if (authorizationData.getUsername() == null ||
271// authorizationData.getUsername().isEmpty() ||
272// authorizationData.getPassword()== null ||
273// authorizationData.getPassword().isEmpty())
274// // is actual an invalid request
275// throw kustvaktResponseHandler.throwit(StatusCodes.REQUEST_INVALID);
276//
277// Map<String, Object> attr = new HashMap<>();
278// if (scopes != null && !scopes.isEmpty())
279// attr.put(Attributes.SCOPE, scopes);
280// attr.put(Attributes.HOST, host);
281// attr.put(Attributes.USER_AGENT, agent);
282//
283// TokenContext context;
284// try {
285// // User user = controller.authenticate(0, values[0], values[1], attr); Implementation by Hanl
286// User user = controller.authenticate(AuthenticationMethod.LDAP,
287// authorizationData.getUsername(), authorizationData.getPassword(), attr); // Implementation with IdM/LDAP
288// // Userdata data = this.controller.getUserData(user, UserDetails.class); // Implem. by Hanl
289// // todo: is this necessary?
290// // attr.putAll(data.fields());
291//
292// // EM: add authentication time
293// Date authenticationTime = TimeUtils.getNow().toDate();
294// attr.put(Attributes.AUTHENTICATION_TIME, authenticationTime);
295// // -- EM
296//
297// controller.setAccessAndLocation(user, headers);
298// if (DEBUG_LOG == true) System.out.printf(
299// "Debug: /apiToken/: location=%s, access='%s'.\n",
300// user.locationtoString(), user.accesstoString());
301// attr.put(Attributes.LOCATION, user.getLocation());
302// attr.put(Attributes.CORPUS_ACCESS, user.getCorpusAccess());
303// context = controller.createTokenContext(user, attr,
304// TokenType.API);
305//// context = controller.createTokenContext(user, attr,
306//// Attributes.API_AUTHENTICATION);
307// }
308// catch (KustvaktException e) {
309// throw kustvaktResponseHandler.throwit(e);
310// }
311//
312// try {
313// return Response.ok(context.toJson()).build();
314// }
315// catch (KustvaktException e) {
316// throw kustvaktResponseHandler.throwit(e);
317// }
318// }
319
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200320
Michael Hanlfb839b92015-09-19 21:32:34 +0200321 // todo:
322 @Deprecated
323 @GET
324 @Path("refresh")
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200325 public Response refresh (@Context SecurityContext context,
Michael Hanlfb839b92015-09-19 21:32:34 +0200326 @Context Locale locale) {
327 TokenContext ctx = (TokenContext) context.getUserPrincipal();
328 TokenContext newContext;
329
330 // try {
331 // newContext = controller.refresh(ctx);
332 // }catch (KorAPException e) {
333 // KorAPLogger.ERROR_LOGGER.error("Exception encountered!", e);
Michael Hanl482f30d2015-09-25 12:39:46 +0200334 // throw KustvaktResponseHandler.throwit(e);
Michael Hanlfb839b92015-09-19 21:32:34 +0200335 // }
336 // return Response.ok().entity(newContext.getToken()).build();
337 return null;
338 }
339
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200340
Michael Hanlfb839b92015-09-19 21:32:34 +0200341 @GET
342 @Path("sessionToken")
Michael Hanl9be4e422016-07-21 14:13:27 +0200343 //@ResourceFilters({HeaderFilter.class})
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200344 public Response requestSession (@Context HttpHeaders headers,
Michael Hanlfb839b92015-09-19 21:32:34 +0200345 @Context Locale locale,
346 @HeaderParam(ContainerRequest.USER_AGENT) String agent,
347 @HeaderParam(ContainerRequest.HOST) String host) {
margarethaf18298b2017-09-14 22:14:32 +0200348 List<String> auth =
349 headers.getRequestHeader(ContainerRequest.AUTHORIZATION);
Michael Hanlfb839b92015-09-19 21:32:34 +0200350
margarethacd206792017-11-17 14:48:09 +0100351 AuthorizationData authorizationData;
margaretha4b5c1412017-11-15 20:55:04 +0100352 try {
margarethacd206792017-11-17 14:48:09 +0100353 authorizationData = authorizationHandler.
margaretha2afb97d2017-12-07 19:18:44 +0100354 parseAuthorizationHeaderValue(auth.get(0));
355 authorizationData = authorizationHandler.parseBasicToken(authorizationData);
margaretha4b5c1412017-11-15 20:55:04 +0100356
357 }
358 catch (KustvaktException e) {
margarethada3c7852018-06-14 20:35:11 +0200359 throw kustvaktResponseHandler.throwit(e);
margaretha4b5c1412017-11-15 20:55:04 +0100360 }
Michael Hanlfb839b92015-09-19 21:32:34 +0200361
Bodmo3d6bd352017-04-25 11:31:39 +0200362 // Implementation Hanl mit '|'. 16.02.17/FB
363 //if (values[0].equalsIgnoreCase("null")
364 // | values[1].equalsIgnoreCase("null"))
margarethacd206792017-11-17 14:48:09 +0100365 if (authorizationData.getUsername() == null ||
366 authorizationData.getUsername().isEmpty() ||
367 authorizationData.getPassword()== null ||
368 authorizationData.getPassword().isEmpty())
369 // is actual an invalid request
margarethada3c7852018-06-14 20:35:11 +0200370 throw kustvaktResponseHandler.throwit(StatusCodes.REQUEST_INVALID);
Michael Hanlfb839b92015-09-19 21:32:34 +0200371
Michael Hanl5fac8ab2016-01-29 16:33:04 +0100372 Map<String, Object> attr = new HashMap<>();
Michael Hanlfb839b92015-09-19 21:32:34 +0200373 attr.put(Attributes.HOST, host);
374 attr.put(Attributes.USER_AGENT, agent);
375 TokenContext context;
margarethaf18298b2017-09-14 22:14:32 +0200376 String contextJson;
Michael Hanlfb839b92015-09-19 21:32:34 +0200377 try {
margaretha2afb97d2017-12-07 19:18:44 +0100378 //EM: authentication scheme default
379 User user = controller.authenticate(AuthenticationMethod.DATABASE,
margarethacd206792017-11-17 14:48:09 +0100380 authorizationData.getUsername(), authorizationData.getPassword(), attr);
Michael Hanlfb839b92015-09-19 21:32:34 +0200381 context = controller.createTokenContext(user, attr,
margaretha2afb97d2017-12-07 19:18:44 +0100382 TokenType.SESSION);
383// context = controller.createTokenContext(user, attr,
384// Attributes.SESSION_AUTHENTICATION);
margarethaf18298b2017-09-14 22:14:32 +0200385 contextJson = context.toJson();
386 jlog.debug(contextJson);
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200387 }
388 catch (KustvaktException e) {
margarethada3c7852018-06-14 20:35:11 +0200389 throw kustvaktResponseHandler.throwit(e);
Michael Hanlfb839b92015-09-19 21:32:34 +0200390 }
margarethaf18298b2017-09-14 22:14:32 +0200391 return Response.ok().entity(contextJson).build();
Michael Hanlfb839b92015-09-19 21:32:34 +0200392 }
393
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200394
Michael Hanlfb839b92015-09-19 21:32:34 +0200395 // fixme: security issues: setup shibboleth compatible authentication system
396 // todo: will be purged with token authentication --> shib is client side
397 @POST
Michael Hanl6bfe4002016-07-02 11:43:09 +0200398 @Consumes(MediaType.APPLICATION_JSON)
Michael Hanlfb839b92015-09-19 21:32:34 +0200399 @Produces("application/json")
400 @Path("shibboleth")
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200401 public Response loginshib (@Context HttpHeaders headers,
Michael Hanlfb839b92015-09-19 21:32:34 +0200402 @Context Locale locale,
403 @HeaderParam(ContainerRequest.USER_AGENT) String agent,
404 @HeaderParam(ContainerRequest.HOST) String host,
405 @QueryParam("client_id") String client_id) {
406
407 // the shibfilter decrypted the values
408 // define default provider for returned access token strategy?!
409
Michael Hanl5fac8ab2016-01-29 16:33:04 +0100410 Map<String, Object> attr = new HashMap<>();
Michael Hanlfb839b92015-09-19 21:32:34 +0200411 attr.put(Attributes.HOST, host);
412 attr.put(Attributes.USER_AGENT, agent);
413
414 TokenContext context;
415
416 try {
417 // todo: distinguish type KorAP/Shibusers
margaretha2afb97d2017-12-07 19:18:44 +0100418 User user = controller.authenticate(AuthenticationMethod.SHIBBOLETH,
margaretha139d0f72017-11-14 18:56:22 +0100419 null, null, attr);
Michael Hanlfb839b92015-09-19 21:32:34 +0200420 context = controller.createTokenContext(user, attr, null);
Michael Hanl8abaf9e2016-05-23 16:46:35 +0200421 }
422 catch (KustvaktException e) {
margarethada3c7852018-06-14 20:35:11 +0200423 throw kustvaktResponseHandler.throwit(e);
Michael Hanlfb839b92015-09-19 21:32:34 +0200424 }
margarethad4796662017-11-09 16:11:40 +0100425 try {
426 return Response.ok().entity(context.toJson()).build();
427 }
428 catch (KustvaktException e) {
margarethada3c7852018-06-14 20:35:11 +0200429 throw kustvaktResponseHandler.throwit(e);
margarethad4796662017-11-09 16:11:40 +0100430 }
Michael Hanlfb839b92015-09-19 21:32:34 +0200431 }
Michael Hanl19390652016-01-16 11:01:24 +0100432
Michael Hanlfb839b92015-09-19 21:32:34 +0200433}