亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tokenprocessor.java

?? struts的源代碼
?? JAVA
字號:
/*
 * $Id: TokenProcessor.java 54929 2004-10-16 16:38:42Z germuska $ 
 *
 * Copyright 2003-2004 The Apache Software Foundation.
 * 
 * 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 org.apache.struts.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.Globals;
import org.apache.struts.taglib.html.Constants;

/**
 * TokenProcessor is responsible for handling all token related functionality.  The 
 * methods in this class are synchronized to protect token processing from multiple
 * threads.  Servlet containers are allowed to return a different HttpSession object
 * for two threads accessing the same session so it is not possible to synchronize 
 * on the session.
 * 
 * @since Struts 1.1
 */
public class TokenProcessor {

    /**
     * The singleton instance of this class.
     */
    private static TokenProcessor instance = new TokenProcessor();

    /**
     * Retrieves the singleton instance of this class.
     */
    public static TokenProcessor getInstance() {
        return instance;
    }

    /**
     * Protected constructor for TokenProcessor.  Use TokenProcessor.getInstance()
     * to obtain a reference to the processor.
     */
    protected TokenProcessor() {
        super();
    }

    /**
     * The timestamp used most recently to generate a token value.
     */
    private long previous;

    /**
     * Return <code>true</code> if there is a transaction token stored in
     * the user's current session, and the value submitted as a request
     * parameter with this action matches it.  Returns <code>false</code>
     * under any of the following circumstances:
     * <ul>
     * <li>No session associated with this request</li>
     * <li>No transaction token saved in the session</li>
     * <li>No transaction token included as a request parameter</li>
     * <li>The included transaction token value does not match the
     *     transaction token in the user's session</li>
     * </ul>
     *
     * @param request The servlet request we are processing
     */
    public synchronized boolean isTokenValid(HttpServletRequest request) {
        return this.isTokenValid(request, false);
    }

    /**
     * Return <code>true</code> if there is a transaction token stored in
     * the user's current session, and the value submitted as a request
     * parameter with this action matches it.  Returns <code>false</code>
     * <ul>
     * <li>No session associated with this request</li>
     * <li>No transaction token saved in the session</li>
     * <li>No transaction token included as a request parameter</li>
     * <li>The included transaction token value does not match the
     *     transaction token in the user's session</li>
     * </ul>
     *
     * @param request The servlet request we are processing
     * @param reset Should we reset the token after checking it?
     */
    public synchronized boolean isTokenValid(
        HttpServletRequest request,
        boolean reset) {

        // Retrieve the current session for this request
        HttpSession session = request.getSession(false);
        if (session == null) {
            return false;
        }

        // Retrieve the transaction token from this session, and
        // reset it if requested
        String saved = (String) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY);
        if (saved == null) {
            return false;
        }

        if (reset) {
            this.resetToken(request);
        }

        // Retrieve the transaction token included in this request
        String token = request.getParameter(Constants.TOKEN_KEY);
        if (token == null) {
            return false;
        }

