Project

General

Profile

« Previous | Next » 

Revision 9173

add whoami endpoint to make debugging authn/authz easier as we use additional mechanisms for proving identity.

View differences:

src/edu/ucsb/nceas/metacat/restservice/v2/MNResourceHandler.java
66 66
import org.dataone.service.types.v1.ObjectList;
67 67
import org.dataone.service.types.v1.Permission;
68 68
import org.dataone.service.types.v1.Person;
69
import org.dataone.service.types.v1.Subject;
70
import org.dataone.service.types.v1.SubjectInfo;
69 71
import org.dataone.service.types.v1_1.QueryEngineDescription;
70 72
import org.dataone.service.types.v1_1.QueryEngineList;
71 73
import org.dataone.service.types.v2.Log;
......
141 143
    protected static final String RESOURCE_PUBLISH = "publish";
142 144
    protected static final String RESOURCE_PACKAGE = "package";
143 145
    protected static final String RESOURCE_TOKEN = "token";
146
    protected static final String RESOURCE_WHOAMI = "whoami";
144 147

  
145 148

  
146 149

  
......
229 232
                        status = true;
230 233
                    }
231 234
                    
235
                } else if (resource.startsWith(RESOURCE_WHOAMI)) {
236
                    logMetacat.debug("Using resource 'whoami'");
237
                    // get
238
                    if (httpVerb == GET) {
239
                    	// after the command
240
                        whoami();
241
                        status = true;
242
                    }
243
                    
232 244
                } else if (resource.startsWith(RESOURCE_IS_AUTHORIZED)) {
233 245
                    if (httpVerb == GET) {
234 246
                    	// after the command
......
793 805
		
794 806
    }
795 807
    
808
    private void whoami() throws Exception {
809
		
810
		if (this.session != null) {
811
			Subject subject = this.session.getSubject();
812
			SubjectInfo subjectInfo = null;
813
			try {
814
				subjectInfo = this.session.getSubjectInfo();
815
			} catch (Exception e) {
816
				logMetacat.warn(e.getMessage(), e);
817
			}
818
			
819
			response.setStatus(200);
820
			response.setContentType("text/plain");
821
	        OutputStream out = response.getOutputStream();
822
	        
823
	        if (subjectInfo != null) {
824
		        TypeMarshaller.marshalTypeToOutputStream(subjectInfo, out);
825
	        } else {
826
		        TypeMarshaller.marshalTypeToOutputStream(subject, out);
827
	        }
828
	        
829
	        out.close();
830
		} else {
831
			response.setStatus(401);
832
			response.setContentType("text/plain");
833
			OutputStream out = response.getOutputStream();
834
	        out.write("No session information found".getBytes(MetaCatServlet.DEFAULT_ENCODING));
835
	        out.close();
836
		}
837
		
838
    }
839
    
796 840
    /**
797 841
     * Processes failed synchronization message
798 842
     * @throws NotImplemented

Also available in: Unified diff