Session attribute in a Condition – HttpConfigurationProvider

Splash Forums Rewrite Users Session attribute in a Condition – HttpConfigurationProvider

This topic contains 2 replies, has 3 voices, and was last updated by  Lincoln Baxter III 3 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19762

    rbento
    Participant

    Hello,

    I’m using the rewrite-servlet and rewrite-integration-faces extension modules and I”m trying to create a login filter.

    Is there a way to get or set session attributes inside a Condition?

    I’ve seen the login example using CDI, but I don’t use CDI in my application. Therefore I would like to check if the user is in session. Is that possible?

    Thanks a lot.

    #23477

    There is no existing condition in Rewrite that allows to check for an session attribute. But you can build one yourself very easily. If you implement your condition on top of of HttpCondition, you can get the request (and therefore also the session) from the HttpServletRewrite event. Something like this:

    .defineRule()
    .when(new HttpCondition() {
    @Override
    public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context) {
    HttpServletRequest request = event.getRequest();
    return request.getSession(true).getAttribute("something") != null;
    }
    })
    .perform(.... something ...)

    I hope this helps. :)

    #23478

    Christian beat me to it, but yes, that’s exactly what you would do!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Comments are closed.