示例#1
0
 /** {@inheritDoc} */
 @Override
 public Response handleRequest(FreenetRequest request, Response response) throws IOException {
   if (webInterface.getCore().getPreferences().isRequireFullAccess()
       && !request.getToadletContext().isAllowedFullAccess()) {
     return response
         .setStatusCode(403)
         .setStatusText("Forbidden")
         .setContentType("application/json")
         .write(objectMapper.writeValueAsString(new JsonErrorReturnObject("auth-required")));
   }
   if (needsFormPassword()) {
     String formPassword = request.getHttpRequest().getParam("formPassword");
     if (!webInterface.getFormPassword().equals(formPassword)) {
       return response
           .setStatusCode(403)
           .setStatusText("Forbidden")
           .setContentType("application/json")
           .write(objectMapper.writeValueAsString(new JsonErrorReturnObject("auth-required")));
     }
   }
   if (requiresLogin()) {
     if (getCurrentSone(request.getToadletContext(), false) == null) {
       return response
           .setStatusCode(403)
           .setStatusText("Forbidden")
           .setContentType("application/json")
           .write(objectMapper.writeValueAsString(new JsonErrorReturnObject("auth-required")));
     }
   }
   try {
     JsonReturnObject jsonObject = createJsonObject(request);
     return response
         .setStatusCode(200)
         .setStatusText("OK")
         .setContentType("application/json")
         .write(objectMapper.writeValueAsString(jsonObject));
   } catch (Exception e1) {
     logger.log(Level.WARNING, "Error executing JSON page!", e1);
     return response
         .setStatusCode(500)
         .setStatusText(e1.getMessage())
         .setContentType("text/plain")
         .write(dumpStackTrace(e1));
   }
 }
示例#2
0
 /**
  * Returns the current session, creating a new session if there is no current session and {@code
  * create} is {@code true}.
  *
  * @param toadletContenxt The toadlet context
  * @param create {@code true} to create a new session if there is no current session, {@code
  *     false} otherwise
  * @return The current session, or {@code null} if there is no current session
  */
 protected Session getCurrentSession(ToadletContext toadletContenxt, boolean create) {
   return webInterface.getCurrentSession(toadletContenxt, create);
 }
示例#3
0
 /**
  * Returns the current session, creating a new session if there is no current session.
  *
  * @param toadletContenxt The toadlet context
  * @return The current session, or {@code null} if there is no current session
  */
 protected Session getCurrentSession(ToadletContext toadletContenxt) {
   return webInterface.getCurrentSession(toadletContenxt);
 }
示例#4
0
 /**
  * Returns the currently logged in Sone.
  *
  * @param toadletContext The toadlet context
  * @param create {@code true} to create a new session if no session exists, {@code false} to not
  *     create a new session
  * @return The currently logged in Sone, or {@code null} if no Sone is currently logged in
  */
 protected Sone getCurrentSone(ToadletContext toadletContext, boolean create) {
   return webInterface.getCurrentSone(toadletContext, create);
 }
示例#5
0
 /**
  * Returns the currently logged in Sone.
  *
  * @param toadletContext The toadlet context
  * @return The currently logged in Sone, or {@code null} if no Sone is currently logged in
  */
 protected Sone getCurrentSone(ToadletContext toadletContext) {
   return webInterface.getCurrentSone(toadletContext);
 }