        return saved.equals(token);
    }

    /**
     * Reset the saved transaction token in the user's session.  This
     * indicates that transactional token checking will not be needed
     * on the next request that is submitted.
     *
     * @param request The servlet request we are processing
     */
    public synchronized void resetToken(HttpServletRequest request) {

        HttpSession session = request.getSession(false);
        if (session == null) {
            return;
        }
        session.removeAttribute(Globals.TRANSACTION_TOKEN_KEY);
    }

    /**
     * Save a new transaction token in the user's current session, creating
     * a new session if necessary.
     *
     * @param request The servlet request we are processing
     */
    public synchronized void saveToken(HttpServletRequest request) {

        HttpSession session = request.getSession();
        String token = generateToken(request);
        if (token != null) {
            session.setAttribute(Globals.TRANSACTION_TOKEN_KEY, token);
        }

    }

    /**
     * Generate a new transaction token, to be used for enforcing a single
     * request for a particular transaction.
     * 
     * @param request The request we are processing
     */
    public synchronized String generateToken(HttpServletRequest request) {

        HttpSession session = request.getSession();
        try {
            byte id[] = session.getId().getBytes();
            long current = System.currentTimeMillis();
            if (current == previous) {
                current++;
            }
            previous = current;
            byte now[] = new Long(current).toString().getBytes();
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(id);
            md.update(now);
            return toHex(md.digest());
        } catch (NoSuchAlgorithmException e) {
            return null;
        }

    }

    /**
     * Convert a byte array to a String of hexadecimal digits and return it.
     * @param buffer The byte array to be converted
     */
    private String toHex(byte buffer[]) {
        StringBuffer sb = new StringBuffer(buffer.length * 2);
        for (int i = 0; i < buffer.length; i++) {
            sb.append(Character.forDigit((buffer[i] & 0xf0) >> 4, 16));
            sb.append(Character.forDigit(buffer[i] & 0x0f, 16));
        }
        return sb.toString();
    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产乱一区二区| 老司机免费视频一区二区三区| 一区二区三区波多野结衣在线观看| 亚洲综合免费观看高清完整版 | 亚洲天堂2014| 极品少妇xxxx精品少妇| 欧美日韩综合一区| 国产性做久久久久久| 免费一级片91| 麻豆精品在线视频| 精品污污网站免费看| 在线观看亚洲精品视频| 精品国产乱码久久久久久图片| 国产精品久久久久久久久免费相片 | 久久精品二区亚洲w码| 欧美午夜精品久久久久久超碰| 国产精品久久一级| 国产成人av电影免费在线观看| 91麻豆精品国产91久久久资源速度| 中文字幕一区二区在线播放| 国模娜娜一区二区三区| 欧美成人bangbros| 精品一区二区三区免费观看| 91麻豆精品国产自产在线观看一区| 亚洲欧美日韩国产成人精品影院 | 久久精品亚洲精品国产欧美kt∨| 欧美日韩久久不卡| 日韩一区精品视频| 国模娜娜一区二区三区| 久久女同性恋中文字幕| 麻豆成人综合网| 久久亚洲影视婷婷| 粉嫩一区二区三区在线看| 中文字幕欧美激情一区| 亚洲成人av在线电影| 一本一道波多野结衣一区二区| 亚洲美女电影在线| 日韩欧美一二区| 成人午夜视频网站| 一卡二卡三卡日韩欧美| 日韩高清不卡在线| 久久久噜噜噜久久中文字幕色伊伊| 丁香六月综合激情| 亚洲综合一区二区三区| 日韩欧美在线网站| www.亚洲精品| 日韩不卡一区二区三区| 久久精品亚洲乱码伦伦中文| 色成人在线视频| 精品在线免费视频| 亚洲精品乱码久久久久| 日韩美女天天操| 色综合久久88色综合天天| 琪琪久久久久日韩精品| 国产精品看片你懂得| 日韩一区二区电影网| 精品福利一二区| 成人丝袜视频网| 热久久一区二区| 亚洲精品视频免费看| 久久综合色综合88| 欧美高清你懂得| av不卡在线播放| 国产一区二区三区日韩| 亚洲动漫第一页| 中文字幕在线免费不卡| 欧美一区二区三级| 欧美视频中文字幕| 婷婷久久综合九色综合伊人色| 久久精品一区二区三区不卡牛牛| 欧美午夜寂寞影院| 亚洲国产精品欧美一二99| 国产精品免费久久久久| 精品日韩欧美在线| 欧美一区二区私人影院日本| 91美女精品福利| 成人一区二区三区在线观看| 国产曰批免费观看久久久| 久久电影网站中文字幕| 精品一区二区三区视频| 日本中文字幕不卡| 久久成人综合网| 极品美女销魂一区二区三区免费 | 91在线免费视频观看| 99免费精品视频| 色婷婷综合视频在线观看| 色综合天天综合网天天看片| gogo大胆日本视频一区| 波多野结衣中文字幕一区| 成人美女在线视频| 色综合久久中文综合久久牛| 欧美亚一区二区| 欧美一区二区三区公司| 欧美va亚洲va| 国产午夜精品一区二区三区视频| 国产精品久久久久一区二区三区| 中文字幕亚洲在| 日韩影视精彩在线| 国产91色综合久久免费分享| 色综合咪咪久久| 欧美一二三四在线| 精品日韩欧美在线| 椎名由奈av一区二区三区| 尤物在线观看一区| 美女免费视频一区| 91免费版pro下载短视频| 色菇凉天天综合网| 精品99999| 亚洲精品高清视频在线观看| 日韩av一区二区在线影视| 午夜影院久久久| 人禽交欧美网站| 91久久国产综合久久| 欧美精品一区二区三区在线播放| 亚洲天天做日日做天天谢日日欢| 日韩av一级电影| 一本大道久久a久久综合婷婷| 日韩午夜电影在线观看| 亚洲精品一二三| 国产一区二区精品久久99| 欧美日韩精品专区| 亚洲精品国产a久久久久久| 国产大陆亚洲精品国产| 精品亚洲免费视频| 欧美久久高跟鞋激| 亚洲一区在线看| av在线不卡免费看| av一区二区不卡| 久久久不卡影院| 国内精品国产成人| 欧美一区二区三区在线电影 | 琪琪久久久久日韩精品| 在线中文字幕一区二区| 一区免费观看视频| 91在线视频播放| 亚洲美女免费视频| 欧美视频日韩视频| 亚洲国产日韩精品| 91久久线看在观草草青青| 综合欧美一区二区三区| 亚洲日穴在线视频| 91在线免费播放| 一级日本不卡的影视| 成人99免费视频| 中文字幕电影一区| 不卡视频在线看| 日韩美女精品在线| 色综合一区二区三区| 一区二区三区四区蜜桃| 久久精品国产久精国产爱| 欧美精品一区二区不卡| 成人av免费在线观看| 综合激情网...| 3d成人动漫网站| 国产伦精一区二区三区| 蜜臀av性久久久久蜜臀aⅴ| 欧美一区二区三区免费观看视频 | 久久99久久精品| 国产视频一区二区三区在线观看| 国产成人综合在线观看| 久久综合给合久久狠狠狠97色69| 粉嫩绯色av一区二区在线观看| 1024国产精品| 日韩免费看网站| 国产精华液一区二区三区| 亚洲综合精品自拍| www成人在线观看| 欧美一级黄色片| 春色校园综合激情亚洲| 91麻豆精品一区二区三区| 亚洲18女电影在线观看| 国产欧美综合在线观看第十页| 色噜噜狠狠色综合欧洲selulu| 久久成人免费网站| 亚洲精品ww久久久久久p站| 精品成人一区二区三区| 欧美男女性生活在线直播观看| 国产麻豆精品在线观看| 日韩av成人高清| 怡红院av一区二区三区| 国产欧美日韩另类一区| 蜜乳av一区二区| 丝袜亚洲精品中文字幕一区| 中文字幕av一区二区三区免费看| 欧美日韩免费观看一区三区| www.日韩精品| 成人理论电影网| 国产黄色91视频| 国产精品12区| 国产高清精品在线| 久久精品噜噜噜成人88aⅴ| 午夜欧美一区二区三区在线播放| 亚洲欧美另类在线| 亚洲欧美日韩一区二区三区在线观看| av欧美精品.com| 91免费版在线看| 欧美日韩一卡二卡三卡 | 成人免费看视频| 欧美精品丝袜中出| 伊人色综合久久天天|