source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsUiRestlet.java @ 97:434264e1839a

Last change on this file since 97:434264e1839a was 97:434264e1839a, checked in by casties, 9 years ago

fixed http login realm name.

File size: 3.8 KB
Line 
1/**
2 *
3 */
4package 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
28import java.util.logging.Logger;
29
30import org.restlet.Restlet;
31import org.restlet.data.ChallengeScheme;
32import org.restlet.routing.Router;
33import org.restlet.security.ChallengeAuthenticator;
34import org.restlet.security.MapVerifier;
35
36import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
37import de.mpiwg.itgroup.annotations.restlet.utils.UrlPrefixFilter;
38
39/**
40 * @author casties
41 *
42 */
43public class AnnotationsUiRestlet extends BaseRestlet {
44
45    public final String version = "AnnotationManagerN4J/AnnotationsUI 0.3";
46
47    public static Logger logger = Logger.getLogger("de.mpiwg.itgroup.annotations.restlet.annotations_ui.AnnotationsUiRestlet");
48
49    /*
50     * (non-Javadoc)
51     *
52     * @see org.restlet.Application#createInboundRoot()
53     */
54    @Override
55    public Restlet createInboundRoot() {
56        // this.authenticator = createAuthenticator();
57        Restlet root = null;
58       
59        Router router = new Router(getContext());
60        router.attach("/groups", GroupsResource.class);
61        router.attach("/groups/", GroupsResource.class);
62        router.attach("/groups/{id}", GroupResource.class);
63        router.attach("/groups/{id}/", GroupResource.class);
64        router.attach("/groups/{id}/members", GroupMembersResource.class);
65        router.attach("/persons", PersonsResource.class);
66        router.attach("/persons/", PersonsResource.class);
67        router.attach("/persons/{id}", PersonResource.class);
68        router.attach("/persons/{id}/", PersonResource.class);
69        router.attach("/annotations", AnnotationsResource.class);
70        router.attach("/annotations/", AnnotationsResource.class);
71        router.attach("/annotations/{id}", AnnotationResource.class);
72        router.attach("/annotations/{id}/", AnnotationResource.class);
73        router.attach("/", InfoResource.class);
74        root = router;
75       
76        if (this.webappUriPrefix != null) {
77                // add prefix path to url
78                UrlPrefixFilter prefixFilter = new UrlPrefixFilter();
79                prefixFilter.setPrefix(this.webappUriPrefix);;
80                prefixFilter.setNext(root);
81                root = prefixFilter;
82        }
83
84        // use simple password verifier
85        MapVerifier verifier = new MapVerifier();
86        // get user name and password
87        String user = serverConfig.getProperty(BaseRestlet.ADMIN_USER_KEY);
88        String pw = serverConfig.getProperty(BaseRestlet.ADMIN_PASSWORD_KEY);
89        if (user != null && pw != null) {
90            verifier.getLocalSecrets().put(user, pw.toCharArray());
91        } else {
92            logger.severe("Admin user and password missing in serverconfig!");
93        }
94        // Create a Guard
95        ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "Annotation Server Admin");
96        guard.setVerifier(verifier);
97        // put everything through guard
98        guard.setNext(root);
99        root = guard;
100       
101        return root;
102    }
103
104    @Override
105    public String getVersion() {
106        return version;
107    }
108
109}
Note: See TracBrowser for help on using the repository browser.