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

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

?? whiteboardservlet.java

?? J2ME MIDP_Example_Applications
?? JAVA
字號:
// Copyright 2003 Nokia Corporation.
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUPPORT. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Corporation
// retains the right to make changes to this source code at
// any time, without notice. This source code is provided for informational
// purposes only.
//
// Nokia and Nokia Connecting People are registered trademarks of Nokia
// Corporation.
// Java and all Java-based marks are trademarks or registered trademarks of
// Sun Microsystems, Inc.
// Other product and company names mentioned herein may be trademarks or
// trade names of their respective owners.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.
package whiteboard;

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.bouncycastle.crypto.*;
import org.bouncycastle.crypto.digests.*;
import org.bouncycastle.util.encoders.Hex;

// Simple servlet serving GET and POST requests
// Version 1.3: Custom authentication based on Digest Authentication logic
public class WhiteboardServlet
     extends HttpServlet
{
    private Whiteboard whiteboard;
    private ServletConfig context;
    private DateFormat format = null;
    private String key = null;
    private UserDatabase userDB = null;
    private long internalKey, counter;
    private Random random;


    public void init()
    {
        context = getServletConfig();
        String dateformat = context.getInitParameter("dateformat");
        if (dateformat != null)
        {
            try
            {
                format = new SimpleDateFormat(dateformat);
            }
            catch (Exception e)
            {
                // ignore, we'll check it later
            }
        }
        if (format == null)
        {
            format = DateFormat.getTimeInstance(DateFormat.SHORT);
        }

        // init the whiteboard data structure
        whiteboard = Whiteboard.getInstance();
        userDB = new UserDatabase();
        // insert a mock up user
        userDB.createUser("guest", "password");

        // It could use SecureRandom as well
        random = new Random();
        internalKey = random.nextLong();
    }


    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, java.io.IOException
    {
        String username = authenticateUsername(req, resp, "GET");
        if (username != null)
        {
            String response = buildResponse();
            resp.setContentType("text/plain");
            ServletOutputStream out = resp.getOutputStream();
            out.println(response);
        }
    }


    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, java.io.IOException
    {
        String username = authenticateUsername(req, resp, "POST");
        if (username != null)
        {
            String msg = req.getParameter("msg");
            if (msg != null)
            {
                whiteboard.addMessage(new Message(username, new Date(), msg));
                String response = buildResponse();
                resp.setContentType("text/plain");
                ServletOutputStream out = resp.getOutputStream();
                out.println(response);
            }
            else
            {
                resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
                    "Missing msg parameter");
            }
        }
    }


    // Creates the response containing a list of messages
    private String buildResponse()
    {
        Collection messages = whiteboard.getMessages();

        // if no count parameter or error during parsing
        if (messages == null)
        {
            messages = whiteboard.getMessages();
        }

        ValueGenerator generator = new ValueGenerator();
        generator.addValue("" + messages.size());
        Iterator i = messages.iterator();
        while (i.hasNext())
        {
            Message msg = (Message) i.next();
            generator.addValue(msg.getUser());
            generator.addValue(format.format(msg.getTimestamp()));
            generator.addValue(msg.getContent());
        }

        // print the text
        return generator.getString();
    }



    // It attempts to validate the user in the request. If it is possible it will return
    // the username. If not it will return null and set the appropriate response
    // including an SC_UNAUTHORIZED error code and a X-WWW-Authenticate challenge
    private String authenticateUsername(HttpServletRequest req, HttpServletResponse resp, String method)
        throws IOException
    {
        String username = null;
        // Check if the user is trying to authenticate
        if (req.getHeader("X-Authorization") == null)
        {
            // no X-Authorization header implies the request is not authorized
            resp.setHeader("X-WWW-Authenticate", createDigestChallenge());
            resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        }
        else
        {
            // The request contains an authorization header
            String xauth = req.getHeader("X-Authorization");
            // Try to validate the authorization
            username = validateDigestResponse(xauth, method);
            if (username == null)
            {
                resp.setHeader("X-WWW-Authenticate", createDigestChallenge());
                resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
            }
        }
        return username;
    }


    // It creates a digest challenge to be passed in the
    // X-WWW-Authorization header. Uses the principles under RFC 2617
    private synchronized String createDigestChallenge()
    {
        StringBuffer challenge = new StringBuffer("X-Digest realm=\"").append(getServletName()).append("\", qop=\"auth\", ");
        // Create a nonce. The counter value ensures that even requests within a milisec
        // will have a different nonce
        String nonce = (System.currentTimeMillis() + counter++) + ":" + internalKey;

        // calculates nonce's digest and encode as HEX
        Digest digest = new MD5Digest();
        byte[] result = new byte[digest.getDigestSize()];
        digest.update(nonce.getBytes(), 0, nonce.getBytes().length);
        digest.doFinal(result, 0);
        nonce = new String(Hex.encode(result));
        challenge.append("nonce=\"").append(nonce).append("\", ");

        // Create opaque
        String opaque = "" + random.nextLong();
        digest.update(opaque.getBytes(), 0, opaque.getBytes().length);
        digest.doFinal(result, 0);
        opaque = new String(Hex.encode(result));
        challenge.append("opaque=\"").append(opaque).append("\"");

        return challenge.toString();
    }


    // It validates the user's response and returns a username.
    // If null the user was not authenticated
    private synchronized String validateDigestResponse(String challengeResponse, String method)
    {
        if (!challengeResponse.startsWith("X-Digest"))
        {
            return null;
        }
        challengeResponse = challengeResponse.substring(8).trim();

        // parse the response components
        StringTokenizer tokenizer = new StringTokenizer(challengeResponse, ",");
        String nonce = null;
        String realm = null;
        String opaque = null;
        String uri = null;
        String username = null;
        String response = null;
        // parses the response
        while (tokenizer.hasMoreTokens())
        {
            String nextToken = tokenizer.nextToken().trim();
            if (nextToken.startsWith("nonce"))
            {
                nonce = nextToken.substring(7, nextToken.length() - 1);
            }
            if (nextToken.startsWith("opaque"))
            {
                opaque = nextToken.substring(8, nextToken.length() - 1);
            }
            if (nextToken.startsWith("uri"))
            {
                uri = nextToken.substring(5, nextToken.length() - 1);
            }
            if (nextToken.startsWith("username"))
            {
                username = nextToken.substring(10, nextToken.length() - 1);
            }
            if (nextToken.startsWith("response"))
            {
                response = nextToken.substring(10, nextToken.length() - 1);
            }
            if (nextToken.startsWith("realm"))
            {
                realm = nextToken.substring(7, nextToken.length() - 1);
            }
        }

        // all components are required
        if (realm == null || nonce == null || opaque == null || uri == null || username == null || response == null)
        {
            return null;
        }
        // Check the realm
        if (!realm.equals(getServletName()))
        {
            return null;
        }
        // try to find a username
        User user = userDB.getUser(username);
        if (user == null)
        {
            return null;
        }
        // If the username is found, we calculate the digest as in RFC 2617
        // Calculate A1
        // A1 could also be calculated by User to avoid exposing the password at this level
        String A1 = username + ":" + realm + ":" + user.getPassword();
        Digest digest = new MD5Digest();
        int size = digest.getDigestSize();
        byte[] allbytes = A1.getBytes();
        byte[] result = new byte[size];
        digest.update(allbytes, 0, allbytes.length);
        digest.doFinal(result, 0);
        A1 = new String(Hex.encode(result));

        // Calculate A2
        String A2 = method + ":" + uri;
        allbytes = A2.getBytes();
        digest.update(allbytes, 0, allbytes.length);
        digest.doFinal(result, 0);
        A2 = new String(Hex.encode(result));

        // Calculate response
        String calculatedResponse = A1 + ":" + nonce + ":" + A2;
        allbytes = calculatedResponse.getBytes();
        digest.update(allbytes, 0, allbytes.length);
        digest.doFinal(result, 0);
        calculatedResponse = new String(Hex.encode(result));

        // Compare servers digest with client's digest
        if (calculatedResponse.equals(response))
        {
            return username;
        }

        return null;
    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
视频一区中文字幕| 国产成人在线看| 国产精品一区免费视频| 色视频成人在线观看免| 欧美大尺度电影在线| 一区二区在线观看免费| 国产精品一色哟哟哟| 欧美乱熟臀69xxxxxx| 1000部国产精品成人观看| 麻豆国产精品777777在线| 欧美在线你懂的| 国产精品理论在线观看| 国产酒店精品激情| 日韩你懂的在线观看| 三级精品在线观看| 欧美视频在线不卡| 一区二区三区在线看| 99re热这里只有精品视频| 久久久亚洲国产美女国产盗摄| 欧美aaaaaa午夜精品| 欧美日韩在线播放| 亚洲成人在线网站| 欧美三级韩国三级日本一级| 亚洲欧美偷拍卡通变态| a级高清视频欧美日韩| 国产精品美女久久久久久久久| 国产一区在线观看麻豆| 久久亚洲二区三区| 国产精品一区二区在线观看网站| 精品日产卡一卡二卡麻豆| 日本不卡123| 日韩精品专区在线影院观看| 久久激情综合网| 久久综合久久99| 懂色av中文一区二区三区 | 欧美日韩精品欧美日韩精品一| 亚洲男人的天堂av| 日本高清成人免费播放| 亚洲免费在线观看视频| 欧美日韩一区二区在线观看| 亚洲二区视频在线| 欧美久久婷婷综合色| 蜜臀va亚洲va欧美va天堂| 欧美变态口味重另类| 国产精一品亚洲二区在线视频| 国产日本欧洲亚洲| 99久久精品免费看国产免费软件| 亚洲精品欧美激情| 欧美日韩高清影院| 久久成人综合网| 亚洲国产精品ⅴa在线观看| 91玉足脚交白嫩脚丫在线播放| 亚洲综合清纯丝袜自拍| 欧美一级二级三级蜜桃| 国产精品亚洲人在线观看| 一区在线观看视频| 欧美日韩视频在线一区二区| 久久99久久久久久久久久久| 国产三区在线成人av| 色乱码一区二区三区88| 日本人妖一区二区| 国产日韩欧美精品一区| 欧美在线不卡视频| 国产一区美女在线| 伊人婷婷欧美激情| 久久精品一级爱片| 欧美影院一区二区三区| 国内精品国产成人| 洋洋成人永久网站入口| 亚洲精品一区二区三区在线观看| 91浏览器在线视频| 久久99日本精品| 亚洲一区二区三区中文字幕在线 | 色婷婷av一区二区| 蜜臀va亚洲va欧美va天堂| 亚洲日本欧美天堂| 26uuu色噜噜精品一区| 色素色在线综合| 国产精品69久久久久水密桃| 午夜欧美一区二区三区在线播放| 久久精品视频一区二区三区| 欧美另类久久久品| 97久久久精品综合88久久| 韩国v欧美v亚洲v日本v| 亚洲影视在线观看| 国产精品每日更新| 久久久精品tv| 精品国产一区二区精华| 欧美天堂一区二区三区| 一本一本久久a久久精品综合麻豆| 精品一区二区在线看| 肉丝袜脚交视频一区二区| 一区二区三区免费观看| 中文字幕制服丝袜一区二区三区 | 日韩免费一区二区| 在线视频国内自拍亚洲视频| 成人精品高清在线| 国产成人一区在线| 国产一区二区美女| 奇米在线7777在线精品| 亚洲福中文字幕伊人影院| 亚洲欧美日韩小说| 国产精品国产三级国产aⅴ入口| 337p日本欧洲亚洲大胆色噜噜| 欧美日韩电影在线播放| 在线精品亚洲一区二区不卡| av电影一区二区| 成人精品鲁一区一区二区| www.一区二区| 99热99精品| 色综合欧美在线视频区| 99re热视频精品| 色吧成人激情小说| 在线视频国内自拍亚洲视频| 欧美亚洲一区二区在线| 欧美日韩在线免费视频| 4438x亚洲最大成人网| 91精品国产色综合久久不卡电影| 欧美精选在线播放| 日韩一级免费一区| 欧美xxxxxxxxx| 久久久久久久久一| 国产精品毛片a∨一区二区三区 | 久久噜噜亚洲综合| 久久综合九色欧美综合狠狠| 久久久久国产免费免费| 国产精品乱子久久久久| 亚洲精品午夜久久久| 亚洲国产一区在线观看| 免费人成网站在线观看欧美高清| 黄色小说综合网站| 国产99久久久久| 91麻豆精品一区二区三区| 欧美性大战久久久久久久蜜臀| 欧美日韩成人综合在线一区二区| 日韩美一区二区三区| 久久午夜电影网| 中文字幕欧美一| 亚洲成人免费影院| 国产美女视频一区| 色婷婷综合视频在线观看| 欧美肥大bbwbbw高潮| 国产亚洲欧美色| 一区二区三区国产| 精品一区二区三区日韩| www.亚洲免费av| 欧美电视剧在线观看完整版| 国产精品美女视频| 日韩av不卡在线观看| 成人涩涩免费视频| 欧美视频日韩视频| 欧美激情综合网| 日本伊人色综合网| 99久久精品99国产精品| 日韩午夜激情av| 亚洲黄网站在线观看| 国产精品一级在线| 欧美日本一区二区三区四区| 亚洲国产精品99久久久久久久久| 亚洲国产欧美日韩另类综合| 国产成人在线看| 欧美一级xxx| 亚洲综合一区二区| 东方aⅴ免费观看久久av| 7777精品伊人久久久大香线蕉完整版| 久久九九国产精品| 免费观看在线综合色| 日本韩国欧美一区| 中文字幕av在线一区二区三区| 午夜精品久久一牛影视| 91在线看国产| 亚洲精品一区二区三区四区高清| 亚洲精品高清在线| 成人一级视频在线观看| 精品日韩在线观看| 男男视频亚洲欧美| 91成人免费在线视频| 国产精品乱人伦中文| 国产999精品久久久久久绿帽| 日韩一区二区精品葵司在线| 五月综合激情网| 在线免费亚洲电影| 亚洲丝袜美腿综合| 成人午夜伦理影院| 国产日韩av一区| 国产剧情在线观看一区二区| 精品福利一区二区三区免费视频| 亚洲国产精品久久人人爱 | 成人深夜视频在线观看| 欧美精品一区二区三区视频| 全部av―极品视觉盛宴亚洲| 欧美日韩一区二区在线观看视频 | 18成人在线观看| 91在线高清观看| 亚洲视频综合在线| 91网址在线看| 亚洲乱码国产乱码精品精可以看| 97精品国产97久久久久久久久久久久| 欧美国产日本韩| av成人动漫在线观看|