/**
  * Store the authentication information to the session.
  *
  * @param authInfo
  * @param user
  */
 protected void storeToSession(final AuthInfo authInfo, final User user) {
   if (logger.isDebugEnabled()) {
     logger.debug("storing to session: " + authInfo);
   }
   ContextUtils.setSessionAttribute(AUTH_INFO_ATTRIBUTE, authInfo);
   ContextUtils.setSessionAttribute(USER_ATTRIBUTE, user);
 }
Esempio n. 2
0
 /**
  * @see org.esupportail.commons.web.component.UIAbstractPaginatorStyle#makeDivPages(
  *     javax.faces.application.Application)
  */
 @SuppressWarnings("unchecked")
 @Override
 protected Div makeDivPages(final Application a) {
   if (logger.isDebugEnabled()) {
     logger.debug("entering makeDivPagination(" + a + ")");
   }
   Div divPages = (Div) a.createComponent(Div.COMPONENT_TYPE);
   divPages.setParent(this);
   divPages.setStyleClass(NAVIGATION_BLOCK);
   // if there are more than one page on display pagination
   if (getPaginator().getFirstPageNumber() != getPaginator().getLastPageNumber()) {
     HtmlTag ul1 = (HtmlTag) a.createComponent(HtmlTag.COMPONENT_TYPE);
     ul1.setValue(HTML.UL_ELEM);
     ul1.setParent(divPages);
     // PREVIOUS BUTTON
     if (getPaginator().getCurrentPage() != getPaginator().getFirstPageNumber()) {
       ul1.getChildren()
           .add(
               makeLiGroup(
                   a,
                   getStringsVar() + "['" + PREVIOUS_BUTTON_I18N_KEY + "']",
                   null,
                   true,
                   PaginatorUtils.GOTO_PREVIOUS,
                   null,
                   null));
     }
     // BODY of Paginator
     divPages = makePages(divPages, getPaginator(), ul1, a);
   }
   return divPages;
 }
 @Override
 public String restart() {
   Map<String, Resettable> resettables = BeanUtils.getBeansOfClass(Resettable.class);
   for (String name : resettables.keySet()) {
     if (logger.isDebugEnabled()) {
       logger.debug("trying to reset bean [" + name + "]...");
     }
     Resettable bean = resettables.get(name);
     if (bean == null) {
       throw new ConfigException(
           "bean [" + name + "] is null, " + "application can not be restarted.");
     }
     bean.reset();
     if (logger.isDebugEnabled()) {
       logger.debug("bean [" + name + "] was reset.");
     }
   }
   if (!isPortletMode()) {
     // it is always this case !
     ExceptionUtils.unmarkExceptionCaught();
     ((HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false))
         .invalidate();
   }
   return "applicationRestarted";
 }
 /** @return the current user's locale. */
 @Override
 public Locale getCurrentUserLocale() {
   if (logger.isDebugEnabled()) {
     logger.debug(this.getClass().getName() + ".getCurrentUserLocale()");
   }
   User currentUser = null;
   try {
     currentUser = getCurrentUser();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   if (currentUser == null) {
     if (logger.isDebugEnabled()) {
       logger.debug("no current user, return null");
     }
     return null;
   }
   String lang = currentUser.getLanguage();
   if (lang == null) {
     if (logger.isDebugEnabled()) {
       logger.debug("language not set for user '" + currentUser.getLogin() + "', return null");
     }
     return null;
   }
   Locale locale = new Locale(lang);
   if (logger.isDebugEnabled()) {
     logger.debug("language for user '" + currentUser.getLogin() + "' is '" + locale + "'");
   }
   return locale;
 }
 /** @return true if portlet mode. */
 private boolean isPortletMode() {
   if (logger.isDebugEnabled()) {
     logger.debug("Mode detected in Application");
   }
   FacesContext fc = FacesContext.getCurrentInstance();
   portletMode = ExternalContextUtils.isPortlet(fc.getExternalContext());
   if (logger.isDebugEnabled()) {
     if (portletMode) {
       logger.debug("Portlet mode detected");
     } else {
       logger.debug("Servlet mode detected");
     }
   }
   return portletMode;
 }
 /** @see org.esupportail.commons.services.smtp.AbstractSmtpService#test() */
 @Override
 public void test() {
   if (testAddress == null) {
     logger.error(
         "can not test the SMTP connection when property testAddress is not set, "
             + "edit configuration file smtp.xml.");
     return;
   }
   sendDoNotIntercept(
       testAddress, "SMTP test", "<p>This is a <b>test</b>.</p>", "This is a test.");
 }
 /** @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */
 public void afterPropertiesSet() {
   if (CollectionUtils.isEmpty(servers)) {
     logger.info(
         getClass()
             + ": no SMTP server set, '"
             + SmtpServer.DEFAULT_HOST
             + ":"
             + SmtpServer.DEFAULT_PORT
             + "' will be used");
     SmtpServer server = new SmtpServer();
     server.setDefaultHost();
     server.setDefaultPort();
     if (this.servers == null) {
       this.servers = new Vector<SmtpServer>();
     }
     this.servers.add(server);
   }
   Assert.notNull(
       this.fromAddress,
       "property fromAddress of class " + this.getClass().getName() + " can not be null");
   if (!StringUtils.hasText(charset)) {
     logger.info(getClass() + ": no encoding charset set, '" + DEFAULT_CHARSET + "' will be used");
     setDefaultCharset();
   }
   if (testAddress == null) {
     logger.info(getClass() + ": no testAddress attribute set, target ldap-smtp will not work.");
   }
   Assert.notNull(
       this.interceptAll,
       "property interceptAll of class " + this.getClass().getName() + " can not be null");
   if (interceptAll) {
     Assert.notNull(
         this.interceptAddress,
         "property interceptAddress of class "
             + this.getClass().getName()
             + " can not be null when interceptAll is true");
   }
   if (notInterceptedAddresses == null) {
     notInterceptedAddresses = new ArrayList<String>();
   }
 }
 /**
  * @param targetService
  * @return a proxy ticket.
  * @throws CasException
  */
 private String retrieveProxyTicket(final String targetService) throws CasException {
   if (logger.isDebugEnabled()) {
     logger.debug("retrieving a proxy ticket for service [" + targetService + "]...");
     logger.debug("pgtIou=[" + validator.getPgtIou() + "]");
   }
   int tryNumber = 0;
   Exception exception = null;
   while (tryNumber < (1 + retries)) {
     tryNumber++;
     if (logger.isDebugEnabled()) {
       logger.debug("try #" + tryNumber);
     }
     try {
       String url = URLEncoder.encode(targetService, "UTF-8");
       return ProxyTicketReceptor.getProxyTicket(validator.getPgtIou(), url);
     } catch (IOException e) {
       if (logger.isDebugEnabled()) {
         logger.debug(
             "could not retrieve a proxy ticket for service ["
                 + targetService
                 + "] (try #"
                 + tryNumber
                 + ")",
             e);
       }
       if (tryNumber == retries) {
         try {
           Thread.sleep(sleep * THOUSAND);
         } catch (InterruptedException ie) {
           exception = ie;
         }
       } else {
         exception = e;
       }
     }
   }
   CasException ce =
       new CasException(
           "could not get a proxy ticket for service [" + targetService + "]", exception);
   if (logger.isDebugEnabled()) {
     logger.debug(ce);
   }
   throw ce;
 }
 /** @see org.esupportail.pstage.services.authentication.Authenticator#getUser() */
 public User getUser() {
   AuthInfo authInfo = (AuthInfo) ContextUtils.getSessionAttribute(AUTH_INFO_ATTRIBUTE);
   if (authInfo != null) {
     User user = (User) ContextUtils.getSessionAttribute(USER_ATTRIBUTE);
     if (logger.isDebugEnabled()) {
       logger.debug("found auth info in session: " + user);
     }
     return user;
   }
   if (logger.isDebugEnabled()) {
     logger.debug("no auth info found in session");
   }
   authInfo = authenticationService.getAuthInfo();
   if (authInfo == null) {
     return null;
   }
   if (AuthUtils.CAS.equals(authInfo.getType())) {
     User user = getDomainService().getUser(authInfo.getId());
     storeToSession(authInfo, user);
     return user;
   }
   return null;
 }
  public String getAsString(
      @SuppressWarnings("unused") final FacesContext context,
      @SuppressWarnings("unused") final UIComponent component,
      final Object value) {

    String text = value.toString();
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(text);
    while (m.find())
      text =
          text.replace(
              m.group(1),
              account.getAttribute(m.group(2)) != null ? account.getAttribute(m.group(2)) : none);

    logger.debug("Converted string : " + text);

    return text;
  }
 /** @see org.esupportail.commons.services.cas.CasService#validate() */
 public void validate() throws CasException {
   String serviceTicket = getServiceTicket();
   validator = new ProxyTicketValidator();
   validator.setCasValidateUrl(casValidateUrl);
   validator.setService(service);
   validator.setServiceTicket(serviceTicket);
   validator.setProxyCallbackUrl(proxyCallbackUrl);
   if (logger.isDebugEnabled()) {
     logger.debug("validating ticket [" + serviceTicket + "]...");
     logger.debug("casValidateUrl=[" + validator.getCasValidateUrl() + "]");
     logger.debug("service=[" + service + "]");
     logger.debug("proxyCallbackUrl=[" + validator.getProxyCallbackUrl() + "]");
   }
   int tryNumber = 0;
   Exception validateException = null;
   while (tryNumber < (1 + retries)) {
     tryNumber++;
     if (logger.isDebugEnabled()) {
       logger.debug("try #" + tryNumber);
     }
     try {
       validator.validate();
       if (logger.isDebugEnabled()) {
         logger.debug("response = [" + validator.getResponse() + "]");
         logger.debug("errorCode = [" + validator.getErrorCode() + "]");
         logger.debug("errorMessage = [" + validator.getErrorMessage() + "]");
       }
       if (validator.isAuthenticationSuccesful()) {
         return;
       }
       // no error, but authentication failed
       throw new CasException(
           "authentication failed for ticket ["
               + serviceTicket
               + "] ("
               + validator.getErrorCode()
               + ": "
               + validator.getErrorMessage()
               + ")");
     } catch (IOException e) {
       if (logger.isDebugEnabled()) {
         logger.debug(
             "could not validate ticket [" + serviceTicket + "] (try #" + tryNumber + ")", e);
       }
       if (tryNumber == retries) {
         try {
           Thread.sleep(sleep * THOUSAND);
         } catch (InterruptedException ie) {
           validateException = ie;
         }
       } else {
         validateException = e;
       }
     } catch (SAXException e) {
       validateException = e;
     } catch (ParserConfigurationException e) {
       validateException = e;
     }
   }
   CasException ce =
       new CasException("could not validate ticket [" + serviceTicket + "]", validateException);
   if (logger.isDebugEnabled()) {
     logger.debug(ce);
   }
   throw ce;
 }