annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsUiRestlet.java @ 94:fcb6fe10e08c

added config option for webapp URL prefix.
author casties
date Tue, 10 Feb 2015 17:45:56 +0100
parents 25eb2e1df106
children 434264e1839a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
1 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
2 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
3 */
23
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
4 package de.mpiwg.itgroup.annotations.restlet.annotations_ui;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
5
70
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
6 /*
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
7 * #%L
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
8 * AnnotationManager
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
9 * %%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
10 * Copyright (C) 2012 - 2014 MPIWG Berlin
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
11 * %%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
12 * This program is free software: you can redistribute it and/or modify
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
13 * it under the terms of the GNU Lesser General Public License as
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
14 * published by the Free Software Foundation, either version 3 of the
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
15 * License, or (at your option) any later version.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
16 *
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
17 * This program is distributed in the hope that it will be useful,
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
20 * GNU General Lesser Public License for more details.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
21 *
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
22 * You should have received a copy of the GNU General Lesser Public
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
23 * License along with this program. If not, see
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
24 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
25 * #L%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
26 */
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 53
diff changeset
27
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 72
diff changeset
28 import java.util.logging.Logger;
25eb2e1df106 change logging to java.util.logging.
casties
parents: 72
diff changeset
29
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
30 import org.restlet.Restlet;
49
f30f42080711 first steps for authorization for annotations ui.
casties
parents: 34
diff changeset
31 import org.restlet.data.ChallengeScheme;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
32 import org.restlet.routing.Router;
49
f30f42080711 first steps for authorization for annotations ui.
casties
parents: 34
diff changeset
33 import org.restlet.security.ChallengeAuthenticator;
f30f42080711 first steps for authorization for annotations ui.
casties
parents: 34
diff changeset
34 import org.restlet.security.MapVerifier;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
35
23
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
36 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
94
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
37 import de.mpiwg.itgroup.annotations.restlet.utils.UrlPrefixFilter;
23
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
38
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
39 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
40 * @author casties
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
41 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
42 */
23
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
43 public class AnnotationsUiRestlet extends BaseRestlet {
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
44
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 49
diff changeset
45 public final String version = "AnnotationManagerN4J/AnnotationsUI 0.3";
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
46
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 72
diff changeset
47 public static Logger logger = Logger.getLogger("de.mpiwg.itgroup.annotations.restlet.annotations_ui.AnnotationsUiRestlet");
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
48
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
49 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
50 * (non-Javadoc)
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
51 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
52 * @see org.restlet.Application#createInboundRoot()
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
53 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
54 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
55 public Restlet createInboundRoot() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
56 // this.authenticator = createAuthenticator();
94
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
57 Restlet root = null;
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
58
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
59 Router router = new Router(getContext());
23
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
60 router.attach("/groups", GroupsResource.class);
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
61 router.attach("/groups/", GroupsResource.class);
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
62 router.attach("/groups/{id}", GroupResource.class);
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
63 router.attach("/groups/{id}/", GroupResource.class);
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
64 router.attach("/groups/{id}/members", GroupMembersResource.class);
32
0731c4549065 UI for editing groups and persons works now. (still no authorisation!)
casties
parents: 23
diff changeset
65 router.attach("/persons", PersonsResource.class);
0731c4549065 UI for editing groups and persons works now. (still no authorisation!)
casties
parents: 23
diff changeset
66 router.attach("/persons/", PersonsResource.class);
0731c4549065 UI for editing groups and persons works now. (still no authorisation!)
casties
parents: 23
diff changeset
67 router.attach("/persons/{id}", PersonResource.class);
0731c4549065 UI for editing groups and persons works now. (still no authorisation!)
casties
parents: 23
diff changeset
68 router.attach("/persons/{id}/", PersonResource.class);
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 49
diff changeset
69 router.attach("/annotations", AnnotationsResource.class);
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 49
diff changeset
70 router.attach("/annotations/", AnnotationsResource.class);
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 49
diff changeset
71 router.attach("/annotations/{id}", AnnotationResource.class);
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 49
diff changeset
72 router.attach("/annotations/{id}/", AnnotationResource.class);
23
d22d01ba953a reorganised code for annotations and groups ui. work in progress.
casties
parents: 22
diff changeset
73 router.attach("/", InfoResource.class);
94
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
74 root = router;
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
75
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
76 if (this.webappUriPrefix != null) {
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
77 // add prefix path to url
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
78 UrlPrefixFilter prefixFilter = new UrlPrefixFilter();
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
79 prefixFilter.setPrefix(this.webappUriPrefix);;
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
80 prefixFilter.setNext(root);
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
81 root = prefixFilter;
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
82 }
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
83
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 49
diff changeset
84 // use simple password verifier
49
f30f42080711 first steps for authorization for annotations ui.
casties
parents: 34
diff changeset
85 MapVerifier verifier = new MapVerifier();
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 49
diff changeset
86 // get user name and password
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 49
diff changeset
87 String user = serverConfig.getProperty(BaseRestlet.ADMIN_USER_KEY);
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 49
diff changeset
88 String pw = serverConfig.getProperty(BaseRestlet.ADMIN_PASSWORD_KEY);
53
fc4c23247bb5 don't crash if admin user missing in config.
casties
parents: 50
diff changeset
89 if (user != null && pw != null) {
fc4c23247bb5 don't crash if admin user missing in config.
casties
parents: 50
diff changeset
90 verifier.getLocalSecrets().put(user, pw.toCharArray());
fc4c23247bb5 don't crash if admin user missing in config.
casties
parents: 50
diff changeset
91 } else {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 72
diff changeset
92 logger.severe("Admin user and password missing in serverconfig!");
53
fc4c23247bb5 don't crash if admin user missing in config.
casties
parents: 50
diff changeset
93 }
49
f30f42080711 first steps for authorization for annotations ui.
casties
parents: 34
diff changeset
94 // Create a Guard
f30f42080711 first steps for authorization for annotations ui.
casties
parents: 34
diff changeset
95 ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "Tutorial");
f30f42080711 first steps for authorization for annotations ui.
casties
parents: 34
diff changeset
96 guard.setVerifier(verifier);
f30f42080711 first steps for authorization for annotations ui.
casties
parents: 34
diff changeset
97 // put everything through guard
94
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
98 guard.setNext(root);
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
99 root = guard;
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
100
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
101 return root;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
102 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
103
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
104 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
105 public String getVersion() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
106 return version;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
107 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
108
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
109 }