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.

  (fabu)

Number of messages  28
Registration date
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!

  (fabu)

Number of messages  28
Registration date
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  262
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