1 | /** |
---|
2 | * |
---|
3 | */ |
---|
4 | package de.mpiwg.itgroup.annotations.restlet.annotations_ui; |
---|
5 | |
---|
6 | /* |
---|
7 | * #%L |
---|
8 | * AnnotationManager |
---|
9 | * %% |
---|
10 | * Copyright (C) 2012 - 2014 MPIWG Berlin |
---|
11 | * %% |
---|
12 | * This program is free software: you can redistribute it and/or modify |
---|
13 | * it under the terms of the GNU Lesser General Public License as |
---|
14 | * published by the Free Software Foundation, either version 3 of the |
---|
15 | * License, or (at your option) any later version. |
---|
16 | * |
---|
17 | * This program is distributed in the hope that it will be useful, |
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | * GNU General Lesser Public License for more details. |
---|
21 | * |
---|
22 | * You should have received a copy of the GNU General Lesser Public |
---|
23 | * License along with this program. If not, see |
---|
24 | * <http://www.gnu.org/licenses/lgpl-3.0.html>. |
---|
25 | * #L% |
---|
26 | */ |
---|
27 | |
---|
28 | import org.apache.log4j.Logger; |
---|
29 | import org.restlet.Context; |
---|
30 | import org.restlet.Restlet; |
---|
31 | import org.restlet.data.ChallengeScheme; |
---|
32 | import org.restlet.routing.Router; |
---|
33 | import org.restlet.security.ChallengeAuthenticator; |
---|
34 | import org.restlet.security.MapVerifier; |
---|
35 | |
---|
36 | import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; |
---|
37 | |
---|
38 | /** |
---|
39 | * @author casties |
---|
40 | * |
---|
41 | */ |
---|
42 | public class AnnotationsUiRestlet extends BaseRestlet { |
---|
43 | |
---|
44 | public final String version = "AnnotationManagerN4J/AnnotationsUI 0.3"; |
---|
45 | |
---|
46 | public static Logger logger = Logger.getLogger(AnnotationsUiRestlet.class); |
---|
47 | |
---|
48 | public AnnotationsUiRestlet(Context context) { |
---|
49 | super(context); |
---|
50 | logger.info(version); |
---|
51 | } |
---|
52 | |
---|
53 | /* |
---|
54 | * (non-Javadoc) |
---|
55 | * |
---|
56 | * @see org.restlet.Application#createInboundRoot() |
---|
57 | */ |
---|
58 | @Override |
---|
59 | public Restlet createInboundRoot() { |
---|
60 | // this.authenticator = createAuthenticator(); |
---|
61 | |
---|
62 | Router router = new Router(getContext()); |
---|
63 | |
---|
64 | router.attach("/groups", GroupsResource.class); |
---|
65 | router.attach("/groups/", GroupsResource.class); |
---|
66 | router.attach("/groups/{id}", GroupResource.class); |
---|
67 | router.attach("/groups/{id}/", GroupResource.class); |
---|
68 | router.attach("/groups/{id}/members", GroupMembersResource.class); |
---|
69 | router.attach("/persons", PersonsResource.class); |
---|
70 | router.attach("/persons/", PersonsResource.class); |
---|
71 | router.attach("/persons/{id}", PersonResource.class); |
---|
72 | router.attach("/persons/{id}/", PersonResource.class); |
---|
73 | router.attach("/annotations", AnnotationsResource.class); |
---|
74 | router.attach("/annotations/", AnnotationsResource.class); |
---|
75 | router.attach("/annotations/{id}", AnnotationResource.class); |
---|
76 | router.attach("/annotations/{id}/", AnnotationResource.class); |
---|
77 | |
---|
78 | router.attach("/", InfoResource.class); |
---|
79 | |
---|
80 | // use simple password verifier |
---|
81 | MapVerifier verifier = new MapVerifier(); |
---|
82 | // get user name and password |
---|
83 | String user = serverConfig.getProperty(BaseRestlet.ADMIN_USER_KEY); |
---|
84 | String pw = serverConfig.getProperty(BaseRestlet.ADMIN_PASSWORD_KEY); |
---|
85 | if (user != null && pw != null) { |
---|
86 | verifier.getLocalSecrets().put(user, pw.toCharArray()); |
---|
87 | } else { |
---|
88 | logger.error("Admin user and password missing in serverconfig!"); |
---|
89 | } |
---|
90 | // Create a Guard |
---|
91 | ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "Tutorial"); |
---|
92 | guard.setVerifier(verifier); |
---|
93 | // put everything through guard |
---|
94 | guard.setNext(router); |
---|
95 | return guard; |
---|
96 | } |
---|
97 | |
---|
98 | @Override |
---|
99 | public String getVersion() { |
---|
100 | return version; |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|