Source Code Cross Referenced for ClientLoginModule.java in  » J2EE » openejb3 » org » apache » openejb » client » 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 » J2EE » openejb3 » org.apache.openejb.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *
003:         * Licensed to the Apache Software Foundation (ASF) under one or more
004:         * contributor license agreements.  See the NOTICE file distributed with
005:         * this work for additional information regarding copyright ownership.
006:         * The ASF licenses this file to You under the Apache License, Version 2.0
007:         * (the "License"); you may not use this file except in compliance with
008:         * the License.  You may obtain a copy of the License at
009:         *
010:         *     http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         *  Unless required by applicable law or agreed to in writing, software
013:         *  distributed under the License is distributed on an "AS IS" BASIS,
014:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         *  See the License for the specific language governing permissions and
016:         *  limitations under the License.
017:         */package org.apache.openejb.client;
018:
019:        import javax.security.auth.Subject;
020:        import javax.security.auth.callback.Callback;
021:        import javax.security.auth.callback.CallbackHandler;
022:        import javax.security.auth.callback.NameCallback;
023:        import javax.security.auth.callback.PasswordCallback;
024:        import javax.security.auth.callback.UnsupportedCallbackException;
025:        import javax.security.auth.login.LoginException;
026:        import javax.security.auth.spi.LoginModule;
027:        import java.io.IOException;
028:        import java.net.URI;
029:        import java.net.URISyntaxException;
030:        import java.util.Map;
031:        import java.util.logging.Logger;
032:
033:        public class ClientLoginModule implements  LoginModule {
034:            private static final Logger log = Logger
035:                    .getLogger("OpenEJB.client");
036:            private Subject subject;
037:            private CallbackHandler callbackHandler;
038:            private String serverUri;
039:            private boolean debug;
040:
041:            private String user;
042:            private Object clientIdentity;
043:            private ClientIdentityPrincipal principal;
044:            private String realmNameSeparator;
045:            private String realmName;
046:
047:            public void initialize(Subject subject,
048:                    CallbackHandler callbackHandler, Map sharedState,
049:                    Map options) {
050:                this .subject = subject;
051:                this .callbackHandler = callbackHandler;
052:
053:                // determine the server uri
054:                serverUri = System.getProperty("openejb.server.uri");
055:                if (serverUri == null) {
056:                    serverUri = (String) options.get("openejb.server.uri");
057:                }
058:
059:                this .debug = "true".equalsIgnoreCase((String) options
060:                        .get("debug"));
061:                if (debug) {
062:                    log.config("Initialized ClientLoginModule: debug=" + debug);
063:                }
064:
065:                if (options.containsKey("RealmNameSeparator")) {
066:                    realmNameSeparator = (String) options
067:                            .get("RealmNameSeparator");
068:                }
069:
070:                if (options.containsKey("RealmName")) {
071:                    realmName = (String) options.get("RealmName");
072:                }
073:            }
074:
075:            public boolean login() throws LoginException {
076:                // determine the server location
077:                URI location = null;
078:                try {
079:                    location = new URI(serverUri);
080:                } catch (Exception e) {
081:                    if (serverUri.indexOf("://") == -1) {
082:                        try {
083:                            location = new URI("foo://" + serverUri);
084:                        } catch (URISyntaxException giveUp) {
085:                            throw new LoginException(
086:                                    "Invalid openejb.server.uri " + serverUri);
087:                        }
088:                    }
089:                }
090:                ServerMetaData server = new ServerMetaData(location);
091:
092:                // create the callbacks
093:                Callback[] callbacks = new Callback[2];
094:                callbacks[0] = new NameCallback("Username: ");
095:                callbacks[1] = new PasswordCallback("Password: ", false);
096:
097:                // get the call back values (username and password)
098:                try {
099:                    callbackHandler.handle(callbacks);
100:                } catch (IOException ioe) {
101:                    throw new LoginException(ioe.getMessage());
102:                } catch (UnsupportedCallbackException uce) {
103:                    throw new LoginException(uce.getMessage()
104:                            + " not available to obtain information from user");
105:                }
106:                user = ((NameCallback) callbacks[0]).getName();
107:                char[] tmpPassword = ((PasswordCallback) callbacks[1])
108:                        .getPassword();
109:                if (tmpPassword == null)
110:                    tmpPassword = new char[0];
111:
112:                if (realmNameSeparator != null) {
113:                    String[] strings = user.split(realmNameSeparator);
114:                    if (strings.length == 2) {
115:                        realmName = strings[0];
116:                        user = strings[1];
117:                    }
118:                }
119:
120:                if (realmName != null) {
121:                    clientIdentity = ClientSecurity.directAuthentication(
122:                            realmName, user, new String(tmpPassword), server);
123:                } else {
124:                    clientIdentity = ClientSecurity.directAuthentication(user,
125:                            new String(tmpPassword), server);
126:                }
127:
128:                if (debug) {
129:                    log.config("login " + user);
130:                }
131:                return true;
132:            }
133:
134:            public boolean commit() throws LoginException {
135:                principal = new ClientIdentityPrincipal(user, clientIdentity);
136:                subject.getPrincipals().add(principal);
137:
138:                if (debug) {
139:                    log.config("commit");
140:                }
141:                return true;
142:            }
143:
144:            public boolean abort() throws LoginException {
145:                clear();
146:
147:                if (debug) {
148:                    log.config("abort");
149:                }
150:                return true;
151:            }
152:
153:            public boolean logout() throws LoginException {
154:                subject.getPrincipals().remove(principal);
155:
156:                if (debug) {
157:                    log.config("logout");
158:                }
159:                return true;
160:            }
161:
162:            private void clear() {
163:                user = null;
164:                clientIdentity = null;
165:                principal = null;
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.