⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sessioncontextutil.java

📁 JiveJdon 3.0 is the application of Jdon Framework 1.4 final.
💻 JAVA
字号:
/*
 * Copyright 2003-2005 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.jdon.jivejdon.service.util;

import org.apache.log4j.Logger;

import com.jdon.container.visitor.data.SessionContext;
import com.jdon.container.visitor.data.SessionContextSetup;
import com.jdon.jivejdon.dao.AccountDao;
import com.jdon.jivejdon.model.Account;

/**
 * @author <a href="mailto:banqiao@jdon.com">banq</a>
 *
 */
public class SessionContextUtil {
    private final static Logger logger = Logger.getLogger(SessionContextUtil.class);
    public static final String ACCOUNT = "Account";
    
    private AccountDao accountDao;
    private ContainerUtil containerUtil;
        
    /**
     * @param accountDao
     */
    public SessionContextUtil(ContainerUtil containerUtil, AccountDao accountDao) {
        this.containerUtil = containerUtil;
        this.accountDao = accountDao;
    }
    
    public Account getLoginAccount(SessionContext sessionContext) {
        Account account = null;
        try {
            SessionContextSetup sessionContextSetup  = containerUtil.getSessionContextSetup();
            String principleName = (String)sessionContextSetup.getArrtibute(SessionContextSetup.PRINCIPAL_NAME, sessionContext);
            if (principleName == null) {
                throw new Exception("the login principle name is null");
            }
            logger.debug(" the login name is:" + principleName);
            account = getAccountByName(principleName, sessionContext);            
            if (account != null) {           
                logger.debug(" got the account, userId:" + account.getUserId());
                String ip = (String) sessionContextSetup.getArrtibute(SessionContextSetup.REMOTE_ADDRESS, sessionContext);
                account.setPostIP(ip);
            }
        } catch (Exception e) {
            logger.debug(" getLoginAccount error: " + e);
        }
        return account;
    }    
    
    public Account getAccountByName(String username, SessionContext sessionContext){
        Account account =  (Account)sessionContext.getArrtibute(ACCOUNT);
        if (account == null){
            account = accountDao.getAccountByName(username);   
            if (account != null){
                sessionContext.setArrtibute(ACCOUNT, account);
            }
        }
        return account;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -