Project

General

Profile

« Previous | Next » 

Revision 9706

merge to trunk from 2.6 branch: action=validatesession can handle Authorization token

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
840 840

  
841 841
				// handle session validate request
842 842
			} else if (action.equals("validatesession")) {
843
				Writer out = new OutputStreamWriter(response.getOutputStream(), DEFAULT_ENCODING);
844
				String idToValidate = null;
845
				String idsToValidate[] = params.get("sessionid");
846
				if (idsToValidate != null) {
847
					idToValidate = idsToValidate[0];
848
				} else {
849
					// use the sessionid from the cookie
843
				String token = request.getHeader("Authorization");
844
				
845
				// First check for a valid authentication token
846
				if ( token != null && ! token.equals("") ) {
847
					Writer out = new OutputStreamWriter(response.getOutputStream(), DEFAULT_ENCODING);
850 848
					SessionData sessionData = RequestUtil.getSessionData(request);
849
					
850
					response.setContentType("text/xml");
851
					out.write("<?xml version=\"1.0\"?>");
852
					out.write("<validateSession><status>");
853
					
854
					if ( sessionData != null ) {
855
						out.write("valid");
856
						
857
					} else {
858
						out.write("invalid");
859
						
860
					}
861
					out.write("</status>");
862
				    
851 863
					if (sessionData != null) {
852
						idToValidate = sessionData.getId();
864
						out.write("<userInformation>");
865
						out.write("<name>");
866
						out.write(sessionData.getUserName());
867
						out.write("</name>");
868
						out.write("<fullName>");
869
						out.write(sessionData.getName());
870
						out.write("</fullName>");
871
						String[] groups = sessionData.getGroupNames();
872
						if ( groups != null ) {
873
							for(String groupName : groups) {
874
							  out.write("<group>");
875
							  out.write(groupName);
876
							  out.write("</group>");
877
							}
878
						}
879
						out.write("</userInformation>");
853 880
					}
881

  
882
					out.write("<sessionId>" + sessionId + "</sessionId></validateSession>");				
883
					out.close();
884
					
885
				} else {
886
					// With no token, validate the sessionid
887
					Writer out = new OutputStreamWriter(response.getOutputStream(), DEFAULT_ENCODING);
888
					String idToValidate = null;
889
					String idsToValidate[] = params.get("sessionid");
890
					if (idsToValidate != null) {
891
						idToValidate = idsToValidate[0];
892
						
893
					} else {
894
						// use the sessionid from the cookie
895
						SessionData sessionData = RequestUtil.getSessionData(request);
896
						if (sessionData != null) {
897
							idToValidate = sessionData.getId();
898
							
899
						}
900
					}
901
					SessionService.getInstance().validateSession(out, response, idToValidate);
902
					out.close();
854 903
				}
855
				SessionService.getInstance().validateSession(out, response, idToValidate);
856
				out.close();
857 904

  
858 905
				// aware of session expiration on every request
859 906
			} else {
......
868 915

  
869 916
				logMetacat.info("MetaCatServlet.handleGetOrPost - The user is : " + userName);
870 917
			}
918
			
871 919
			// Now that we know the session is valid, we can delegate the
872 920
			// request to a particular action handler
873 921
			if (action.equals("query")) {

Also available in: Unified diff