Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

b.o.d.j.u.RequestUtils - Error getting subject: Futures timed out after [2000 milliseconds] #8

Closed
johdah opened this issue Apr 16, 2015 · 5 comments
Assignees

Comments

@johdah
Copy link

johdah commented Apr 16, 2015

I get this error all the time now.

I guess that it's caused by my getSubject method, but I have timed "Application.getLoggedOnUser()" and it takes 14-27ms so it couldn't be that I guess. So what could cause this?

2015-04-16 15:00:52,716 - [error] b.o.d.j.u.RequestUtils - Error getting subject: Futures timed out after [2000 milliseconds]
java.util.concurrent.TimeoutException: Futures timed out after [2000 milliseconds]
    at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219) ~[org.scala-lang.scala-library-2.11.6.jar:na]
    at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:223) ~[org.scala-lang.scala-library-2.11.6.jar:na]
    at scala.concurrent.Await$$anonfun$result$1.apply(package.scala:190) ~[org.scala-lang.scala-library-2.11.6.jar:na]
    at akka.dispatch.MonitorableThreadFactory$AkkaForkJoinWorkerThread$$anon$3.block(ThreadPoolBuilder.scala:169) ~[com.typesafe.akka.akka-actor_2.11-2.3.4.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:3640) [org.scala-lang.scala-library-2.11.6.jar:na]

My getSubject method looks like this.

public F.Promise<Subject> getSubject(Http.Context context) {
        return F.Promise.promise(new F.Function0<Subject>()
        {
            @Override
            public Subject apply() throws Throwable {
                return Application.getLoggedOnUser();
            }
        });
    }
@schaloner
Copy link
Collaborator

This is the reason I changed the signature of getSubject in 2.3.3 to return a Subject and not a promise. You're using 2.3.2, I guess?

@schaloner schaloner self-assigned this Apr 17, 2015
@johdah
Copy link
Author

johdah commented Apr 17, 2015

Yes, I will update. But I got the following error when rewriting the getSubject method.

[error] /home/johdah/Development/svn/MobitecAccess/branches/Johan/Hibernate/app/auth/MyDynamicResourceHandler.java:188: non-static method checkPatternEquality(be.objectify.deadbolt.core.models.Subject,java.lang.String) cannot be referenced from a static context
[error] DeadboltAnalyzer.checkPatternEquality

MyDynamicResourceHandler looks like this.

    public boolean isAllowed(final String name, final String meta, final DeadboltHandler deadboltHandler, final Http.Context ctx) {
        final DynamicResourceHandler handler = HANDLERS.get(name);

//      return deadboltHandler.getSubject(ctx).map(
//          new F.Function<Subject, Boolean>() {
//              @Override
//              public Boolean apply(Subject subject) throws Throwable {
        if(meta.isEmpty()) return true;
        Subject subject = deadboltHandler.getSubject(ctx);

        // Check if permission pattern applied as meta is allowed!
        if(!DeadboltAnalyzer.checkPatternEquality(subject, meta)) {
            Logger.debug(String.format("Access failed to %s", meta));
            return false;
        }

        boolean result = false;
        if (handler == null) {
            Logger.error("No handler available for " + name);
        } else {
            result = handler.isAllowed(name, meta, deadboltHandler, ctx);
        }
        return result;
//              }
//          }
//      ).get(1, TimeUnit.SECONDS);
    }

@schaloner
Copy link
Collaborator

DeadboltAnalyzer's methods are not static any more, because people were asking for DI support. You can declare a static DeadboltAnalyzer in your MyDynamicResourceHandler class and reference that instead.

@johdah
Copy link
Author

johdah commented Apr 17, 2015

Thanks! Then it will hopefully work without the errors now then.

@schaloner
Copy link
Collaborator

No further issues reported on this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants