Source Code Cross Referenced for JAASCallbackHandler.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » catalina » 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 » Sevlet Container » apache tomcat 6.0.14 » org.apache.catalina.realm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.catalina.realm;
019:
020:        import java.io.IOException;
021:        import javax.security.auth.callback.Callback;
022:        import javax.security.auth.callback.CallbackHandler;
023:        import javax.security.auth.callback.NameCallback;
024:        import javax.security.auth.callback.PasswordCallback;
025:        import javax.security.auth.callback.UnsupportedCallbackException;
026:
027:        import org.apache.catalina.util.StringManager;
028:
029:        /**
030:         * <p>Implementation of the JAAS <code>CallbackHandler</code> interface,
031:         * used to negotiate delivery of the username and credentials that were
032:         * specified to our constructor.  No interaction with the user is required
033:         * (or possible).</p>
034:         *
035:         * <p>This <code>CallbackHandler</code> will pre-digest the supplied
036:         * password, if required by the <code>&lt;Realm&gt;</code> element in 
037:         * <code>server.xml</code>.</p>
038:         * <p>At present, <code>JAASCallbackHandler</code> knows how to handle callbacks of
039:         * type <code>javax.security.auth.callback.NameCallback</code> and
040:         * <code>javax.security.auth.callback.PasswordCallback</code>.</p>
041:         *
042:         * @author Craig R. McClanahan
043:         * @author Andrew R. Jaquith
044:         * @version $Revision: 543691 $ $Date: 2007-06-02 03:37:08 +0200 (sam., 02 juin 2007) $
045:         */
046:
047:        public class JAASCallbackHandler implements  CallbackHandler {
048:
049:            // ------------------------------------------------------------ Constructor
050:
051:            /**
052:             * Construct a callback handler configured with the specified values.
053:             * Note that if the <code>JAASRealm</code> instance specifies digested passwords,
054:             * the <code>password</code> parameter will be pre-digested here.
055:             *
056:             * @param realm Our associated JAASRealm instance
057:             * @param username Username to be authenticated with
058:             * @param password Password to be authenticated with
059:             */
060:            public JAASCallbackHandler(JAASRealm realm, String username,
061:                    String password) {
062:
063:                super ();
064:                this .realm = realm;
065:                this .username = username;
066:
067:                if (realm.hasMessageDigest()) {
068:                    this .password = realm.digest(password);
069:                } else {
070:                    this .password = password;
071:                }
072:            }
073:
074:            // ----------------------------------------------------- Instance Variables
075:
076:            /**
077:             * The string manager for this package.
078:             */
079:            protected static final StringManager sm = StringManager
080:                    .getManager(Constants.Package);
081:
082:            /**
083:             * The password to be authenticated with.
084:             */
085:            protected String password = null;
086:
087:            /**
088:             * The associated <code>JAASRealm</code> instance.
089:             */
090:            protected JAASRealm realm = null;
091:
092:            /**
093:             * The username to be authenticated with.
094:             */
095:            protected String username = null;
096:
097:            // --------------------------------------------------------- Public Methods
098:
099:            /**
100:             * Retrieve the information requested in the provided <code>Callbacks</code>.
101:             * This implementation only recognizes <code>NameCallback</code> and
102:             * <code>PasswordCallback</code> instances.
103:             *
104:             * @param callbacks The set of <code>Callback</code>s to be processed
105:             *
106:             * @exception IOException if an input/output error occurs
107:             * @exception UnsupportedCallbackException if the login method requests
108:             *  an unsupported callback type
109:             */
110:            public void handle(Callback callbacks[]) throws IOException,
111:                    UnsupportedCallbackException {
112:
113:                for (int i = 0; i < callbacks.length; i++) {
114:
115:                    if (callbacks[i] instanceof  NameCallback) {
116:                        if (realm.getContainer().getLogger().isTraceEnabled())
117:                            realm.getContainer().getLogger().trace(
118:                                    sm.getString("jaasCallback.username",
119:                                            username));
120:                        ((NameCallback) callbacks[i]).setName(username);
121:                    } else if (callbacks[i] instanceof  PasswordCallback) {
122:                        final char[] passwordcontents;
123:                        if (password != null) {
124:                            passwordcontents = password.toCharArray();
125:                        } else {
126:                            passwordcontents = new char[0];
127:                        }
128:                        ((PasswordCallback) callbacks[i])
129:                                .setPassword(passwordcontents);
130:                    } else {
131:                        throw new UnsupportedCallbackException(callbacks[i]);
132:                    }
133:                }
134:            }
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.