Revision 8874
Added by ben leinfelder almost 10 years ago
MNResourceHandler.java | ||
---|---|---|
44 | 44 |
import org.dataone.client.v2.formats.ObjectFormatInfo; |
45 | 45 |
import org.dataone.mimemultipart.MultipartRequest; |
46 | 46 |
import org.dataone.mimemultipart.MultipartRequestResolver; |
47 |
import org.dataone.portal.TokenGenerator; |
|
47 | 48 |
import org.dataone.service.exceptions.BaseException; |
48 | 49 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
49 | 50 |
import org.dataone.service.exceptions.InsufficientResources; |
... | ... | |
82 | 83 |
import edu.ucsb.nceas.metacat.restservice.D1ResourceHandler; |
83 | 84 |
import edu.ucsb.nceas.metacat.util.DeleteOnCloseFileInputStream; |
84 | 85 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
86 |
import edu.ucsb.nceas.metacat.MetaCatServlet; |
|
85 | 87 |
|
88 |
|
|
86 | 89 |
/** |
87 | 90 |
* MN REST service implementation handler |
88 | 91 |
* |
... | ... | |
136 | 139 |
protected static final String RESOURCE_PUBLISH = "publish"; |
137 | 140 |
protected static final String RESOURCE_PACKAGE = "package"; |
138 | 141 |
protected static final String RESOURCE_VIEWS = "views"; |
142 |
protected static final String RESOURCE_TOKEN = "token"; |
|
139 | 143 |
|
140 | 144 |
|
141 | 145 |
|
... | ... | |
214 | 218 |
// node response |
215 | 219 |
node(); |
216 | 220 |
status = true; |
221 |
} else if (resource.startsWith(RESOURCE_TOKEN)) { |
|
222 |
logMetacat.debug("Using resource 'token'"); |
|
223 |
// get |
|
224 |
if (httpVerb == GET) { |
|
225 |
// after the command |
|
226 |
getToken(); |
|
227 |
status = true; |
|
228 |
} |
|
229 |
|
|
217 | 230 |
} else if (resource.startsWith(RESOURCE_IS_AUTHORIZED)) { |
218 | 231 |
if (httpVerb == GET) { |
219 | 232 |
// after the command |
... | ... | |
452 | 465 |
} |
453 | 466 |
} |
454 | 467 |
|
468 |
private void getToken() throws Exception { |
|
469 |
|
|
470 |
if (this.session != null) { |
|
471 |
String userId = this.session.getSubject().getValue(); |
|
455 | 472 |
|
473 |
String token = null; |
|
474 |
token = TokenGenerator.getJWT(userId); |
|
475 |
|
|
476 |
response.setStatus(200); |
|
477 |
response.setContentType("text/plain"); |
|
478 |
OutputStream out = response.getOutputStream(); |
|
479 |
out.write(token.getBytes(MetaCatServlet.DEFAULT_ENCODING)); |
|
480 |
out.close(); |
|
481 |
} else { |
|
482 |
response.setStatus(401); |
|
483 |
response.setContentType("text/plain"); |
|
484 |
OutputStream out = response.getOutputStream(); |
|
485 |
out.write("No session information found".getBytes(MetaCatServlet.DEFAULT_ENCODING)); |
|
486 |
out.close(); |
|
487 |
} |
|
488 |
|
|
489 |
} |
|
490 |
|
|
456 | 491 |
private void doQuery(String engine, String query) { |
457 | 492 |
|
458 | 493 |
OutputStream out = null; |
Also available in: Unified diff
add /token endpoint for annotatorJS/annotateIt.org integration. https://github.com/DataONEorg/sem-prov-design/issues/18