annotate src/main/java/de/intevation/lada/rest/AuthInfoService.java @ 291:1a01e1473dc7

Added authinfo service. This service returns information about ownership and readonly status of a probe object.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 14 Aug 2013 13:27:26 +0200
parents
children 567ce7697fc7
rev   line source
291
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 package de.intevation.lada.rest;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 import javax.enterprise.context.RequestScoped;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4 import javax.inject.Inject;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 import javax.inject.Named;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 import javax.ws.rs.GET;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 import javax.ws.rs.Path;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 import javax.ws.rs.PathParam;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 import javax.ws.rs.Produces;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import javax.ws.rs.core.Context;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import javax.ws.rs.core.HttpHeaders;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import javax.ws.rs.core.UriInfo;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import de.intevation.lada.auth.Authentication;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 import de.intevation.lada.auth.AuthenticationException;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 import de.intevation.lada.auth.Authorization;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 /**
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 * This class produces a RESTful service to get information about
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 * access of probe objects.
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 *
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 */
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 @Path("/authinfo")
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 @RequestScoped
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 public class AuthInfoService
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 {
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 /**
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 * The authorization module.
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 */
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 @Inject
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 @Named("ldapauth")
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 private Authentication authentication;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 @Inject
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 @Named("dataauthorization")
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 private Authorization authorization;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 /**
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 * Request information about access to probe objects
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 *
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 * @param info The URL query parameters.
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 * @param headers The HTTP header containing authorization information.
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 * @return Response object.
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 */
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 @GET
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 @Path("/{id}")
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 @Produces("text/json")
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 public Response get(
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 @PathParam("id") String id,
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 @Context HttpHeaders headers
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 ) {
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 try {
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 if (!authentication.isAuthorizedUser(headers)) {
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 return new Response(false, 699, null);
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 }
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 boolean isOwner = false;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 boolean isReadonly = true;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 if (authentication.hasAccess(headers, id)) {
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 isOwner = true;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 }
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 if (!authorization.isReadOnly(id)) {
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 isReadonly = false;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 }
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 Response response = new Response(
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 true,
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 200,
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 "{isOwner: " + isOwner + ", readonly:" + isReadonly + "}");
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 return response;
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 }
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 catch(AuthenticationException ae) {
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 return new Response(false, 699, null);
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 }
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 }
1a01e1473dc7 Added authinfo service. This service returns information about ownership and readonly status of a probe object.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)