Source Code Cross Referenced for SecuredCASLR.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jtests » beans » jca15 » 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 » JOnAS 4.8.6 » org.objectweb.jonas.jtests.beans.jca15 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // SecuredCASLR.java
002:        // Stateless Session bean
003:
004:        package org.objectweb.jonas.jtests.beans.jca15;
005:
006:        import java.rmi.RemoteException;
007:        import javax.ejb.CreateException;
008:        import javax.ejb.EJBException;
009:        import javax.ejb.RemoveException;
010:        import javax.ejb.EJBObject;
011:        import javax.ejb.SessionBean;
012:        import javax.ejb.SessionContext;
013:        import javax.naming.Context;
014:        import javax.naming.InitialContext;
015:        import javax.naming.NamingException;
016:        import javax.sql.DataSource;
017:        import ersatz.resourceadapter.*;
018:        import javax.resource.cci.Connection;
019:        import javax.resource.spi.ManagedConnection;
020:        import javax.resource.spi.ConnectionEvent;
021:        import javax.resource.spi.ConnectionManager;
022:
023:        /**
024:         *
025:         */
026:        public class SecuredCASLR implements  SessionBean {
027:
028:            SessionContext ejbContext;
029:            private ManagedConnectionFactoryImpl mcf = null; //Managed Connection Factory
030:            private ConnectionFactoryImpl cccf = null; //Common Client Connection Factory
031:            private ConnectionImpl conn = null;
032:            private ConnectionRequestInfoImpl crii = null;
033:            InitialContext ic = null;
034:            private String res_auth = "";
035:            String cName = "SecuredCASLR";
036:
037:            // ------------------------------------------------------------------
038:            // SessionBean implementation
039:            // ------------------------------------------------------------------
040:
041:            public void setSessionContext(SessionContext ctx) {
042:                Utility.log(cName + ".setSessionContext");
043:                ejbContext = ctx;
044:            }
045:
046:            public void ejbRemove() {
047:                Utility.log("");
048:            }
049:
050:            public void ejbCreate() throws CreateException {
051:                Utility.log("");
052:            }
053:
054:            public void ejbPassivate() {
055:                Utility.log("");
056:            }
057:
058:            public void ejbActivate() {
059:                Utility.log("");
060:            }
061:
062:            /**
063:             * closeUp
064:             */
065:            public void closeUp(int w) {
066:                try {
067:                    if (w > 0) {
068:                        // The CONNECTION_ERROR_OCCURRED indicates that the associated 
069:                        // ManagedConnectionImpl instance is now invalid and unusable.
070:                        conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED);
071:                        Utility.log(cName
072:                                + ".closeUp : closed physical connection");
073:                    } else {
074:                        // The CONNECTION_CLOSED indicates that connection handle
075:                        // is closed, but physical connection still exists
076:                        conn.close();
077:                        Utility.log(cName + ".closeUp : closed connection");
078:                    }
079:                } catch (Exception e) {
080:                    Utility
081:                            .log(cName
082:                                    + ".closeUp error: close handle/physical connection failed");
083:                }
084:            }
085:
086:            public void setResAuth(String ra) {
087:                res_auth = ra; // set to Application or Container
088:            }
089:
090:            public void setMatchNull(boolean b) {
091:                mcf = cccf.getMcf(); // ManagedConnectionFactory    
092:                mcf.setMatchNull(b);
093:            }
094:
095:            // ------------------------------------------------------------------
096:            // secured implementation
097:            // ------------------------------------------------------------------
098:
099:            /**
100:             * method1
101:             */
102:            public void method1(String rar_jndi_name, String testName)
103:                    throws Exception {
104:                Utility.log("============================ " + testName);
105:                try {
106:                    ic = new InitialContext();
107:                } catch (Exception e1) {
108:                    Utility
109:                            .log(cName
110:                                    + ".method1 error: InitialContext failed");
111:                    throw e1;
112:                }
113:                try {
114:                    cccf = (ConnectionFactoryImpl) ic.lookup(rar_jndi_name);
115:                    Utility.log(cName + ".method1 : found " + rar_jndi_name);
116:                } catch (Exception e2) {
117:                    Utility.log(cName + ".method1 error: lookup failed for "
118:                            + rar_jndi_name);
119:                    throw e2;
120:                }
121:
122:                //
123:                // Container-managed sign-on when file "secured.xml" contains line below
124:                //
125:                //   <res-auth>Container</res-auth>
126:                //
127:                try {
128:                    conn = (ConnectionImpl) cccf.getConnection();
129:                    Utility.log(cName
130:                            + ".method1 : getConnection() 'Container' conn="
131:                            + conn);
132:
133:                    if (conn == null) {
134:                        Utility
135:                                .log(cName
136:                                        + ".method1 error: getConnection returned null connection.");
137:                        throw new Exception("");
138:                    }
139:                } catch (Exception e4) {
140:                    Utility.log(cName + ".method1 error: getConnection failed "
141:                            + e4.toString());
142:                    throw e4;
143:                }
144:            }
145:
146:            public String getResAuth() {
147:                try {
148:                    ManagedConnectionImpl mc = conn.getMC();
149:                    String ra = mc.res_auth; // get real "Application" or "Container"
150:                    Utility.log(cName + ".getResAuth " + "<res-auth>" + ra
151:                            + "</res-auth>");
152:                    if (ra == null || ra.length() == 0)
153:                        throw new Exception("");
154:                    return ra;
155:                } catch (Exception e) {
156:                    Utility.log(cName
157:                            + ".getResAuth error: failed to find <res-auth> "
158:                            + "in ManagedConnectionImpl");
159:                    return "";
160:                }
161:            }
162:
163:            public String getSecurityPassword() {
164:                crii = conn.crii; // look at ConnectionRequestInfoImpl
165:                try {
166:                    ManagedConnectionImpl mc = conn.getMC();
167:                    String pw = crii.getPassword();
168:                    Utility.log(cName + ".getSecurityPassword (" + mc.res_auth
169:                            + ")password=" + pw);
170:                    if (pw == null || pw.length() == 0)
171:                        throw new Exception("");
172:                    return pw;
173:                } catch (Exception e) {
174:                    mcf = cccf.getMcf();
175:                    String pw = mcf.defaultPassword; // find default
176:                    Utility
177:                            .log(cName
178:                                    + ".getSecurityPassword error: failed to find ConnectionRequestInfoImpl "
179:                                    + "instance containing password. Using default="
180:                                    + pw);
181:                    return pw;
182:                }
183:            }
184:
185:            public String getSecurityUserName() {
186:                crii = conn.crii; // look at ConnectionRequestInfoImpl
187:                try {
188:                    ManagedConnectionImpl mc = conn.getMC();
189:                    String u = crii.getUserName();
190:                    Utility.log(cName + ".getSecurityUserName ("
191:                            + mcf.getRes_Auth() + ")userName=" + u);
192:                    if (u == null || u.length() == 0)
193:                        throw new Exception("");
194:                    return u;
195:                } catch (Exception e) {
196:                    mcf = cccf.getMcf();
197:                    String u = mcf.defaultUserName; // find default
198:                    Utility
199:                            .log(cName
200:                                    + ".getSecurityUserName error: failed to find ConnectionRequestInfoImpl "
201:                                    + "instance containing userName. Using default="
202:                                    + u);
203:                    return u;
204:                }
205:            }
206:
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.