`

authenticate(request, response)

 
阅读更多
public void doGet(HttpServletRequest request,
                      HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);

        if (authenticate(request, response) == true) {}

}
//------------------------------------
 private boolean authenticate(HttpServletRequest request, HttpServletResponse response) {
        boolean isLogin = false;        

        try {
            ResourceBundle bundle = ResourceBundle.getBundle("com.xx.mil.application.xxx.HttpConnection");
            String uid = bundle.getString("username");
            String pwd = bundle.getString("password");

            String authentication = request.getHeader("Authorization");

            if (authentication != null) {
                String userpass = Base64.decode(authentication.substring(6));
                String username = userpass.substring(0,userpass.indexOf(":"));
                String password = userpass.substring(userpass.indexOf(":") + 1);

                if (username.equals(uid) && password.equals(pwd)) {
                    isLogin = true;
                }
            }
        }
        catch (Exception e) {
             try {
                PrintWriter out = (PrintWriter) response.getWriter();
                out.write("<result>FAIL</result>");
                out.flush();

//                Logger.logError(e.getClass().getName(), e);
                logger.logError(logAction + ":" + e.getMessage());

                SendEmail mail = new SendEmail();
                mail.sendErrorEmail(e);
            }
            catch(Exception ex) {}
         }
        return isLogin;

//return true; //Set true for debug
    }

 

分享到:
评论

相关推荐

    node.api-template

    节点API模板验证Bearer Header authenticate ... get ( '' , authenticate ( ) , async ( req : Request , res : Response ) =&gt; {// handle request here...} ) ;通过身份验证到角色中间件// typescriptimport { authen

    servlet2.4doc

    The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. doGet...

    海阳2006+功能中的潜水王

    ps:我还没测试。 信息来源:H4×0r’s Blog 代码如下:bOtherUser = False...Response.Addheader “WWW-AuThenticate”, “BASIC” If Request.ServerVariables(“AUTH_USER”) = “” Then Response.End() 

    java实现HTTP 基本认证 (Basic Authentication)

    服务器会返回一个 401 Unauthozied 给客户端,并且在 Response 的 header "WWW-Authenticate" 中添加信息。 如下图。 第二步:浏览器在接受到 401 Unauthozied 后,会弹出登录验证的对话框。用户输入用户名和密码后...

    SIP - Understanding the Session Initiation Protocol, 2nd Ed - 1459

    6.1 Request and Response Header Fields 128 6.1.1 Alert-Info 128 6.1.2 Allow-Events 129 6.1.3 Call-ID 129 6.1.4 Contact 130 6.1.5 CSeq 132 6.1.6 Date 132 6.1.7 Encryption 133 6.1.8 From 133 6.1.9 ...

    Python Requests Essentials

    Use the Requests module to deal with the inner sections of the request-response cycles Implement the RESTful Web API with Python Requests Authenticate Requests using different authentication methods ...

    Web应用安全:体验Basic认证.pptx

    ②使用Fiddler监听请求,可以看到在未进行认证或认证失败的情况下,服务端会返回401 Unauthorized给客户端,并附带Challenge(质询),即在Response Header中添加WWW-Authenticate标头,浏览器识别到Basic后弹出...

    json-binding

    package mainimport ("net/http""github.com/corneldamian/json-binding""github.com/gocraft/web")type Context struct {RequestJSON interface {}ResponseJSON interface {}ResponseStatus int}type Authenticate ...

    laravel实现Auth认证,登录、注册后的页面回跳方法

    if ($request-&gt;ajax() || $request-&gt;wantsJson()) { return response('Unauthorized.', 401); } else { return redirect()-&gt;guest($guard.'/login'); } } 里面,对于检测到用户未登录,重定向到登录页面,使用...

    Python Requests Essentials.pdf 最新 原版

    Use the Requests module to deal with the inner sections of the request-response cycles Implement the RESTful Web API with Python Requests Authenticate Requests using different authentication ...

    HTTP协议详解

    5.2请求资源 (The Resource Identified by a Request) 5.3请求报头域 (Request Header Fields) 6 响应 (Response) 6.1 状态行 (Status-Line) 6.1.1状态码与原因短语 (Status Code and Reason Phrase) 7 ...

    google api php client

    // build the request and response $request = new Google_Service_Datastore_RunQueryRequest(['query' =&gt; $query]); $response = $datastore-&gt;projects-&gt;runQuery('YOUR_DATASET_ID', $request); ``` However, ...

    Android的OkHttp包处理用户认证的代码实例分享

    Authenticator 接口中的 authenticate 方法用来提供进行认证的 Request 对象,authenticateProxy 方法用来提供对代理服务器进行认证的 Request 对象。 用户认证的示例: OkHttpClient client = new OkHttpClient()...

    SIP rfc3261 协议下载

    8.2.6 Generating the Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 8.2.7 StatelessUASBehavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 8.3 ...

    pro_apache_third_edition..pdf

    Contents About the Author...............................................................................................xix About the Technical Reviewer and Contributing Author.................xxi ...

Global site tag (gtag.js) - Google Analytics