Commits

Stefan Saasen  committed 1533997

Redirect to login unless the user is authenticated

  • Participants
  • Parent commits 4712d50

Comments (0)

Files changed (2)

File src/main/java/com/atlassian/plugins/polyglot/jrubyexample/servlet/SinatraAdapterServlet.java

 import com.atlassian.plugin.webresource.WebResourceManager;
 import com.atlassian.plugins.polyglot.jrubyexample.bridge.ScriptingContainerProvider;
 import org.apache.commons.lang.StringUtils;
-import org.jruby.embed.EmbedEvalUnit;
-import org.jruby.embed.PathType;
-import org.jruby.embed.ScriptingContainer;
+import org.jruby.embed.*;
 import org.jruby.exceptions.RaiseException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import java.io.Writer;
 import java.security.Principal;
 import java.util.Collections;
+import java.util.Map;
 
 public class SinatraAdapterServlet extends HttpServlet {
 
                     "/jruby_integration/handle_request.rb");
 
             String body = container.callMethod(rackResponse, "getBody", String.class);
+            Integer status = container.callMethod(rackResponse, "getStatus", Integer.class);
+            Map<String,Object> headers = container.callMethod(rackResponse, "getHeaders", Map.class);
+            for(Map.Entry<String,Object> e : headers.entrySet()) {
+                response.setHeader(e.getKey(), e.getValue().toString());
+            }
+            response.setStatus(status);
             response.setContentLength(body.getBytes().length);
             w.write(body);
             container.clear();
 
         } catch (RaiseException re) {
             response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, re.getLocalizedMessage());
+        } catch (EvalFailedException efe) {
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, efe.getLocalizedMessage());
+        } catch (InvokeFailedException ife) {
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ife.getLocalizedMessage());
         }
     }
 

File src/main/ruby/app/confluence_sinatra_app.rb

 
   before do
     @current_user = current_user
+    redirect "#{$context_path}/login.action" unless @current_user
   end
 
   not_found { erb :not_found }