Beispiel #1
0
  public UserSessionBase processSuccessLogin(
      int authType, String userAgent, HttpServletRequest httpRequest) {
    boolean newSessionCreation = true;
    UserSessionBase userSession = null;

    XASecurityContext context = XAContextHolder.getSecurityContext();
    if (context != null) {
      userSession = context.getUserSession();
    }

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    WebAuthenticationDetails details = (WebAuthenticationDetails) authentication.getDetails();

    String currentLoginId = authentication.getName();
    if (userSession != null) {
      if (validateUserSession(userSession, currentLoginId)) {
        newSessionCreation = false;
      }
    }

    if (newSessionCreation) {
      // Need to build the UserSession
      XXPortalUser gjUser = daoManager.getXXPortalUser().findByLoginId(currentLoginId);
      if (gjUser == null) {
        logger.error("Error getting user for loginId=" + currentLoginId, new Exception());
        return null;
      }

      XXAuthSession gjAuthSession = new XXAuthSession();
      gjAuthSession.setLoginId(currentLoginId);
      gjAuthSession.setUserId(gjUser.getId());
      gjAuthSession.setAuthTime(DateUtil.getUTCDate());
      gjAuthSession.setAuthStatus(XXAuthSession.AUTH_STATUS_SUCCESS);
      gjAuthSession.setAuthType(authType);
      if (details != null) {
        gjAuthSession.setExtSessionId(details.getSessionId());
        gjAuthSession.setRequestIP(details.getRemoteAddress());
      }

      if (userAgent != null) {
        gjAuthSession.setRequestUserAgent(userAgent);
      }
      gjAuthSession.setDeviceType(httpUtil.getDeviceType(userAgent));
      gjAuthSession = storeAuthSession(gjAuthSession);

      userSession = new UserSessionBase();
      userSession.setXXPortalUser(gjUser);
      userSession.setXXAuthSession(gjAuthSession);
      resetUserSessionForProfiles(userSession);

      if (details != null) {
        logger.info(
            "Login Success: loginId="
                + currentLoginId
                + ", sessionId="
                + gjAuthSession.getId()
                + ", sessionId="
                + details.getSessionId()
                + ", requestId="
                + details.getRemoteAddress());
      } else {
        logger.info(
            "Login Success: loginId="
                + currentLoginId
                + ", sessionId="
                + gjAuthSession.getId()
                + ", details is null");
      }
    }

    return userSession;
  }