package controllers;

import java.util.ArrayList;

import com.feth.play.module.pa.PlayAuthenticate;
import com.feth.play.module.pa.user.AuthUser;

import models.User;

import play.Logger;
import play.mvc.Http.Context;
import play.mvc.Result;
import play.mvc.Security;

public class Secured extends Security.Authenticator {

	@Override
	public String getUsername(final Context ctx) {
        Logger.debug("Secured::getUsername " + ctx);
		final AuthUser u = PlayAuthenticate.getUser(ctx.session());

		if (u != null) {
            User the_user = User.findByAuthUserIdentity(u);
            if (the_user == null) {
                return null;
            }

            return u.getId();
        }

        return null;
	}

	@Override
	public Result onUnauthorized(final Context ctx) {
		return redirect(com.feth.play.module.pa.controllers.routes.Authenticate.logout());
	}
}
@@ -684,32 +684,81 @@
 d();%0A        %7D%0A%0A
+        PlayAuthenticate.storeOriginalUrl(ctx);%0A%0A
         return n
@@ -852,68 +852,37 @@
 t(co
-m.feth.play.module.pa.controllers.routes.Authenticate.logout
+ntrollers.routes.Public.index
 ());

Store original URL before logging in so that user is properly redirected on login.