<commit_before>package security;

import models.User;
import play.libs.F;
import play.mvc.Http;
import play.mvc.SimpleResult;
import be.objectify.deadbolt.java.AbstractDeadboltHandler;
import be.objectify.deadbolt.java.DynamicResourceHandler;
import be.objectify.deadbolt.core.models.Subject;

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

public class MyDeadboltHandler extends AbstractDeadboltHandler
{
	@Override
	public F.Promise<SimpleResult> beforeAuthCheck(final Http.Context context)
	{
		if (PlayAuthenticate.isLoggedIn(context.session()))
		{
			// user is logged in
			return F.Promise.pure(null);
		}
		else
		{
			// user is not logged in

			// call this if you want to redirect your visitor to the page that
			// was requested before sending him to the login page
			// if you don't call this, the user will get redirected to the page
			// defined by your resolver
			final String originalUrl = PlayAuthenticate.storeOriginalUrl(context);

			context.flash().put("error",
					"You need to log in first, to view '" + originalUrl + "'");
            return F.Promise.promise(new F.Function0<SimpleResult>()
            {
                @Override
                public SimpleResult apply() throws Throwable
                {
                    return redirect(PlayAuthenticate.getResolver().login());
                }
            });
		}
	}

	@Override
	public Subject getSubject(final Http.Context context)
	{
		final AuthUserIdentity u = PlayAuthenticate.getUser(context);
		// Caching might be a good idea here
		return User.findByAuthUserIdentity(u);
	}

	@Override
	public DynamicResourceHandler getDynamicResourceHandler(final Http.Context context)
	{
		return null;
	}

	@Override
	public F.Promise<SimpleResult> onAuthFailure(final Http.Context context,
			                               final String content)
	{
		// if the user has a cookie with a valid user and the local user has
		// been deactivated/deleted in between, it is possible that this gets
		// shown. You might want to consider to sign the user out in this case.
        return F.Promise.promise(new F.Function0<SimpleResult>()
        {
            @Override
            public SimpleResult apply() throws Throwable
            {
                return forbidden("Forbidden");
            }
        });
	}
}<commit_msg>Updated to be compatible with newer Deadbolt version. Upgrade to Play 2.3 should be complete.<commit_after>package security;

import models.User;
import play.libs.F;
import play.mvc.Http;
import play.mvc.Result;
import be.objectify.deadbolt.java.AbstractDeadboltHandler;
import be.objectify.deadbolt.java.DynamicResourceHandler;
import be.objectify.deadbolt.core.models.Subject;

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

public class MyDeadboltHandler extends AbstractDeadboltHandler
{
	@Override
	public F.Promise<Result> beforeAuthCheck(final Http.Context context)
	{
		if (PlayAuthenticate.isLoggedIn(context.session()))
		{
			// user is logged in
			return F.Promise.pure(null);
		}
		else
		{
			// user is not logged in

			// call this if you want to redirect your visitor to the page that
			// was requested before sending him to the login page
			// if you don't call this, the user will get redirected to the page
			// defined by your resolver
			final String originalUrl = PlayAuthenticate.storeOriginalUrl(context);

			context.flash().put("error",
					"You need to log in first, to view '" + originalUrl + "'");
            return F.Promise.promise(new F.Function0<Result>()
            {
                @Override
                public Result apply() throws Throwable
                {
                    return redirect(PlayAuthenticate.getResolver().login());
                }
            });
		}
	}

	@Override
	public F.Promise<Subject> getSubject(final Http.Context context)
	{
		final AuthUserIdentity u = PlayAuthenticate.getUser(context);
		// Caching might be a good idea here
		return F.Promise.pure((Subject) User.findByAuthUserIdentity(u));
	}

	@Override
	public DynamicResourceHandler getDynamicResourceHandler(final Http.Context context)
	{
		return null;
	}

	@Override
	public F.Promise<Result> onAuthFailure(final Http.Context context,
			                               final String content)
	{
		// if the user has a cookie with a valid user and the local user has
		// been deactivated/deleted in between, it is possible that this gets
		// shown. You might want to consider to sign the user out in this case.
        return F.Promise.promise(new F.Function0<Result>()
        {
            @Override
            public Result apply() throws Throwable
            {
                return forbidden("Forbidden");
            }
        });
	}
}
{'fraction_non_alphanumeric': 0.08632496368541191, 'fraction_numerical': 0.0012450715916165179, 'mean_word_length': 2.7422360248447206, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7570333', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1310, 'n_words': 405}