Пример #1
0
  /**
   * Checks for user authentication using some SSO implementation
   *
   * @param userSession UserSession
   */
  protected void checkSSO(UserSession userSession) {

    LOG.trace("checkSSO");
    try {
      SSO sso =
          (SSO) Class.forName(SystemGlobals.getValue(ConfigKeys.SSO_IMPLEMENTATION)).newInstance();
      String username = sso.authenticateUser(JForumExecutionContext.getRequest());

      if (username == null || username.trim().equals("")) {
        userSession.makeAnonymous();
      } else {
        SSOUtils utils = new SSOUtils();

        if (!utils.userExists(username)) {
          SessionContext session = JForumExecutionContext.getRequest().getSessionContext();

          String email =
              (String) session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_EMAIL_ATTRIBUTE));
          String password =
              (String)
                  session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_PASSWORD_ATTRIBUTE));

          if (email == null) {
            email = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_EMAIL);
          }

          if (password == null) {
            password = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_PASSWORD);
          }

          utils.register(password, email);
        }

        this.configureUserSession(userSession, utils.getUser());
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new ForumException("Error while executing SSO actions: " + e);
    }
  }
Пример #2
0
  private void setJforumScreenname(User user) {
    SSOUtils ssoutils = new SSOUtils();

    if (!ssoutils.userExists(user.getUsername())) {
      net.jforum.entities.User jforumuser = new net.jforum.entities.User();

      jforumuser.setUsername(user.getUsername());
      jforumuser.setPassword("sso");
      String email = null == user.getEmail() ? "" : user.getEmail();
      jforumuser.setEmail(email);
      jforumuser.setFrom(user.getScreenname());
      jforumuser.setActive(1);

      UserDAO dao = DataAccessDriver.getInstance().newUserDAO();

      dao.addNew(jforumuser);

      net.jforum.entities.User addedjforumuser = dao.selectByName(user.getUsername());

      addedjforumuser.setFrom(user.getScreenname());

      dao.update(addedjforumuser);
    }
  }