Mercurial > hg > MetaDataManagerRestlet
comparison src/de/mpiwg/itgroup/metaDataManagerRestlet/RestServer.java @ 4:aae47a713589
editing
author | dwinter |
---|---|
date | Mon, 02 Jan 2012 12:42:28 +0100 |
parents | dfd72ea936ff |
children | a59be29f06c8 |
comparison
equal
deleted
inserted
replaced
3:dfd72ea936ff | 4:aae47a713589 |
---|---|
1 package de.mpiwg.itgroup.metaDataManagerRestlet; | 1 package de.mpiwg.itgroup.metaDataManagerRestlet; |
2 | |
3 import java.net.URI; | |
4 import java.net.URISyntaxException; | |
5 | |
6 import javax.security.auth.callback.CallbackHandler; | |
7 import javax.security.auth.login.Configuration; | |
2 | 8 |
3 import org.apache.log4j.BasicConfigurator; | 9 import org.apache.log4j.BasicConfigurator; |
4 import org.apache.log4j.Level; | 10 import org.apache.log4j.Level; |
5 import org.apache.log4j.Logger; | 11 import org.apache.log4j.Logger; |
6 import org.restlet.Application; | 12 import org.restlet.Application; |
7 import org.restlet.Context; | 13 import org.restlet.Context; |
14 import org.restlet.Request; | |
15 import org.restlet.Response; | |
8 import org.restlet.Restlet; | 16 import org.restlet.Restlet; |
17 import org.restlet.data.ChallengeScheme; | |
18 import org.restlet.ext.jaas.JaasVerifier; | |
9 import org.restlet.routing.Router; | 19 import org.restlet.routing.Router; |
10 import org.restlet.routing.Template; | 20 import org.restlet.routing.Template; |
11 import org.restlet.routing.TemplateRoute; | 21 import org.restlet.routing.TemplateRoute; |
22 import org.restlet.security.ChallengeAuthenticator; | |
23 | |
24 import com.sun.security.auth.login.ConfigFile; | |
12 | 25 |
13 import de.mpiwg.itgroup.metaDataManagerRestlet.pid.PIDcreator; | 26 import de.mpiwg.itgroup.metaDataManagerRestlet.pid.PIDcreator; |
14 import de.mpiwg.itgroup.metaDataManagerRestlet.ui.GeneralInfo; | 27 import de.mpiwg.itgroup.metaDataManagerRestlet.ui.GeneralInfo; |
15 import de.mpiwg.itgroup.metaDataManagerRestlet.ui.SearchPersons; | 28 import de.mpiwg.itgroup.metaDataManagerRestlet.ui.SearchPersons; |
16 import de.mpiwg.itgroup.metadataManager.indexMeta.server.IndexMetaProvider; | 29 import de.mpiwg.itgroup.metadataManager.indexMeta.server.IndexMetaProvider; |
30 import de.mpiwg.itgroup.nimanager.edit.Editor; | |
17 import de.mpiwg.itgroup.nimanager.persons.PersonByNameService; | 31 import de.mpiwg.itgroup.nimanager.persons.PersonByNameService; |
18 import de.mpiwg.itgroup.nimanager.persons.PersonByIDService; | 32 import de.mpiwg.itgroup.nimanager.persons.PersonByIDService; |
19 import de.mpiwg.itgroup.nimanager.persons.PersonListService; | 33 import de.mpiwg.itgroup.nimanager.persons.PersonListService; |
20 //import de.mpiwg.itgroup.nimanager.persons.PersonService; | 34 //import de.mpiwg.itgroup.nimanager.persons.PersonService; |
21 import de.mpiwg.itgroup.nimanager.persons.PersonService; | 35 import de.mpiwg.itgroup.nimanager.persons.PersonService; |
32 rl.setLevel(Level.DEBUG); | 46 rl.setLevel(Level.DEBUG); |
33 | 47 |
34 | 48 |
35 } | 49 } |
36 | 50 |
51 | |
52 private ChallengeAuthenticator authenticator; | |
53 private CallbackHandler callbackHandler; | |
54 | |
55 /** Erzeuge einen Authenticator | |
56 * @return | |
57 */ | |
58 private ChallengeAuthenticator createAuthenticator() { | |
59 Context context = getContext(); | |
60 boolean optional = true; | |
61 ChallengeScheme challengeScheme = ChallengeScheme.HTTP_BASIC; | |
62 String realm = "Annotation Service"; | |
63 | |
64 JaasVerifier verifier = new JaasVerifier("BasicJaasAuthenticationApplication"); | |
65 //JaasVerifier verifier = new JaasVerifier("DummyAuthentication"); | |
66 | |
67 Configuration jaasConfig; | |
68 jaasConfig = createConfiguration(); | |
69 | |
70 | |
71 verifier.setConfiguration(jaasConfig); | |
72 verifier.setUserPrincipalClassName("com.sun.security.auth.UserPrincipal"); | |
73 | |
74 ChallengeAuthenticator auth = new ChallengeAuthenticator(context, optional, challengeScheme, realm, verifier) { | |
75 @Override | |
76 protected boolean authenticate(Request request, Response response) { | |
77 if (request.getChallengeResponse() == null) { | |
78 return false; | |
79 } else { | |
80 return super.authenticate(request, response); | |
81 } | |
82 } | |
83 }; | |
84 | |
85 return auth; | |
86 } | |
87 | |
88 /** | |
89 * Konfiguration für den Authentificator in Jaas. Pfad zum JAAS-Konfigurationsfile liegt im Context-Parameter | |
90 * "de.mpiwg.itgroup.annotationManager.jaas.configFilePath". | |
91 * @return | |
92 */ | |
93 protected Configuration createConfiguration() { | |
94 Configuration jaasConfig; | |
95 URI confUri; | |
96 | |
97 Context context = getContext(); | |
98 String configFilePath = context.getParameters().getFirstValue("de.mpiwg.itgroup.jaas.configFilePath"); | |
99 | |
100 | |
101 try { | |
102 confUri = new URI(configFilePath); | |
103 } catch (URISyntaxException e) { | |
104 e.printStackTrace(); | |
105 confUri = null; | |
106 } | |
107 | |
108 jaasConfig= new ConfigFile(confUri); | |
109 return jaasConfig; | |
110 } | |
111 | |
112 | |
113 | |
114 | |
115 | |
37 public synchronized Restlet createInboundRoot(){ | 116 public synchronized Restlet createInboundRoot(){ |
117 this.authenticator = createAuthenticator(); | |
118 | |
38 Router router = new Router(getContext()); | 119 Router router = new Router(getContext()); |
39 | 120 |
40 router.attach("/",GeneralInfo.class); | 121 router.attach("/",GeneralInfo.class); |
41 router.attach("/PID",PIDcreator.class); | 122 router.attach("/PID",PIDcreator.class); |
42 router.attach("/searchPersons",SearchPersons.class); | 123 router.attach("/searchPersons",SearchPersons.class); |
43 router.attach("/person/name/{name}",PersonByNameService.class); | 124 router.attach("/person/name/{name}",PersonByNameService.class); |
44 router.attach("/persons",PersonListService.class); | 125 router.attach("/persons",PersonListService.class); |
45 router.attach("/person/id/{personId}",PersonService.class); | 126 router.attach("/person/id/{personId}",PersonService.class); |
46 router.attach("/person/id/{personId}/{graphId}",PersonService.class); | 127 router.attach("/person/id/{personId}/{graphId}",PersonService.class); |
47 router.attach("/ids",PersonByIDService.class); | 128 router.attach("/ids",PersonByIDService.class); |
129 router.attach("/edit",Editor.class); | |
48 TemplateRoute route = router.attach("/indexMeta", IndexMetaProvider.class); | 130 TemplateRoute route = router.attach("/indexMeta", IndexMetaProvider.class); |
49 route.setMatchingMode(Template.MODE_STARTS_WITH); | 131 route.setMatchingMode(Template.MODE_STARTS_WITH); |
50 | 132 |
133 authenticator.setNext(router); | |
134 return authenticator; | |
135 | |
136 | |
51 | 137 |
52 return router; | |
53 } | 138 } |
139 | |
140 /** | |
141 * Authentifiziere den Benutzer aus dem Request (BasicAuthenfication) | |
142 * @param request | |
143 * @param response | |
144 * @return | |
145 */ | |
146 public boolean authenticate(Request request, Response response) { | |
147 if (!request.getClientInfo().isAuthenticated()) { | |
148 authenticator.challenge(response, false); | |
149 return false; | |
150 } | |
151 | |
152 if(request.getClientInfo().getUser()==null) //FIXME sometimes ist authenticated true, but no user | |
153 { | |
154 authenticator.challenge(response, false); | |
155 return false; | |
156 } | |
157 | |
158 | |
159 return true; | |
160 } | |
161 | |
54 } | 162 } |
55 | 163 |