Jahia Dev Forum > Get current site...

0 (0 Good)
0 (0 Bad)

Get current site from AutoRegisteredBaseAuthValve

by  fabu »  2013/11/13 09:46

Hello,
 
I try to retrieve current site key from inherited class of AutoRegisteredBaseAuthValve.java.
 
Is there a way to add a custom valve and get current site key?
 
I looked for request parameters and attributes, session or cookies but I did not find any solutions!
 
Any idea?
 
Thanks in advance,
Best regards.
  • Get current site from AutoRegisteredBaseAuthValve
    2013/11/13 09:47

    fabu <div> Hello,</div> <div> &nbsp;</div> <div> I try to retrieve current site key from inherited class of AutoRegisteredBaseAuthValve.java.</div> <div> &nbsp;</div> <div> Is there a way to add a custom valve and get current site key?</div> <div> &nbsp;</div> <div> I looked for request parameters and attributes, session or cookies but I did not find any solutions!</div> <div> &nbsp;</div> <div> Any idea?</div> <div> &nbsp;</div> <div> Thanks in advance,</div> <div> Best regards.</div>

  • Number of messages  28
    Registration date Nov 13, 2013
    0 (0 Good)
    0 (0 Bad)

    Re : Get current site from AutoRegisteredBaseAuthValve

    by  fabu »  2013/11/13 15:42

    I solved the problem by doing this piece of code:

    /**
    * Try to identify current jahia site from URL
    * @param request
    * @return Current Jahia Site or null
    * @throws JahiaException
    */
    private JahiaSite getCurrentSite(HttpServletRequest request) throws JahiaException {
     
    JahiaSite currentJahiaSite = null;
     
    // Check first if URI contains a known jahia virtual site key
    Iterator<JahiaSite> sites = jahiaSitesService.getSites();
    while (sites.hasNext()) {
      JahiaSite jahiaSite = sites.next();
      String jahiaSiteKey = jahiaSite.getSiteKey();
      if (request.getRequestURI().matches("(.*)\\/" + jahiaSiteKey + "\\/(.*)")) {
        currentJahiaSite = jahiaSite;
        logger.debug("Jahia site has been found by key. " + jahiaSite);
        break;
      }
    }
     
    // Reset iterator to check if server name is known
    sites = jahiaSitesService.getSites();
    if (currentJahiaSite == null) {
      while (sites.hasNext()) {
        JahiaSite jahiaSite = sites.next();
        String jahiaSiteServerName = jahiaSite.getServerName();
        if (request.getServerName().equals(jahiaSiteServerName)) {
          currentJahiaSite = jahiaSite;
          logger.debug("Jahia site has been found by server name. " + jahiaSite);
          break;
        }
      }
    }
     
    return currentJahiaSite;
    }

    If i doing something wrong, please let me know!

  • Re : Get current site from AutoRegisteredBaseAuthValve
    2013/11/14 22:07

    fabu <p> I solved the problem by doing this piece of code:</p> <blockquote> <div> /**</div> <div> * Try to identify current jahia site from URL</div> <div> *&nbsp;</div> <div> * @param request</div> <div> * @return Current Jahia Site or null</div> <div> * @throws JahiaException</div> <div> */</div> <div> private JahiaSite getCurrentSite(HttpServletRequest request) throws JahiaException {</div> <div> &nbsp;</div> <div> JahiaSite currentJahiaSite = null;</div> <div> &nbsp;</div> <div> // Check first if URI contains a known jahia virtual site key</div> <div> Iterator&lt;JahiaSite&gt; sites = jahiaSitesService.getSites();</div> <div> while (sites.hasNext()) {</div> <div> &nbsp; JahiaSite jahiaSite = sites.next();</div> <div> &nbsp; String jahiaSiteKey = jahiaSite.getSiteKey();</div> <div> &nbsp; if (request.getRequestURI().matches(&quot;(.*)\\/&quot; + jahiaSiteKey + &quot;\\/(.*)&quot;)) {</div> <div> &nbsp; &nbsp; currentJahiaSite = jahiaSite;</div> <div> &nbsp; &nbsp; logger.debug(&quot;Jahia site has been found by key. &quot; + jahiaSite);</div> <div> &nbsp; &nbsp; break;</div> <div> &nbsp; }</div> <div> }</div> <div> &nbsp;</div> <div> // Reset iterator to check if server name is known</div> <div> sites = jahiaSitesService.getSites();</div> <div> if (currentJahiaSite == null) {</div> <div> &nbsp; while (sites.hasNext()) {</div> <div> &nbsp; &nbsp; JahiaSite jahiaSite = sites.next();</div> <div> &nbsp; &nbsp; String jahiaSiteServerName = jahiaSite.getServerName();</div> <div> &nbsp; &nbsp; if (request.getServerName().equals(jahiaSiteServerName)) {</div> <div> &nbsp; &nbsp; &nbsp; currentJahiaSite = jahiaSite;</div> <div> &nbsp; &nbsp; &nbsp; logger.debug(&quot;Jahia site has been found by server name. &quot; + jahiaSite);</div> <div> &nbsp; &nbsp; &nbsp; break;</div> <div> &nbsp; &nbsp; }</div> <div> &nbsp; }</div> <div> }</div> <div> &nbsp;</div> <div> return currentJahiaSite;</div> <div> }</div> </blockquote> <p> If i doing something wrong, please let me know!</p>

  • Number of messages  28
    Registration date Nov 13, 2013
    0 (0 Good)
    0 (0 Bad)

    Re : Re : Get current site from AutoRegisteredBaseAuthValve

    by  faissah »  2013/11/15 22:18

    We're glad you solved your issue!

    Fabrice  (faissah)

    Number of messages  264
    Registration date
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page