package nl.tudelft.ewi.dea.jaxrs.html;

import java.net.URI;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import nl.tudelft.ewi.dea.BuildInfo;
import nl.tudelft.ewi.dea.jaxrs.html.utils.Renderer;
import nl.tudelft.ewi.dea.security.SecurityProvider;

import com.google.inject.persist.Transactional;
import com.google.inject.servlet.RequestScoped;

@RequestScoped
@Path("login")
@Produces(MediaType.TEXT_HTML)
public class LoginPage {

	private final Renderer renderer;
	private final BuildInfo buildInfo;
	private final SecurityProvider securityProvider;

	@Inject
	public LoginPage(SecurityProvider securityProvider,
			Renderer renderer, BuildInfo buildInfo) {

		this.securityProvider = securityProvider;
		this.renderer = renderer;
		this.buildInfo = buildInfo;
	}

	@GET
	@Transactional
	public Response servePage() {
		if (securityProvider.getSubject().isAuthenticated()) {
			return Response.seeOther(URI.create("/dashboard")).build();
		}

		return Response.ok(renderer
				.setValue("buildInfo", buildInfo)
				.render("login.tpl")).build();
	}
}

package nl.tudelft.ewi.dea.jaxrs.html;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import nl.tudelft.ewi.dea.BuildInfo;
import nl.tudelft.ewi.dea.jaxrs.html.utils.Renderer;

import com.google.inject.persist.Transactional;
import com.google.inject.servlet.RequestScoped;

@RequestScoped
@Path("login")
@Produces(MediaType.TEXT_HTML)
public class LoginPage {

	private final Renderer renderer;
	private final BuildInfo buildInfo;

	@Inject
	public LoginPage(Renderer renderer, BuildInfo buildInfo) {
		this.renderer = renderer;
		this.buildInfo = buildInfo;
	}

	@GET
	@Transactional
	public String servePage() {
		return renderer
				.setValue("buildInfo", buildInfo)
				.render("login.tpl");
	}

}

--- 
+++ 
@@ -1,13 +1,17 @@
 package nl.tudelft.ewi.dea.jaxrs.html;
+
+import java.net.URI;
 
 import javax.inject.Inject;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 
 import nl.tudelft.ewi.dea.BuildInfo;
 import nl.tudelft.ewi.dea.jaxrs.html.utils.Renderer;
+import nl.tudelft.ewi.dea.security.SecurityProvider;
 
 import com.google.inject.persist.Transactional;
 import com.google.inject.servlet.RequestScoped;
@@ -19,19 +23,26 @@
 
 	private final Renderer renderer;
 	private final BuildInfo buildInfo;
+	private final SecurityProvider securityProvider;
 
 	@Inject
-	public LoginPage(Renderer renderer, BuildInfo buildInfo) {
+	public LoginPage(SecurityProvider securityProvider,
+			Renderer renderer, BuildInfo buildInfo) {
+
+		this.securityProvider = securityProvider;
 		this.renderer = renderer;
 		this.buildInfo = buildInfo;
 	}
 
 	@GET
 	@Transactional
-	public String servePage() {
-		return renderer
+	public Response servePage() {
+		if (securityProvider.getSubject().isAuthenticated()) {
+			return Response.seeOther(URI.create("/dashboard")).build();
+		}
+
+		return Response.ok(renderer
 				.setValue("buildInfo", buildInfo)
-				.render("login.tpl");
+				.render("login.tpl")).build();
 	}
-
 }
Fix issue-45: When already logged in, the login page should redirect to the dashboard.
