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


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