annotate src/main/java/de/intevation/lada/rest/AuthInfoService.java @ 366:567ce7697fc7 0.5

Code documentation.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 10 Sep 2013 15:55:54 +0200
parents 1a01e1473dc7
children f3d0894d9bfc
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;
366
567ce7697fc7 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 291
diff changeset
17 import de.intevation.lada.model.LProbe;
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
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 /**
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 * 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
21 * 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
22 *
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 * @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
24 */
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 @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
26 @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
27 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
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 /**
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 * 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
31 */
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 @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
33 @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
34 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
35
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 @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
37 @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
38 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
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 /**
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 * 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
42 *
366
567ce7697fc7 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 291
diff changeset
43 * @param id The {@link LProbe} id.
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
44 * @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
45 * @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
46 */
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 @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
48 @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
49 @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
50 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
51 @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
52 @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
53 ) {
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 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
55 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
56 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
57 }
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 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
59 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
60 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
61 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
62 }
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 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
64 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
65 }
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 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
67 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
68 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
69 "{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
70 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
71 }
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 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
73 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
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 }
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
76 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)