Source Code Cross Referenced for MVNTomcatJDBCRealm.java in  » Forum » mvnforum-1.1 » com » mvnsoft » auth » realm » 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 » Forum » mvnforum 1.1 » com.mvnsoft.auth.realm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2005 Kurt Miller <truk@optonline.net>
003:         *
004:         * Permission to use, copy, modify, and distribute this software for any
005:         * purpose with or without fee is hereby granted, provided that the above
006:         * copyright notice and this permission notice appear in all copies.
007:         *
008:         * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
009:         * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
010:         * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
011:         * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
012:         * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
013:         * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
014:         * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
015:         */
016:
017:        /* This file rewritten from a sample implementation of JDBCRealm written by Kurt Miller.
018:         * 
019:         * We configure realm with no digest, then encode it when authenticating 
020:         * instead of decoding database credentials. Because We don't know why 
021:         * MVNTomcatJDBCRealm is never called  
022:         * 
023:         * View Thread: http://www.mvnforum.com/mvnforum/mvnforum/viewthread?thread=2782
024:         */
025:        package com.mvnsoft.auth.realm;
026:
027:        import java.security.MessageDigest;
028:        import java.security.Principal;
029:        import java.security.cert.X509Certificate;
030:
031:        import org.apache.catalina.realm.JDBCRealm;
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:
035:        import sun.misc.BASE64Encoder;
036:
037:        public class MVNTomcatJDBCRealm extends JDBCRealm {
038:
039:            private static Log log = LogFactory
040:                    .getLog(MVNTomcatJDBCRealm.class);
041:
042:            protected String getPassword(String username) {
043:                // I don't know why this method is never called
044:                return super .getPassword(username);
045:            }
046:
047:            public String getMD5_Base64(String input) {
048:                // please note that we dont use digest, because if we
049:                // cannot get digest, then the second time we have to call it
050:                // again, which will fail again
051:                MessageDigest digest = null;
052:                try {
053:                    digest = MessageDigest.getInstance("MD5");
054:                } catch (Exception ex) {
055:                    log
056:                            .fatal(
057:                                    "Cannot get MessageDigest. Application may fail to run correctly.",
058:                                    ex);
059:                }
060:                if (digest == null)
061:                    return input;
062:
063:                // now everything is ok, go ahead
064:                try {
065:                    digest.update(input.getBytes("UTF-8"));
066:                } catch (java.io.UnsupportedEncodingException ex) {
067:                    log.error("Assertion: This should never occur.");
068:                }
069:                byte[] rawData = digest.digest();
070:                BASE64Encoder encoder = new BASE64Encoder();
071:
072:                return encoder.encode(rawData);
073:            }
074:
075:            protected String digest(String credentials) {
076:                System.out.println("MVNTomcatJDBCRealm.digest()");
077:                //return super.digest(credentials);
078:                return getMD5_Base64(credentials);
079:            }
080:
081:            /**
082:             * This is a sample implementation of JDBCRealm using password
083:             */
084:
085:            public Principal authenticate(String username, String password) {
086:                String md5_base64 = getMD5_Base64(password);
087:                System.out
088:                        .println("MVNTomcatJDBCRealm.authenticate(username, password)");
089:                //System.out.println("Authenticate 2 params " + username + " and " + md5_base64);
090:                //return super.authenticate(username, md5_base64);
091:                return super .authenticate(username, password);
092:            }
093:
094:            public Principal authenticate(String username, byte[] credentials) {
095:                System.out.println("Authenticate byte");
096:                return super .authenticate(username, credentials);
097:            }
098:
099:            public Principal authenticate(String username, String clientDigest,
100:                    String nOnce, String nc, String cnonce, String qop,
101:                    String realm, String md5a2) {
102:                //System.out.println("Authenticate username, clientDigest, nOnce, nc, cnonce, qop, realm, md5a2");
103:                return super .authenticate(username, clientDigest, nOnce, nc,
104:                        cnonce, qop, realm, md5a2);
105:            }
106:
107:            public Principal authenticate(X509Certificate[] certs) {
108:                //System.out.println("Authenticate X509Certificate");
109:                return super.authenticate(certs);
110:            }
111:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.