Source Code Cross Referenced for NtlmSsp.java in  » Net » jCIFS » jcifs » http » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » jCIFS » jcifs.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* jcifs smb client library in Java
002:         * Copyright (C) 2002  "Michael B. Allen" <jcifs at samba dot org>
003:         *                   "Eric Glass" <jcifs at samba dot org>
004:         *                   "Jason Pugsley" <jcifs at samba dot org>
005:         *                   "skeetz" <jcifs at samba dot org>
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:
022:        package jcifs.http;
023:
024:        import java.io.IOException;
025:
026:        import javax.servlet.ServletException;
027:
028:        import javax.servlet.http.HttpServletRequest;
029:        import javax.servlet.http.HttpServletResponse;
030:
031:        import jcifs.smb.NtlmPasswordAuthentication;
032:
033:        import jcifs.util.Base64;
034:
035:        import jcifs.ntlmssp.NtlmFlags;
036:        import jcifs.ntlmssp.Type1Message;
037:        import jcifs.ntlmssp.Type2Message;
038:        import jcifs.ntlmssp.Type3Message;
039:
040:        /**
041:         * This class is used internally by <tt>NtlmHttpFilter</tt>,
042:         * <tt>NtlmServlet</tt>, and <tt>NetworkExplorer</tt> to negiotiate password
043:         * hashes via NTLM SSP with MSIE. It might also be used directly by servlet
044:         * containers to incorporate similar functionality.
045:         * <p>
046:         * How NTLMSSP is used in conjunction with HTTP and MSIE clients is
047:         * described in an <A HREF="http://www.innovation.ch/java/ntlm.html">NTLM
048:         * Authentication Scheme for HTTP</A>.  <p> Also, read <a
049:         * href="../../../ntlmhttpauth.html">jCIFS NTLM HTTP Authentication and
050:         * the Network Explorer Servlet</a> related information.
051:         */
052:
053:        public class NtlmSsp implements  NtlmFlags {
054:
055:            /**
056:             * Calls the static {@link #authenticate(HttpServletRequest,
057:             * HttpServletResponse, byte[])} method to perform NTLM authentication
058:             * for the specified servlet request.
059:             *
060:             * @param req The request being serviced.
061:             * @param resp The response.
062:             * @param challenge The domain controller challenge.
063:             * @throws IOException If an IO error occurs.
064:             * @throws ServletException If an error occurs.
065:             */
066:            public NtlmPasswordAuthentication doAuthentication(
067:                    HttpServletRequest req, HttpServletResponse resp,
068:                    byte[] challenge) throws IOException, ServletException {
069:                return authenticate(req, resp, challenge);
070:            }
071:
072:            /**
073:             * Performs NTLM authentication for the servlet request.
074:             *
075:             * @param req The request being serviced.
076:             * @param resp The response.
077:             * @param challenge The domain controller challenge.
078:             * @throws IOException If an IO error occurs.
079:             * @throws ServletException If an error occurs.
080:             */
081:            public static NtlmPasswordAuthentication authenticate(
082:                    HttpServletRequest req, HttpServletResponse resp,
083:                    byte[] challenge) throws IOException, ServletException {
084:                String msg = req.getHeader("Authorization");
085:                if (msg != null && msg.startsWith("NTLM ")) {
086:                    byte[] src = Base64.decode(msg.substring(5));
087:                    if (src[8] == 1) {
088:                        Type1Message type1 = new Type1Message(src);
089:                        Type2Message type2 = new Type2Message(type1, challenge,
090:                                null);
091:                        msg = Base64.encode(type2.toByteArray());
092:                        resp.setHeader("WWW-Authenticate", "NTLM " + msg);
093:                    } else if (src[8] == 3) {
094:                        Type3Message type3 = new Type3Message(src);
095:                        byte[] lmResponse = type3.getLMResponse();
096:                        if (lmResponse == null)
097:                            lmResponse = new byte[0];
098:                        byte[] ntResponse = type3.getNTResponse();
099:                        if (ntResponse == null)
100:                            ntResponse = new byte[0];
101:                        return new NtlmPasswordAuthentication(
102:                                type3.getDomain(), type3.getUser(), challenge,
103:                                lmResponse, ntResponse);
104:                    }
105:                } else {
106:                    resp.setHeader("WWW-Authenticate", "NTLM");
107:                }
108:                resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
109:                resp.flushBuffer();
110:                return null;
111:            }
112:
113:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.