Multi tenand app with rewrite

Splash Forums Rewrite Users Multi tenand app with rewrite

This topic contains 5 replies, has 2 voices, and was last updated by  Christian Kaltepoth 2 years, 6 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #25795

    Roland
    Participant

    I would like to write a rule that enables me to make my application multi tenand

    basically I would like to introduce a path variable “organization” as the first path segment and add it as parameter
    My first attempt is this:

    .addRule(Join.path(“/{organisation}/{path}?{params}”).to(“/{path}?organisation={organisation}&{params}”))

    1. It does not consider parameters at all
    2. It does not accept deeper paths with multiple /../../

    What must I do to “join” organisation as a Get paramenter for any possible url?

    Thank you!

    #25800

    Hey,

    A few things to note here:

    * you won’t need the params parameter at all, as query parameter are automatically preserved.
    * parameters are automatically turned into query parameters. So you don’t need organisaion in the to() part at all.
    * By default parameters only match a single path segment. But you can change the regular expression that is used for this.

    So you could try this one:

    .addRule(Join.path(“/{organisation}/{path}”).to(“/{path}”))
    .where("path").matches(".*")
    
    #25801

    Roland
    Participant

    Thank you Christian,
    It works.

    now I have a legacy code which redirects me to /WEB-INF/**

    I do not understand the fluid interface very well
    for example I try to

    .addRule().when(Path.matches("/WEB-INF/.*")).perform(Log.message(Level.INFO, "web-inf"))
    .addRule(Join.path("/{organisation}/{path}").to("/{path}"))
    			   .perform(Log.message(Level.INFO, "Forward to /{path}?organisation={organisation}"))
    			   .where("path").matches(".*")

    and it never hits the first rule

    how could I exclude everything that goes to WEB-INF from my multitenant join rule?

    #25802

    You could use this rule which will basically abort evaluating other rules if the path matches:

    .addRule()
    .when( Path.matches( "/WEB-INF/{whatever}" ) )
    .perform( Lifecycle.proceed() )
    .where( "whatever" ).matches( ".*" )
    

    Another option would be to modify the regular expression for the organisation parameter so that WEB-INF doesn’t match it any more.

    .addRule(Join.path("/{organisation}/{path}").to("/{path}"))
    .where("path").matches(".*")
    .where("organisation").matches("[a-z]+")
    
    #25803

    Roland
    Participant

    I came to this solution with Lifecycle.handled():

    .addRule()
    .when(Direction.isInbound().and(Response.isCommitted()))
    .perform(Lifecycle.abort())
     
    .addRule()
    .when(Direction.isInbound().and(Path.matches("/WEB-INF/{path}")))
    .perform(Log.message(Level.INFO, "{path}").and(Lifecycle.handled()))
    

    What exactly is the difference to Lifecycle.proceed() ?

    ro

    #25805

    Oh, sorry. Yeah, handled() is correct as this one prevents that further rules are evaluated. If you use proceed() other rules will be evaluated which will lead to the problems you described above. Sorry, I mixed them up. 🙂

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

You must be logged in to reply to this topic.

Comments are closed.