comparison src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java @ 57:4efb21cf0ce0

new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
author casties
date Tue, 20 Nov 2012 17:56:35 +0100
parents a52c597075dc
children f5c0e6df7e88
comparison
equal deleted inserted replaced
56:30c2e7d4eaf9 57:4efb21cf0ce0
130 public boolean isAuthenticated(Representation entity) { 130 public boolean isAuthenticated(Representation entity) {
131 return (checkAuthToken(entity) != null); 131 return (checkAuthToken(entity) != null);
132 } 132 }
133 133
134 /** 134 /**
135 * checks Annotator Auth plugin authentication information from headers. 135 * Checks Annotator Auth plugin authentication information from headers.
136 * returns userId if successful. 136 * Returns userId if successful. Returns "anonymous" in non-authorization mode.
137 * 137 *
138 * @param entity 138 * @param entity
139 * @return 139 * @return
140 */ 140 */
141 public String checkAuthToken(Representation entity) { 141 public String checkAuthToken(Representation entity) {
142 Form requestHeaders = (Form) getRequest().getAttributes().get("org.restlet.http.headers"); 142 Form requestHeaders = (Form) getRequest().getAttributes().get("org.restlet.http.headers");
143 String authToken = requestHeaders.getFirstValue("x-annotator-auth-token", true); 143 String authToken = requestHeaders.getFirstValue("x-annotator-auth-token", true);
144 if (authToken == null) return null; 144 if (authToken == null) {
145 if (!((BaseRestlet) getApplication()).isAuthorizationMode()) {
146 return "anonymous";
147 }
148 return null;
149 }
145 // decode token first to get consumer key 150 // decode token first to get consumer key
146 JsonToken token = new JsonTokenParser(null, null).deserialize(authToken); 151 JsonToken token = new JsonTokenParser(null, null).deserialize(authToken);
147 String userId = token.getParamAsPrimitive("userId").getAsString(); 152 String userId = token.getParamAsPrimitive("userId").getAsString();
148 String consumerKey = token.getParamAsPrimitive("consumerKey").getAsString(); 153 String consumerKey = token.getParamAsPrimitive("consumerKey").getAsString();
149 // get stored consumer secret for key 154 // get stored consumer secret for key