Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsUiRestlet.java @ 53:fc4c23247bb5
don't crash if admin user missing in config.
author | casties |
---|---|
date | Thu, 15 Nov 2012 15:05:34 +0100 |
parents | 64aa756c60cc |
children | 2b1e6df5e21a |
rev | line source |
---|---|
18 | 1 /** |
2 * | |
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 | 5 |
6 import org.apache.log4j.Logger; | |
7 import org.restlet.Context; | |
8 import org.restlet.Restlet; | |
49 | 9 import org.restlet.data.ChallengeScheme; |
18 | 10 import org.restlet.routing.Router; |
49 | 11 import org.restlet.security.ChallengeAuthenticator; |
12 import org.restlet.security.MapVerifier; | |
18 | 13 |
23
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
14 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; |
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
15 |
18 | 16 /** |
17 * @author casties | |
18 * | |
19 */ | |
23
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
20 public class AnnotationsUiRestlet extends BaseRestlet { |
18 | 21 |
50 | 22 public final String version = "AnnotationManagerN4J/AnnotationsUI 0.3"; |
18 | 23 |
23
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
24 public static Logger logger = Logger.getLogger(AnnotationsUiRestlet.class); |
18 | 25 |
23
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
26 public AnnotationsUiRestlet(Context context) { |
18 | 27 super(context); |
50 | 28 logger.info(version); |
18 | 29 } |
30 | |
31 /* | |
32 * (non-Javadoc) | |
33 * | |
34 * @see org.restlet.Application#createInboundRoot() | |
35 */ | |
36 @Override | |
37 public Restlet createInboundRoot() { | |
38 // this.authenticator = createAuthenticator(); | |
39 | |
40 Router router = new Router(getContext()); | |
41 | |
23
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
42 router.attach("/groups", GroupsResource.class); |
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
43 router.attach("/groups/", GroupsResource.class); |
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
44 router.attach("/groups/{id}", GroupResource.class); |
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
45 router.attach("/groups/{id}/", GroupResource.class); |
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
46 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
|
47 router.attach("/persons", PersonsResource.class); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
23
diff
changeset
|
48 router.attach("/persons/", PersonsResource.class); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
23
diff
changeset
|
49 router.attach("/persons/{id}", PersonResource.class); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
23
diff
changeset
|
50 router.attach("/persons/{id}/", PersonResource.class); |
50 | 51 router.attach("/annotations", AnnotationsResource.class); |
52 router.attach("/annotations/", AnnotationsResource.class); | |
53 router.attach("/annotations/{id}", AnnotationResource.class); | |
54 router.attach("/annotations/{id}/", AnnotationResource.class); | |
18 | 55 |
23
d22d01ba953a
reorganised code for annotations and groups ui. work in progress.
casties
parents:
22
diff
changeset
|
56 router.attach("/", InfoResource.class); |
18 | 57 |
50 | 58 // use simple password verifier |
49 | 59 MapVerifier verifier = new MapVerifier(); |
50 | 60 // get user name and password |
61 String user = serverConfig.getProperty(BaseRestlet.ADMIN_USER_KEY); | |
62 String pw = serverConfig.getProperty(BaseRestlet.ADMIN_PASSWORD_KEY); | |
53 | 63 if (user != null && pw != null) { |
64 verifier.getLocalSecrets().put(user, pw.toCharArray()); | |
65 } else { | |
66 logger.error("Admin user and password missing in serverconfig!"); | |
67 } | |
49 | 68 // Create a Guard |
69 ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "Tutorial"); | |
70 guard.setVerifier(verifier); | |
71 // put everything through guard | |
72 guard.setNext(router); | |
73 return guard; | |
18 | 74 } |
75 | |
76 @Override | |
77 public String getVersion() { | |
78 return version; | |
79 } | |
80 | |
81 } |