Source Code Cross Referenced for LoginContextTestCase.java in  » EJB-Server-JBoss-4.2.1 » security » org » jboss » test » 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 » EJB Server JBoss 4.2.1 » security » org.jboss.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test;
023:
024:        import java.util.Iterator;
025:        import java.util.Set;
026:        import javax.security.auth.login.Configuration;
027:        import javax.security.auth.login.LoginContext;
028:        import javax.security.auth.login.LoginException;
029:        import javax.security.auth.Subject;
030:
031:        import junit.framework.TestCase;
032:
033:        import org.jboss.security.auth.login.XMLLoginConfigImpl;
034:        import org.jboss.security.SimplePrincipal;
035:
036:        public class LoginContextTestCase extends TestCase {
037:
038:            public LoginContextTestCase(String name) {
039:                super (name);
040:            }
041:
042:            protected void setUp() throws Exception {
043:                System.setOut(System.err);
044:                XMLLoginConfigImpl config = new XMLLoginConfigImpl();
045:                config.setConfigResource("login-config.xml");
046:                config.loadConfig();
047:                Configuration.setConfiguration(config);
048:            }
049:
050:            private void validateSuccessfulLogin(LoginContext lc)
051:                    throws LoginException {
052:                Subject subject = lc.getSubject();
053:                assertTrue("case5 subject != null", subject != null);
054:                boolean hasGuest = subject.getPrincipals().contains(
055:                        new SimplePrincipal("guest"));
056:                assertTrue("subject has guest principal", hasGuest);
057:                lc.logout();
058:                hasGuest = subject.getPrincipals().contains(
059:                        new SimplePrincipal("guest"));
060:                assertTrue("subject has guest principal", hasGuest == false);
061:                Set publicCreds = subject.getPublicCredentials();
062:                assertTrue("public creds has 'A public credential'",
063:                        publicCreds.contains("A public credential"));
064:                Set privateCreds = subject.getPrivateCredentials();
065:                assertTrue("private creds has 'A private credential'",
066:                        privateCreds.contains("A private credential"));
067:                Iterator iter = privateCreds.iterator();
068:                int count = 0;
069:                while (iter.hasNext()) {
070:                    iter.next();
071:                    count++;
072:                }
073:                assertTrue("private creds has 1 entry", count == 1);
074:            }
075:
076:            public void testCase1() throws Exception {
077:                LoginContext lc = new LoginContext("case1");
078:                lc.login();
079:                validateSuccessfulLogin(lc);
080:            }
081:
082:            public void testCase2() throws Exception {
083:                LoginContext lc = new LoginContext("case2");
084:                lc.login();
085:                validateSuccessfulLogin(lc);
086:            }
087:
088:            public void testCase3() throws Exception {
089:                LoginContext lc = new LoginContext("case3");
090:                try {
091:                    lc.login();
092:                    fail("LoginContext.login3 did not thrown an exception");
093:                } catch (LoginException e) {
094:                    e.printStackTrace();
095:                }
096:            }
097:
098:            /** This should fail because no login module succeeds
099:             *
100:             * @throws Exception
101:             */
102:            public void testCase4() throws Exception {
103:                LoginContext lc = new LoginContext("case4");
104:                try {
105:                    lc.login();
106:                    fail("LoginContext.login4 did not thrown an exception");
107:                } catch (LoginException e) {
108:                    e.printStackTrace();
109:                }
110:            }
111:
112:            public void testCase5() throws Exception {
113:                LoginContext lc = new LoginContext("case5");
114:                lc.login();
115:                validateSuccessfulLogin(lc);
116:            }
117:
118:            public void testCase6() throws Exception {
119:                LoginContext lc = new LoginContext("case6");
120:                lc.login();
121:                validateSuccessfulLogin(lc);
122:            }
123:
124:            public void testCase7() throws Exception {
125:                LoginContext lc = new LoginContext("case7");
126:                lc.login();
127:                validateSuccessfulLogin(lc);
128:            }
129:
130:            public void testCase8() throws Exception {
131:                LoginContext lc = new LoginContext("case8");
132:                try {
133:                    lc.login();
134:                    fail("LoginContext.login8 did not thrown an exception");
135:                } catch (LoginException e) {
136:                    e.printStackTrace();
137:                }
138:            }
139:
140:            public void testCase9() throws Exception {
141:                LoginContext lc = new LoginContext("case9");
142:                lc.login();
143:                validateSuccessfulLogin(lc);
144:            }
145:
146:            public void testCase10() throws Exception {
147:                LoginContext lc = new LoginContext("case10");
148:                try {
149:                    lc.login();
150:                    fail("LoginContext.login10 did not thrown an exception");
151:                } catch (LoginException e) {
152:                    e.printStackTrace();
153:                }
154:            }
155:
156:            public void testCase11() throws Exception {
157:                LoginContext lc = new LoginContext("case11");
158:                lc.login();
159:                validateSuccessfulLogin(lc);
160:            }
161:
162:            public void testCase12() throws Exception {
163:                LoginContext lc = new LoginContext("case12");
164:                lc.login();
165:                validateSuccessfulLogin(lc);
166:            }
167:
168:            public void testCase13() throws Exception {
169:                LoginContext lc = new LoginContext("case13");
170:                try {
171:                    lc.login();
172:                    fail("LoginContext.login13 did not thrown an exception");
173:                } catch (LoginException e) {
174:                    e.printStackTrace();
175:                }
176:            }
177:
178:            public void testCase14() throws Exception {
179:                LoginContext lc = new LoginContext("case14");
180:                try {
181:                    lc.login();
182:                    fail("LoginContext.login14 did not thrown an exception");
183:                } catch (LoginException e) {
184:                    e.printStackTrace();
185:                }
186:            }
187:
188:            public void testCase15() throws Exception {
189:                LoginContext lc = new LoginContext("case15");
190:                try {
191:                    lc.login();
192:                    fail("LoginContext.login15 did not thrown an exception");
193:                } catch (LoginException e) {
194:                    e.printStackTrace();
195:                }
196:            }
197:
198:            public void testCase16() throws Exception {
199:                LoginContext lc = new LoginContext("case16");
200:                lc.login();
201:                validateSuccessfulLogin(lc);
202:            }
203:
204:            public void testCase17() throws Exception {
205:                LoginContext lc = new LoginContext("case17");
206:                lc.login();
207:                validateSuccessfulLogin(lc);
208:            }
209:
210:            public void testCase18() throws Exception {
211:                LoginContext lc = new LoginContext("case18");
212:                try {
213:                    lc.login();
214:                    fail("LoginContext.login18 did not thrown an exception");
215:                } catch (LoginException e) {
216:                    e.printStackTrace();
217:                }
218:            }
219:
220:            public void testCase19() throws Exception {
221:                LoginContext lc = new LoginContext("case19");
222:                try {
223:                    lc.login();
224:                    fail("LoginContext.login19 did not thrown an exception");
225:                } catch (LoginException e) {
226:                    e.printStackTrace();
227:                }
228:            }
229:
230:            public void testCase20() throws Exception {
231:                LoginContext lc = new LoginContext("case20");
232:                try {
233:                    lc.login();
234:                    fail("LoginContext.login20 did not thrown an exception");
235:                } catch (LoginException e) {
236:                    e.printStackTrace();
237:                }
238:            }
239:
240:            public void testCase21() throws Exception {
241:                LoginContext lc = new LoginContext("case21");
242:                try {
243:                    lc.login();
244:                } catch (LoginException e) {
245:                    e.printStackTrace();
246:                }
247:                Subject subject = lc.getSubject();
248:                assertTrue("case21 subject == null", subject == null);
249:            }
250:
251:            public void testCase22() throws Exception {
252:                LoginContext lc = new LoginContext("case22");
253:                try {
254:                    lc.login();
255:                    fail("LoginContext.login22 did not thrown an exception");
256:                } catch (LoginException e) {
257:                    e.printStackTrace();
258:                }
259:            }
260:
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.