Project

General

Profile

« Previous | Next » 

Revision 8874

add /token endpoint for annotatorJS/annotateIt.org integration. https://github.com/DataONEorg/sem-prov-design/issues/18

View differences:

lib/metacat.properties
662 662
index.hazelcast.indexqueue=hzIndexQueue
663 663
index.hazelcast.indexeventmap=hzIndexEventMap
664 664

  
665
############# Annotator Section ###########################################
666
annotator.sharedSecret=oursharedsecret
667
annotator.consumerKey=myconsumerkey
668

  
665 669
############# SOLR Search Section ###########################################
666 670
#Embedded (default):
667 671
solr.server.classname=org.apache.solr.client.solrj.embedded.EmbeddedSolrServer
src/edu/ucsb/nceas/metacat/restservice/v1/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;
src/edu/ucsb/nceas/metacat/restservice/v2/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;
......
58 59
import org.dataone.service.exceptions.UnsupportedType;
59 60
import org.dataone.service.types.v1.Checksum;
60 61
import org.dataone.service.types.v1.DescribeResponse;
61
import org.dataone.service.types.v1.Event;
62 62
import org.dataone.service.types.v1.Identifier;
63
import org.dataone.service.types.v2.Log;
64
import org.dataone.service.types.v2.Node;
65 63
import org.dataone.service.types.v1.NodeReference;
66 64
import org.dataone.service.types.v1.ObjectFormatIdentifier;
67 65
import org.dataone.service.types.v1.ObjectList;
68 66
import org.dataone.service.types.v1.Permission;
69
import org.dataone.service.types.v2.SystemMetadata;
70 67
import org.dataone.service.types.v1_1.QueryEngineDescription;
71 68
import org.dataone.service.types.v1_1.QueryEngineList;
69
import org.dataone.service.types.v2.Log;
70
import org.dataone.service.types.v2.Node;
71
import org.dataone.service.types.v2.SystemMetadata;
72 72
import org.dataone.service.util.Constants;
73 73
import org.dataone.service.util.DateTimeMarshaller;
74 74
import org.dataone.service.util.ExceptionHandler;
......
76 76
import org.jibx.runtime.JiBXException;
77 77
import org.xml.sax.SAXException;
78 78

  
79
import edu.ucsb.nceas.metacat.MetaCatServlet;
79 80
import edu.ucsb.nceas.metacat.common.query.stream.ContentTypeInputStream;
80 81
import edu.ucsb.nceas.metacat.dataone.MNodeService;
81 82
import edu.ucsb.nceas.metacat.properties.PropertyService;
......
136 137
    protected static final String RESOURCE_PUBLISH = "publish";
137 138
    protected static final String RESOURCE_PACKAGE = "package";
138 139
    protected static final String RESOURCE_VIEWS = "views";
140
    protected static final String RESOURCE_TOKEN = "token";
139 141

  
140 142

  
143

  
141 144
    
142 145
    // shared executor
143 146
	private static ExecutorService executor = null;
......
214 217
                    // node response
215 218
                    node();
216 219
                    status = true;
220
                } else if (resource.startsWith(RESOURCE_TOKEN)) {
221
                    logMetacat.debug("Using resource 'token'");
222
                    // get
223
                    if (httpVerb == GET) {
224
                    	// after the command
225
                        getToken();
226
                        status = true;
227
                    }
228
                    
217 229
                } else if (resource.startsWith(RESOURCE_IS_AUTHORIZED)) {
218 230
                    if (httpVerb == GET) {
219 231
                    	// after the command
......
738 750
		return result;
739 751
    }
740 752
    
753
    private void getToken() throws Exception {
754
		
755
		if (this.session != null) {
756
			String userId = this.session.getSubject().getValue();
757

  
758
			String token = null;
759
			token = TokenGenerator.getJWT(userId);
760
			
761
			response.setStatus(200);
762
			response.setContentType("text/plain");
763
	        OutputStream out = response.getOutputStream();
764
	        out.write(token.getBytes(MetaCatServlet.DEFAULT_ENCODING));
765
	        out.close();
766
		} else {
767
			response.setStatus(401);
768
			response.setContentType("text/plain");
769
			OutputStream out = response.getOutputStream();
770
	        out.write("No session information found".getBytes(MetaCatServlet.DEFAULT_ENCODING));
771
	        out.close();
772
		}
773
		
774
    }
775
    
741 776
    /**
742 777
     * Processes failed synchronization message
743 778
     * @throws NotImplemented

Also available in: Unified diff