Source Code Cross Referenced for SubjectTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » security » auth » 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 » Apache Harmony Java SE » javax package » javax.security.auth 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:
0018:        /**
0019:         * @author Stepan M. Mishura
0020:         * @version $Revision$
0021:         */package javax.security.auth;
0022:
0023:        import java.io.ByteArrayInputStream;
0024:        import java.io.ByteArrayOutputStream;
0025:        import java.io.NotSerializableException;
0026:        import java.io.ObjectInputStream;
0027:        import java.io.ObjectOutputStream;
0028:        import java.io.Serializable;
0029:        import java.security.AccessControlContext;
0030:        import java.security.AccessControlException;
0031:        import java.security.AccessController;
0032:        import java.security.Principal;
0033:        import java.security.PrivilegedAction;
0034:        import java.security.PrivilegedActionException;
0035:        import java.security.PrivilegedExceptionAction;
0036:        import java.security.SecurityPermission;
0037:        import java.util.HashSet;
0038:        import java.util.Iterator;
0039:        import java.util.NoSuchElementException;
0040:        import java.util.Set;
0041:
0042:        import org.apache.harmony.auth.internal.SecurityTest;
0043:
0044:        import junit.framework.Test;
0045:        import junit.framework.TestSuite;
0046:
0047:        /**
0048:         * Tests Subject and its inner classes implementation. 
0049:         */
0050:
0051:        public class SubjectTest extends SecurityTest {
0052:
0053:            private static final Principal principal = new Principal() {
0054:                public String getName() {
0055:                    return "name";
0056:                }
0057:            };
0058:
0059:            PrivilegedAction<Object> emptyPAction = new PrivilegedAction<Object>() {
0060:                public Object run() {
0061:                    return null;
0062:                }
0063:            };
0064:
0065:            PrivilegedExceptionAction<Object> emptyPEAction = new PrivilegedExceptionAction<Object>() {
0066:                public Object run() {
0067:                    return null;
0068:                }
0069:            };
0070:
0071:            PrivilegedAction<AccessControlContext> contextPAction = new PrivilegedAction<AccessControlContext>() {
0072:                public AccessControlContext run() {
0073:                    return AccessController.getContext();
0074:                }
0075:            };
0076:
0077:            PrivilegedExceptionAction<AccessControlContext> contextPEAction = new PrivilegedExceptionAction<AccessControlContext>() {
0078:                public AccessControlContext run() {
0079:                    return AccessController.getContext();
0080:                }
0081:            };
0082:
0083:            PrivilegedAction<Subject> subjectPAction = new PrivilegedAction<Subject>() {
0084:                public Subject run() {
0085:                    return Subject.getSubject(AccessController.getContext());
0086:                }
0087:            };
0088:
0089:            PrivilegedExceptionAction<Subject> subjectPEAction = new PrivilegedExceptionAction<Subject>() {
0090:                public Subject run() {
0091:                    return Subject.getSubject(AccessController.getContext());
0092:                }
0093:            };
0094:
0095:            private final HashSet<Principal> h1 = new HashSet<Principal>(); // principals
0096:
0097:            private final HashSet<Object> h2 = new HashSet<Object>(); // public credentials
0098:
0099:            private final HashSet<Object> h3 = new HashSet<Object>(); // private credentials
0100:
0101:            public static Test suite() throws Exception {
0102:
0103:                TestSuite setSuite = new TestSuite("SubjectSets");
0104:
0105:                setSuite.addTest(new PrincipalTestSuite());
0106:                setSuite.addTest(new PrivateCredentialTestSuite());
0107:                setSuite.addTest(new PublicCredentialTestSuite());
0108:
0109:                setSuite.addTest(new PrincipalClassTestSuite());
0110:                setSuite.addTest(new PrivateCredentialClassTestSuite());
0111:                setSuite.addTest(new PublicCredentialClassTestSuite());
0112:
0113:                TestSuite suite = new TestSuite("Subject");
0114:
0115:                suite.addTestSuite(javax.security.auth.SubjectTest.class);
0116:                suite.addTest(setSuite);
0117:
0118:                return suite;
0119:            }
0120:
0121:            public SubjectTest() {
0122:                super ();
0123:
0124:                h1.add(principal);
0125:
0126:                h2.add(new Object());
0127:                h2.add(new Object());
0128:
0129:                h3.add(new Object());
0130:                h3.add(new Object());
0131:                h3.add(new Object());
0132:            }
0133:
0134:            /**
0135:             * Testing Subject() constructor
0136:             */
0137:            public final void testSubject() {
0138:                Subject subject = new Subject();
0139:
0140:                assertFalse("Read only state", subject.isReadOnly());
0141:                assertEquals("Principals set", 0, subject.getPrincipals()
0142:                        .size());
0143:
0144:                assertEquals("Private credential set", 0, subject
0145:                        .getPrivateCredentials().size());
0146:
0147:                assertEquals("Public credential set", 0, subject
0148:                        .getPublicCredentials().size());
0149:            }
0150:
0151:            /**
0152:             * Testing Subject(boolean,Set,Set,Set) constructor
0153:             */
0154:            public final void testSubject_3Set() {
0155:
0156:                Subject subject = new Subject(false, h1, h2, h3);
0157:
0158:                assertFalse("Read only state", subject.isReadOnly());
0159:                assertEquals("Principals set", h1, subject.getPrincipals());
0160:
0161:                assertEquals("Private credential set", h3, subject
0162:                        .getPrivateCredentials());
0163:
0164:                assertEquals("Public credential set", h2, subject
0165:                        .getPublicCredentials());
0166:
0167:                // the same but for read only subject        
0168:                subject = new Subject(true, h1, h2, h3);
0169:
0170:                assertTrue("Read only state", subject.isReadOnly());
0171:
0172:                assertEquals("Principals set", 1, subject.getPrincipals()
0173:                        .size());
0174:
0175:                assertEquals("Private credential set", 3, subject
0176:                        .getPrivateCredentials().size());
0177:
0178:                assertEquals("Public credential set", 2, subject
0179:                        .getPublicCredentials().size());
0180:            }
0181:
0182:            /**
0183:             * Testing Subject(boolean,Set,Set,Set) constructor
0184:             * in restricted security context
0185:             */
0186:            public final void testSubject_3Set_NoPermissions() {
0187:
0188:                // all sets modifications are denied
0189:                denyPermission(new AuthPermission("*"));
0190:
0191:                new Subject(true, h1, h2, h3);
0192:            }
0193:
0194:            /**
0195:             * Testing Subject(boolean,Set,Set,Set) constructor
0196:             * Checks NullPointerException if one of passed set is null
0197:             */
0198:            @SuppressWarnings("unchecked")
0199:            public final void testSubject_3Set_NPE() {
0200:
0201:                try {
0202:                    new Subject(false, null, new HashSet(), new HashSet());
0203:                    fail("No expected NullPointerException");
0204:                } catch (NullPointerException e) {
0205:                }
0206:
0207:                try {
0208:                    new Subject(false, new HashSet(), null, new HashSet());
0209:                    fail("No expected NullPointerException");
0210:                } catch (NullPointerException e) {
0211:                }
0212:
0213:                try {
0214:                    new Subject(false, new HashSet(), new HashSet(), null);
0215:                    fail("No expected NullPointerException");
0216:                } catch (NullPointerException e) {
0217:                }
0218:            }
0219:
0220:            /**
0221:             * Testing Subject(boolean,Set,Set,Set) constructor.
0222:             * Parameter set contains an invalid element.
0223:             */
0224:            @SuppressWarnings("unchecked")
0225:            public final void testSubject_3Set_InvalidSet() {
0226:                HashSet hash = new HashSet();
0227:
0228:                hash.add(null);
0229:
0230:                try {
0231:                    new Subject(false, hash, new HashSet(), new HashSet());
0232:
0233:                    if (!testing) {
0234:                        // possible to add 'null' principal via constructor
0235:                        fail("No expected NullPointerException");
0236:                    }
0237:                } catch (NullPointerException e) {
0238:                }
0239:
0240:                try {
0241:                    new Subject(false, new HashSet(), hash, new HashSet());
0242:
0243:                    if (!testing) {
0244:                        fail("No expected NullPointerException");
0245:                    }
0246:                } catch (NullPointerException e) {
0247:                }
0248:
0249:                try {
0250:                    new Subject(false, new HashSet(), new HashSet(), hash);
0251:
0252:                    if (!testing) {
0253:                        fail("No expected NullPointerException");
0254:                    }
0255:                } catch (NullPointerException e) {
0256:                }
0257:
0258:                hash.clear();
0259:                hash.add(new Object());
0260:                try {
0261:                    new Subject(false, hash, new HashSet(), new HashSet());
0262:
0263:                    if (!testing) {
0264:                        // possible to add 'null' principal via constructor
0265:                        fail("No expected IllegalArgumentException");
0266:                    }
0267:                } catch (IllegalArgumentException e) {
0268:                }
0269:            }
0270:
0271:            /**
0272:             * Tests SecurityException for Subject.doAs(Subject,PrivilegedAction)
0273:             */
0274:            public final void testACE_doAs_A() throws Exception {
0275:
0276:                denyPermission(new AuthPermission("doAs"));
0277:                try {
0278:                    Subject.doAs(new Subject(), emptyPAction);
0279:                    fail("No expected AccessControlException");
0280:                } catch (AccessControlException e) {
0281:                    assertEquals(e, AuthPermission.class);
0282:                }
0283:            }
0284:
0285:            /**
0286:             * Tests SecurityException for Subject.doAs(Subject,PrivilegedExceptionAction)
0287:             */
0288:            public final void testACE_doAs_EA() throws Exception {
0289:
0290:                denyPermission(new AuthPermission("doAs"));
0291:                try {
0292:                    Subject.doAs(new Subject(), emptyPEAction);
0293:                    fail("No expected AccessControlException");
0294:                } catch (AccessControlException e) {
0295:                    assertEquals(e, AuthPermission.class);
0296:                } catch (PrivilegedActionException e) {
0297:                    fail("Unexpected PrivilegedActionException");
0298:                }
0299:            }
0300:
0301:            /**
0302:             * Tests SecurityException for Subject.doAsPrivileged(
0303:             *     Subject,PrivilegedAction,AccessControlContext)
0304:             */
0305:            public final void testACE_doAsPrivileged_A() throws Exception {
0306:
0307:                denyPermission(new AuthPermission("doAsPrivileged"));
0308:                try {
0309:                    Subject.doAsPrivileged(new Subject(), emptyPAction, null);
0310:                    fail("No expected AccessControlException");
0311:                } catch (AccessControlException e) {
0312:                    assertEquals(e, AuthPermission.class);
0313:                }
0314:            }
0315:
0316:            /**
0317:             * Tests SecurityException for Subject.doAsPrivileged(
0318:             *     Subject,PrivilegedExceptionAction,AccessControlContext)
0319:             */
0320:            public final void testACE_doAsPrivileged_EA() throws Exception {
0321:
0322:                denyPermission(new AuthPermission("doAsPrivileged"));
0323:                try {
0324:                    Subject.doAsPrivileged(new Subject(), emptyPEAction, null);
0325:                    fail("No expected AccessControlException");
0326:                } catch (AccessControlException e) {
0327:                    assertEquals(e, AuthPermission.class);
0328:                }
0329:            }
0330:
0331:            /**
0332:             * Tests SecurityException for Subject.getSubject()
0333:             */
0334:            public final void testACE_getSubject() {
0335:
0336:                denyPermission(new AuthPermission("getSubject"));
0337:                try {
0338:                    Subject.getSubject(AccessController.getContext());
0339:                    fail("No expected AccessControlException");
0340:                } catch (AccessControlException e) {
0341:                    assertEquals(e, AuthPermission.class);
0342:                }
0343:            }
0344:
0345:            /**
0346:             * Tests SecurityException for Subject.setReadOnly()
0347:             */
0348:            public final void testACE_setReadOnly() {
0349:
0350:                denyPermission(new AuthPermission("setReadOnly"));
0351:                try {
0352:                    (new Subject()).setReadOnly();
0353:                    fail("No expected AccessControlException");
0354:                } catch (AccessControlException e) {
0355:                    assertEquals(e, AuthPermission.class);
0356:                }
0357:            }
0358:
0359:            /**
0360:             * Tests Subject.doAs(Subject, PrivilegedAction)
0361:             */
0362:            public final void testDoAs() {
0363:
0364:                Subject subject = new Subject();
0365:
0366:                Subject contextSubject = (Subject) Subject.doAs(subject,
0367:                        subjectPAction);
0368:
0369:                assertTrue("Returned subject", subject == contextSubject);
0370:
0371:                // null subject
0372:                contextSubject = (Subject) Subject.doAs(null, subjectPAction);
0373:
0374:                assertNull("Subject is null", contextSubject);
0375:
0376:                // null subject: check combiner (must be null)
0377:                AccessControlContext context = (AccessControlContext) Subject
0378:                        .doAs(null, contextPAction);
0379:
0380:                assertNull("Combiner for null subject", context
0381:                        .getDomainCombiner());
0382:            }
0383:
0384:            /**
0385:             * Tests Subject.doAs(Subject, PrivilegedExceptionAction)
0386:             */
0387:            public final void testDoAs_PEA() throws Exception {
0388:
0389:                Subject subject = new Subject();
0390:
0391:                Subject contextSubject = (Subject) Subject.doAs(subject,
0392:                        subjectPEAction);
0393:
0394:                assertTrue("Returned subject", subject == contextSubject);
0395:
0396:                // null subject 
0397:                contextSubject = (Subject) Subject.doAs(null, subjectPEAction);
0398:
0399:                assertNull("Subject is null", contextSubject);
0400:
0401:                // null subject: check combiner (must be null)
0402:                AccessControlContext context = (AccessControlContext) Subject
0403:                        .doAs(null, contextPEAction);
0404:
0405:                assertNull("Combiner for null subject", context
0406:                        .getDomainCombiner());
0407:
0408:            }
0409:
0410:            /**
0411:             * Tests Subject.doAsPrivileged(Subject, PrivilegedAction, ACContext)
0412:             */
0413:            public final void testDoAsPrivileged() {
0414:
0415:                Subject subject = new Subject();
0416:
0417:                Subject contextSubject = (Subject) Subject.doAsPrivileged(
0418:                        subject, subjectPAction, null);
0419:
0420:                assertTrue("Returned subject", subject == contextSubject);
0421:
0422:                // null subject
0423:                contextSubject = (Subject) Subject.doAsPrivileged(null,
0424:                        subjectPAction, null);
0425:
0426:                assertNull("Subject is null", contextSubject);
0427:
0428:                // null subject: check combiner (must be null)
0429:                AccessControlContext context = (AccessControlContext) Subject
0430:                        .doAsPrivileged(null, contextPAction, null);
0431:
0432:                assertNull("Combiner for null subject", context
0433:                        .getDomainCombiner());
0434:            }
0435:
0436:            /**
0437:             * Tests Subject.doAsPrivileged(Subject, PEAction, ACContext)
0438:             */
0439:            public final void testDoAsPrivileged_PEA() throws Exception {
0440:
0441:                Subject subject = new Subject();
0442:
0443:                Subject contextSubject = (Subject) Subject.doAsPrivileged(
0444:                        subject, subjectPEAction, null);
0445:
0446:                assertTrue("Returned subject", subject == contextSubject);
0447:
0448:                // null subject
0449:                contextSubject = (Subject) Subject.doAsPrivileged(null,
0450:                        subjectPEAction, null);
0451:
0452:                assertNull("Subject is null", contextSubject);
0453:
0454:                // null subject: check combiner (must be null)
0455:                AccessControlContext context = (AccessControlContext) Subject
0456:                        .doAsPrivileged(null, contextPEAction, null);
0457:
0458:                assertNull("Combiner for null subject", context
0459:                        .getDomainCombiner());
0460:            }
0461:
0462:            /**
0463:             * Tests Subject.doAs* methods for creating new context
0464:             * 
0465:             * Expected: no SecurityException
0466:             */
0467:            public final void testDoAs_newACC() throws Exception {
0468:
0469:                Subject subject = new Subject();
0470:
0471:                Subject.doAs(subject, emptyPAction);
0472:                Subject.doAs(subject, emptyPEAction);
0473:                Subject.doAsPrivileged(subject, emptyPAction, null);
0474:                Subject.doAsPrivileged(subject, emptyPEAction, null);
0475:
0476:                // each doAs* creates new ACContext 
0477:                denyPermission(new SecurityPermission(
0478:                        "createAccessControlContext"));
0479:
0480:                try {
0481:                    Subject.doAs(subject, emptyPAction);
0482:                    fail("No expected AccessControlException");
0483:                } catch (AccessControlException e) {
0484:                }
0485:
0486:                try {
0487:                    Subject.doAs(subject, emptyPEAction);
0488:                    fail("No expected AccessControlException");
0489:                } catch (AccessControlException e) {
0490:                }
0491:
0492:                try {
0493:                    Subject.doAsPrivileged(subject, emptyPAction, null);
0494:                    fail("No expected AccessControlException");
0495:                } catch (AccessControlException e) {
0496:                }
0497:
0498:                try {
0499:                    Subject.doAsPrivileged(subject, emptyPEAction, null);
0500:                    fail("No expected AccessControlException");
0501:                } catch (AccessControlException e) {
0502:                }
0503:            }
0504:
0505:            /**
0506:             * Tests Subject.equals() method
0507:             */
0508:            @SuppressWarnings("unchecked")
0509:            public final void testEquals() {
0510:
0511:                // empty sets
0512:                Subject s1 = new Subject();
0513:                Subject s2 = new Subject(false, new HashSet(), new HashSet(),
0514:                        new HashSet());
0515:                Subject s3 = new Subject(true, new HashSet(), new HashSet(),
0516:                        new HashSet());
0517:
0518:                equalsTest(s1, s2, s3);
0519:
0520:                // non empty sets
0521:
0522:                s1 = new Subject(false, h1, h2, h3);
0523:                s3 = new Subject(true, h1, h2, h3);
0524:
0525:                s2 = new Subject();
0526:                s2.getPrincipals().addAll(h1);
0527:                s2.getPublicCredentials().addAll(h2);
0528:                s2.getPrivateCredentials().addAll(h3);
0529:
0530:                equalsTest(s1, s2, s3);
0531:
0532:                // not equal subjects
0533:                s1 = new Subject();
0534:                s2 = new Subject(true, h1, new HashSet(), h3);
0535:                s3 = new Subject(true, h1, h2, h3);
0536:
0537:                assertFalse(s1.equals(s2));
0538:                assertFalse(s1.equals(s3));
0539:                assertFalse(s2.equals(s3));
0540:            }
0541:
0542:            private void equalsTest(Object obj1, Object obj2, Object obj3) {
0543:
0544:                // Check passed parameters.
0545:                // Because we don't verify Object.equals() method
0546:                if (obj1 == obj2 || obj1 == obj3 || obj2 == obj3) {
0547:                    throw new AssertionError("References MUST be different");
0548:                }
0549:
0550:                // reflexivity
0551:                assertTrue(obj1.equals(obj1));
0552:
0553:                // symmetry
0554:                assertTrue(obj1.equals(obj2));
0555:                assertTrue(obj2.equals(obj1));
0556:
0557:                // transitivity
0558:                assertTrue(obj1.equals(obj2));
0559:                assertTrue(obj2.equals(obj3));
0560:                assertTrue(obj1.equals(obj3));
0561:
0562:                // consistency
0563:                assertTrue(obj3.equals(obj1));
0564:                assertTrue(obj3.equals(obj1));
0565:
0566:                // null value
0567:                assertFalse(obj1.equals(null));
0568:            }
0569:
0570:            /**
0571:             * Verifies that Subject.equals() has defined comparison algorism.
0572:             * 
0573:             * The sequence of checks is following:
0574:             * 1)principal set
0575:             * 2)public credential set
0576:             * 3)private credential set
0577:             */
0578:            @SuppressWarnings("unchecked")
0579:            public final void testEquals_VerifyCheckSequence() {
0580:
0581:                grantMode(); // no permissions
0582:
0583:                HashSet hash = new HashSet();
0584:                hash.add(principal);
0585:
0586:                Subject subject1 = new Subject(false, new HashSet(),
0587:                        new HashSet(), hash);
0588:
0589:                //doesn't verify private credential permissions on itself
0590:                assertTrue(subject1.equals(subject1));
0591:
0592:                // principals comparison goes before
0593:                // no SecurityException expected 
0594:                Subject subject2 = new Subject(false, hash, new HashSet(), hash);
0595:
0596:                assertFalse(subject1.equals(subject2));
0597:
0598:                // public credential comparison goes before
0599:                // no SecurityException expected 
0600:                subject2 = new Subject(false, new HashSet(), hash, hash);
0601:
0602:                assertFalse(subject1.equals(subject2));
0603:
0604:                // principal and public credentials sets are equal
0605:                // Expected: SecurityException
0606:                subject2 = new Subject(false, new HashSet(), new HashSet(),
0607:                        hash);
0608:                try {
0609:                    subject1.equals(subject2);
0610:                    fail("No expected AccessControlException");
0611:                } catch (AccessControlException e) {
0612:                    assertEquals(e, PrivateCredentialPermission.class);
0613:                }
0614:            }
0615:
0616:            /**
0617:             * Verifies no PrivateCredentialPermission
0618:             * for 'this' subject and provided subject
0619:             */
0620:            public final void testEquals_NoPCP() {
0621:
0622:                Subject subThis = new Subject();
0623:                Subject subThat = new Subject();
0624:
0625:                subThis.getPrivateCredentials().add(new MyClass1());
0626:                subThat.getPrivateCredentials().add(new Object());
0627:
0628:                grantMode(); // no permissions
0629:                grantPermission(new PrivateCredentialPermission(
0630:                        "java.lang.Object * \"*\"", "read"));
0631:
0632:                // verify permissions
0633:                try {
0634:                    subThis.getPrivateCredentials().iterator().next();
0635:                    fail("No expected AccessControlException");
0636:                } catch (AccessControlException e) {
0637:                    assertEquals(e, PrivateCredentialPermission.class);
0638:                }
0639:                subThat.getPrivateCredentials().iterator().next();
0640:
0641:                // 'this' subject doesn't have permission
0642:                try {
0643:                    subThis.equals(subThat);
0644:                    fail("No expected AccessControlException");
0645:                } catch (AccessControlException e) {
0646:                    assertEquals(e, PrivateCredentialPermission.class);
0647:                }
0648:
0649:                // provided subject doesn't have permission
0650:                try {
0651:                    subThat.equals(subThis);
0652:                    fail("No expected AccessControlException");
0653:                } catch (AccessControlException e) {
0654:                    assertEquals(e, PrivateCredentialPermission.class);
0655:                }
0656:            }
0657:
0658:            /**
0659:             * Tests Subject.get<set>(Class) methods
0660:             */
0661:            @SuppressWarnings("unchecked")
0662:            public final void testGetSetClass() {
0663:                HashSet hash = new HashSet();
0664:
0665:                MyClass1 p1 = new MyClass1();
0666:                MyClass1 p2 = new MyClass1();
0667:
0668:                hash.add(p1);
0669:                hash.add(p2);
0670:
0671:                HashSet h = new HashSet();
0672:
0673:                h.add(principal);
0674:                h.addAll(hash);
0675:                h.add(new MyClass2());
0676:
0677:                Subject subject = new Subject(true, h, h, h);
0678:
0679:                assertEquals("Principal", hash, subject
0680:                        .getPrincipals(MyClass1.class));
0681:                assertEquals("Private Credentials", hash, subject
0682:                        .getPrivateCredentials(MyClass1.class));
0683:                assertEquals("Public Credentials", hash, subject
0684:                        .getPublicCredentials(MyClass1.class));
0685:            }
0686:
0687:            /**
0688:             * Tests Subject.get<set>(Class) methods for null parameter
0689:             */
0690:            public final void testGetClass_NullParameter() {
0691:
0692:                Subject subject = new Subject();
0693:
0694:                try {
0695:                    subject.getPrincipals(null);
0696:                    fail("No expected NullPointerException");
0697:                } catch (NullPointerException e) {
0698:                }
0699:
0700:                try {
0701:                    subject.getPrivateCredentials(null);
0702:                    fail("No expected NullPointerException");
0703:                } catch (NullPointerException e) {
0704:                }
0705:
0706:                try {
0707:                    subject.getPublicCredentials(null);
0708:                    fail("No expected NullPointerException");
0709:                } catch (NullPointerException e) {
0710:                }
0711:            }
0712:
0713:            /**
0714:             * Tests Subject.getSubject() for null parameter
0715:             */
0716:            public final void test_getSubject_NPE() {
0717:                try {
0718:                    Subject.getSubject(null);
0719:                    fail("No expected NullPointerException");
0720:                } catch (NullPointerException e) {
0721:                }
0722:            }
0723:
0724:            /**
0725:             * Tests Subject.getSubject() for current context
0726:             */
0727:            public final void test_getSubject() {
0728:                assertNull("Current context", Subject
0729:                        .getSubject(AccessController.getContext()));
0730:
0731:                try {
0732:                    Subject.getSubject(null);
0733:                    fail("No expected NullPointerException");
0734:                } catch (NullPointerException e) {
0735:                }
0736:            }
0737:
0738:            /**
0739:             * Tests Subject.getSubject() for associated context
0740:             */
0741:            public final void test_getSubject_SameSubject() {
0742:
0743:                Subject subject = new Subject();
0744:
0745:                Subject contextSubject = (Subject) Subject.doAs(subject,
0746:                        subjectPAction);
0747:
0748:                assertTrue("Subject: ", subject == contextSubject);
0749:            }
0750:
0751:            /**
0752:             * Tests Subject.getSubject() for associated context (2 subjects)
0753:             */
0754:            @SuppressWarnings("unchecked")
0755:            public final void test_getSubject_NotSameSubject() {
0756:
0757:                final HashSet hash = new HashSet();
0758:                hash.add(new MyClass1());
0759:
0760:                PrivilegedAction<Object> action = new PrivilegedAction<Object>() {
0761:                    public Object run() {
0762:
0763:                        return Subject.doAs(
0764:                                new Subject(false, hash, hash, hash),
0765:                                subjectPAction);
0766:                    }
0767:                };
0768:
0769:                Subject subject = new Subject();
0770:
0771:                Subject contextSubject = (Subject) Subject
0772:                        .doAs(subject, action);
0773:
0774:                assertNotNull("Context subject: ", contextSubject);
0775:                assertFalse("Subject: ", subject == contextSubject);
0776:                assertTrue("Principals: ", hash.equals(contextSubject
0777:                        .getPrincipals()));
0778:                assertTrue("Private Credentials: ", hash.equals(contextSubject
0779:                        .getPrivateCredentials()));
0780:                assertTrue("Public Credentials: ", hash.equals(contextSubject
0781:                        .getPublicCredentials()));
0782:            }
0783:
0784:            /**
0785:             * Tests Subject.getSubject() for privileged action in associated context
0786:             */
0787:            public final void test_getSubject_PrivilegedAction() {
0788:
0789:                PrivilegedAction<Object> action = new PrivilegedAction<Object>() {
0790:                    public Object run() {
0791:                        return AccessController.doPrivileged(subjectPAction);
0792:                    }
0793:                };
0794:
0795:                Subject subject = new Subject();
0796:
0797:                Subject contextSubject = (Subject) Subject
0798:                        .doAs(subject, action);
0799:
0800:                assertNull("Context subject: ", contextSubject);
0801:            }
0802:
0803:            /**
0804:             * Tests Subject.hashCode()
0805:             */
0806:            public final void testHashCode() {
0807:                Subject subject1 = new Subject(false, h1, h2, h3);
0808:                Subject subject2 = new Subject(true, h1, h2, h3);
0809:
0810:                assertTrue(subject1.equals(subject2));
0811:                assertTrue(subject1.hashCode() == subject2.hashCode());
0812:            }
0813:
0814:            /**
0815:             * Tests Subject.hashCode() for SecurityException
0816:             */
0817:            public final void testHashCode_ACE() {
0818:
0819:                grantMode();
0820:                try {
0821:                    (new Subject(false, h1, h2, h3)).hashCode();
0822:
0823:                    if (!testing) {
0824:                        fail("No expected AccessControlException");
0825:                    }
0826:                } catch (AccessControlException e) {
0827:                    assertEquals(e, PrivateCredentialPermission.class);
0828:                }
0829:            }
0830:
0831:            /**
0832:             * Tests Subject.isReadOnly() and Subject.setReadOnly()
0833:             */
0834:            public final void testSetReadOnly_isReadOnly() {
0835:                Subject subject = new Subject();
0836:
0837:                // check initialized value
0838:                assertFalse("Read only state", subject.isReadOnly());
0839:
0840:                // set the subject as read only
0841:                subject.setReadOnly();
0842:                assertTrue("Read only state", subject.isReadOnly());
0843:
0844:                // anyway invoke it again to verify subject's state
0845:                subject.setReadOnly();
0846:                assertTrue("Read only state", subject.isReadOnly());
0847:            }
0848:
0849:            public final void testToString() {
0850:                //FIXME        grantMode();
0851:                //denyPermission(new PrivateCredentialPermission("* * \"*\"", "read"));
0852:                //System.out.println((new Subject(false, h1, h2, h3)).toString());
0853:            }
0854:
0855:            public final void testSerialization() throws Exception {
0856:
0857:                Subject subject = new Subject();
0858:
0859:                subject.getPrincipals().add(new MyClass2());
0860:
0861:                ByteArrayOutputStream out = new ByteArrayOutputStream();
0862:                ObjectOutputStream sOut = new ObjectOutputStream(out);
0863:
0864:                try {
0865:                    sOut.writeObject(subject);
0866:                    fail("No expected NotSerializableException");
0867:                } catch (NotSerializableException e) {
0868:                } finally {
0869:                    sOut.close();
0870:                }
0871:
0872:                subject = new Subject();
0873:
0874:                subject.getPrincipals().add(new MyClass1());
0875:                subject.getPublicCredentials().add(new MyClass1());
0876:                subject.getPrivateCredentials().add(new MyClass1());
0877:
0878:                subject.setReadOnly();
0879:
0880:                out = new ByteArrayOutputStream();
0881:                sOut = new ObjectOutputStream(out);
0882:
0883:                sOut.writeObject(subject);
0884:
0885:                sOut.flush();
0886:                sOut.close();
0887:
0888:                ByteArrayInputStream in = new ByteArrayInputStream(out
0889:                        .toByteArray());
0890:                ObjectInputStream sIn = new ObjectInputStream(in);
0891:
0892:                Subject ss = (Subject) sIn.readObject();
0893:
0894:                assertTrue(ss.isReadOnly());
0895:                assertEquals(1, ss.getPrincipals().size());
0896:                assertTrue(ss.getPrincipals().iterator().next() instanceof  MyClass1);
0897:                assertEquals(0, ss.getPublicCredentials().size());
0898:                assertEquals(0, ss.getPrivateCredentials().size());
0899:
0900:                try {
0901:                    ss.getPrincipals().add(new MyClass1());
0902:                    fail("No expected IllegalStateException");
0903:                } catch (IllegalStateException e) {
0904:                }
0905:            }
0906:
0907:            /**
0908:             * Test subject's deserialization in case of invalid('null') principals
0909:             * 
0910:             * Serialization byte array contains null element in principal set
0911:             * The array is invalid because it is not possible to add null element
0912:             * to principal set via public API methods.
0913:             */
0914:            public final void testSerialization_NullPrincipal()
0915:                    throws Exception {
0916:
0917:                // The array was produced in the following way:
0918:                // 1) A check that verifies a passed principal object for null
0919:                //    value was disabled in Subject class.
0920:                // 2) Subject object was created
0921:                // 3) A null was added to subject's principal set by invoking
0922:                //        getPrincipals().add(null);
0923:                // 4) ByteArrayOutputStream class was used to write subject object
0924:                //    and to get resulting array of bytes 
0925:                byte[] nullPrincipal = new byte[] { (byte) 0xac, (byte) 0xed,
0926:                        (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72,
0927:                        (byte) 0x00, (byte) 0x1b, (byte) 0x6a, (byte) 0x61,
0928:                        (byte) 0x76, (byte) 0x61, (byte) 0x78, (byte) 0x2e,
0929:                        (byte) 0x73, (byte) 0x65, (byte) 0x63, (byte) 0x75,
0930:                        (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79,
0931:                        (byte) 0x2e, (byte) 0x61, (byte) 0x75, (byte) 0x74,
0932:                        (byte) 0x68, (byte) 0x2e, (byte) 0x53, (byte) 0x75,
0933:                        (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63,
0934:                        (byte) 0x74, (byte) 0x8c, (byte) 0xb2, (byte) 0x32,
0935:                        (byte) 0x93, (byte) 0x00, (byte) 0x33, (byte) 0xfa,
0936:                        (byte) 0x68, (byte) 0x03, (byte) 0x00, (byte) 0x02,
0937:                        (byte) 0x5a, (byte) 0x00, (byte) 0x0a, (byte) 0x69,
0938:                        (byte) 0x73, (byte) 0x52, (byte) 0x65, (byte) 0x61,
0939:                        (byte) 0x64, (byte) 0x4f, (byte) 0x6e, (byte) 0x6c,
0940:                        (byte) 0x79, (byte) 0x4c, (byte) 0x00, (byte) 0x0a,
0941:                        (byte) 0x70, (byte) 0x72, (byte) 0x69, (byte) 0x6e,
0942:                        (byte) 0x63, (byte) 0x69, (byte) 0x70, (byte) 0x61,
0943:                        (byte) 0x6c, (byte) 0x73, (byte) 0x74, (byte) 0x00,
0944:                        (byte) 0x0f, (byte) 0x4c, (byte) 0x6a, (byte) 0x61,
0945:                        (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x75,
0946:                        (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x2f,
0947:                        (byte) 0x53, (byte) 0x65, (byte) 0x74, (byte) 0x3b,
0948:                        (byte) 0x78, (byte) 0x70, (byte) 0x00, (byte) 0x73,
0949:                        (byte) 0x72, (byte) 0x00, (byte) 0x25, (byte) 0x6a,
0950:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x78,
0951:                        (byte) 0x2e, (byte) 0x73, (byte) 0x65, (byte) 0x63,
0952:                        (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74,
0953:                        (byte) 0x79, (byte) 0x2e, (byte) 0x61, (byte) 0x75,
0954:                        (byte) 0x74, (byte) 0x68, (byte) 0x2e, (byte) 0x53,
0955:                        (byte) 0x75, (byte) 0x62, (byte) 0x6a, (byte) 0x65,
0956:                        (byte) 0x63, (byte) 0x74, (byte) 0x24, (byte) 0x53,
0957:                        (byte) 0x65, (byte) 0x63, (byte) 0x75, (byte) 0x72,
0958:                        (byte) 0x65, (byte) 0x53, (byte) 0x65, (byte) 0x74,
0959:                        (byte) 0x6d, (byte) 0xcc, (byte) 0x32, (byte) 0x80,
0960:                        (byte) 0x17, (byte) 0x55, (byte) 0x7e, (byte) 0x27,
0961:                        (byte) 0x03, (byte) 0x00, (byte) 0x03, (byte) 0x49,
0962:                        (byte) 0x00, (byte) 0x07, (byte) 0x73, (byte) 0x65,
0963:                        (byte) 0x74, (byte) 0x54, (byte) 0x79, (byte) 0x70,
0964:                        (byte) 0x65, (byte) 0x4c, (byte) 0x00, (byte) 0x08,
0965:                        (byte) 0x65, (byte) 0x6c, (byte) 0x65, (byte) 0x6d,
0966:                        (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x73,
0967:                        (byte) 0x74, (byte) 0x00, (byte) 0x16, (byte) 0x4c,
0968:                        (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
0969:                        (byte) 0x2f, (byte) 0x75, (byte) 0x74, (byte) 0x69,
0970:                        (byte) 0x6c, (byte) 0x2f, (byte) 0x4c, (byte) 0x69,
0971:                        (byte) 0x6e, (byte) 0x6b, (byte) 0x65, (byte) 0x64,
0972:                        (byte) 0x4c, (byte) 0x69, (byte) 0x73, (byte) 0x74,
0973:                        (byte) 0x3b, (byte) 0x4c, (byte) 0x00, (byte) 0x06,
0974:                        (byte) 0x74, (byte) 0x68, (byte) 0x69, (byte) 0x73,
0975:                        (byte) 0x24, (byte) 0x30, (byte) 0x74, (byte) 0x00,
0976:                        (byte) 0x1d, (byte) 0x4c, (byte) 0x6a, (byte) 0x61,
0977:                        (byte) 0x76, (byte) 0x61, (byte) 0x78, (byte) 0x2f,
0978:                        (byte) 0x73, (byte) 0x65, (byte) 0x63, (byte) 0x75,
0979:                        (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79,
0980:                        (byte) 0x2f, (byte) 0x61, (byte) 0x75, (byte) 0x74,
0981:                        (byte) 0x68, (byte) 0x2f, (byte) 0x53, (byte) 0x75,
0982:                        (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63,
0983:                        (byte) 0x74, (byte) 0x3b, (byte) 0x78, (byte) 0x70,
0984:                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
0985:                        (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x14,
0986:                        (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
0987:                        (byte) 0x2e, (byte) 0x75, (byte) 0x74, (byte) 0x69,
0988:                        (byte) 0x6c, (byte) 0x2e, (byte) 0x4c, (byte) 0x69,
0989:                        (byte) 0x6e, (byte) 0x6b, (byte) 0x65, (byte) 0x64,
0990:                        (byte) 0x4c, (byte) 0x69, (byte) 0x73, (byte) 0x74,
0991:                        (byte) 0x0c, (byte) 0x29, (byte) 0x53, (byte) 0x5d,
0992:                        (byte) 0x4a, (byte) 0x60, (byte) 0x88, (byte) 0x22,
0993:                        (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x78,
0994:                        (byte) 0x70, (byte) 0x77, (byte) 0x04, (byte) 0x00,
0995:                        (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x70,
0996:                        (byte) 0x78, (byte) 0x71, (byte) 0x00, (byte) 0x7e,
0997:                        (byte) 0x00, (byte) 0x02, (byte) 0x78, (byte) 0x78 };
0998:
0999:                ByteArrayInputStream in = new ByteArrayInputStream(
1000:                        nullPrincipal);
1001:                ObjectInputStream sIn = new ObjectInputStream(in);
1002:
1003:                try {
1004:                    sIn.readObject();
1005:                    if (!testing) {
1006:                        fail("No expected NullPointerException");
1007:                    }
1008:                } catch (NullPointerException e) {
1009:                }
1010:            }
1011:
1012:            /**
1013:             * Test subject's deserialization in case of invalid principals
1014:             * Byte stream contains object in principal set that doesn't
1015:             * implement Principal interface.
1016:             * The array is invalid because it is not possible to add such object
1017:             * to principal set via public API methods.
1018:             */
1019:            public final void testSerialization_IllegalPrincipal()
1020:                    throws Exception {
1021:
1022:                // The array was produced in the following way:
1023:                // 1) A check for verifying that passed principal object 
1024:                //    implements Principal interface was disabled in Subject class.
1025:                // 2) Subject object was created
1026:                // 3) A serializable object was added to subject's principal
1027:                //    set by invoking: getPrincipals().add(object);
1028:                // 4) ByteArrayOutputStream class was used to write subject object
1029:                //    and to get resulting array of bytes 
1030:                byte[] objectPrincipal = new byte[] { (byte) 0xac, (byte) 0xed,
1031:                        (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72,
1032:                        (byte) 0x00, (byte) 0x1b, (byte) 0x6a, (byte) 0x61,
1033:                        (byte) 0x76, (byte) 0x61, (byte) 0x78, (byte) 0x2e,
1034:                        (byte) 0x73, (byte) 0x65, (byte) 0x63, (byte) 0x75,
1035:                        (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79,
1036:                        (byte) 0x2e, (byte) 0x61, (byte) 0x75, (byte) 0x74,
1037:                        (byte) 0x68, (byte) 0x2e, (byte) 0x53, (byte) 0x75,
1038:                        (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63,
1039:                        (byte) 0x74, (byte) 0x8c, (byte) 0xb2, (byte) 0x32,
1040:                        (byte) 0x93, (byte) 0x00, (byte) 0x33, (byte) 0xfa,
1041:                        (byte) 0x68, (byte) 0x03, (byte) 0x00, (byte) 0x02,
1042:                        (byte) 0x5a, (byte) 0x00, (byte) 0x0a, (byte) 0x69,
1043:                        (byte) 0x73, (byte) 0x52, (byte) 0x65, (byte) 0x61,
1044:                        (byte) 0x64, (byte) 0x4f, (byte) 0x6e, (byte) 0x6c,
1045:                        (byte) 0x79, (byte) 0x4c, (byte) 0x00, (byte) 0x0a,
1046:                        (byte) 0x70, (byte) 0x72, (byte) 0x69, (byte) 0x6e,
1047:                        (byte) 0x63, (byte) 0x69, (byte) 0x70, (byte) 0x61,
1048:                        (byte) 0x6c, (byte) 0x73, (byte) 0x74, (byte) 0x00,
1049:                        (byte) 0x0f, (byte) 0x4c, (byte) 0x6a, (byte) 0x61,
1050:                        (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x75,
1051:                        (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x2f,
1052:                        (byte) 0x53, (byte) 0x65, (byte) 0x74, (byte) 0x3b,
1053:                        (byte) 0x78, (byte) 0x70, (byte) 0x00, (byte) 0x73,
1054:                        (byte) 0x72, (byte) 0x00, (byte) 0x25, (byte) 0x6a,
1055:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x78,
1056:                        (byte) 0x2e, (byte) 0x73, (byte) 0x65, (byte) 0x63,
1057:                        (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74,
1058:                        (byte) 0x79, (byte) 0x2e, (byte) 0x61, (byte) 0x75,
1059:                        (byte) 0x74, (byte) 0x68, (byte) 0x2e, (byte) 0x53,
1060:                        (byte) 0x75, (byte) 0x62, (byte) 0x6a, (byte) 0x65,
1061:                        (byte) 0x63, (byte) 0x74, (byte) 0x24, (byte) 0x53,
1062:                        (byte) 0x65, (byte) 0x63, (byte) 0x75, (byte) 0x72,
1063:                        (byte) 0x65, (byte) 0x53, (byte) 0x65, (byte) 0x74,
1064:                        (byte) 0x6d, (byte) 0xcc, (byte) 0x32, (byte) 0x80,
1065:                        (byte) 0x17, (byte) 0x55, (byte) 0x7e, (byte) 0x27,
1066:                        (byte) 0x03, (byte) 0x00, (byte) 0x03, (byte) 0x49,
1067:                        (byte) 0x00, (byte) 0x07, (byte) 0x73, (byte) 0x65,
1068:                        (byte) 0x74, (byte) 0x54, (byte) 0x79, (byte) 0x70,
1069:                        (byte) 0x65, (byte) 0x4c, (byte) 0x00, (byte) 0x08,
1070:                        (byte) 0x65, (byte) 0x6c, (byte) 0x65, (byte) 0x6d,
1071:                        (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x73,
1072:                        (byte) 0x74, (byte) 0x00, (byte) 0x16, (byte) 0x4c,
1073:                        (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
1074:                        (byte) 0x2f, (byte) 0x75, (byte) 0x74, (byte) 0x69,
1075:                        (byte) 0x6c, (byte) 0x2f, (byte) 0x4c, (byte) 0x69,
1076:                        (byte) 0x6e, (byte) 0x6b, (byte) 0x65, (byte) 0x64,
1077:                        (byte) 0x4c, (byte) 0x69, (byte) 0x73, (byte) 0x74,
1078:                        (byte) 0x3b, (byte) 0x4c, (byte) 0x00, (byte) 0x06,
1079:                        (byte) 0x74, (byte) 0x68, (byte) 0x69, (byte) 0x73,
1080:                        (byte) 0x24, (byte) 0x30, (byte) 0x74, (byte) 0x00,
1081:                        (byte) 0x1d, (byte) 0x4c, (byte) 0x6a, (byte) 0x61,
1082:                        (byte) 0x76, (byte) 0x61, (byte) 0x78, (byte) 0x2f,
1083:                        (byte) 0x73, (byte) 0x65, (byte) 0x63, (byte) 0x75,
1084:                        (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79,
1085:                        (byte) 0x2f, (byte) 0x61, (byte) 0x75, (byte) 0x74,
1086:                        (byte) 0x68, (byte) 0x2f, (byte) 0x53, (byte) 0x75,
1087:                        (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63,
1088:                        (byte) 0x74, (byte) 0x3b, (byte) 0x78, (byte) 0x70,
1089:                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
1090:                        (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x14,
1091:                        (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
1092:                        (byte) 0x2e, (byte) 0x75, (byte) 0x74, (byte) 0x69,
1093:                        (byte) 0x6c, (byte) 0x2e, (byte) 0x4c, (byte) 0x69,
1094:                        (byte) 0x6e, (byte) 0x6b, (byte) 0x65, (byte) 0x64,
1095:                        (byte) 0x4c, (byte) 0x69, (byte) 0x73, (byte) 0x74,
1096:                        (byte) 0x0c, (byte) 0x29, (byte) 0x53, (byte) 0x5d,
1097:                        (byte) 0x4a, (byte) 0x60, (byte) 0x88, (byte) 0x22,
1098:                        (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x78,
1099:                        (byte) 0x70, (byte) 0x77, (byte) 0x04, (byte) 0x00,
1100:                        (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x73,
1101:                        (byte) 0x72, (byte) 0x00, (byte) 0x28, (byte) 0x6a,
1102:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x78,
1103:                        (byte) 0x2e, (byte) 0x73, (byte) 0x65, (byte) 0x63,
1104:                        (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74,
1105:                        (byte) 0x79, (byte) 0x2e, (byte) 0x61, (byte) 0x75,
1106:                        (byte) 0x74, (byte) 0x68, (byte) 0x2e, (byte) 0x53,
1107:                        (byte) 0x75, (byte) 0x62, (byte) 0x6a, (byte) 0x65,
1108:                        (byte) 0x63, (byte) 0x74, (byte) 0x54, (byte) 0x65,
1109:                        (byte) 0x73, (byte) 0x74, (byte) 0x24, (byte) 0x4d,
1110:                        (byte) 0x79, (byte) 0x4f, (byte) 0x62, (byte) 0x6a,
1111:                        (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0xf7,
1112:                        (byte) 0xbc, (byte) 0xdc, (byte) 0x95, (byte) 0xb2,
1113:                        (byte) 0x33, (byte) 0x3a, (byte) 0x0f, (byte) 0x02,
1114:                        (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70,
1115:                        (byte) 0x78, (byte) 0x71, (byte) 0x00, (byte) 0x7e,
1116:                        (byte) 0x00, (byte) 0x02, (byte) 0x78, (byte) 0x78 };
1117:
1118:                ByteArrayInputStream in = new ByteArrayInputStream(
1119:                        objectPrincipal);
1120:                ObjectInputStream sIn = new ObjectInputStream(in);
1121:
1122:                try {
1123:                    sIn.readObject();
1124:                    if (!testing) {
1125:                        fail("No expected IllegalArgumentException");
1126:                    }
1127:                } catch (IllegalArgumentException e) {
1128:                }
1129:            }
1130:
1131:            /**
1132:             * Test subject's principal set deserialization in case
1133:             * of invalid principal set's elements. Two cases are tested:
1134:             * 1) null object
1135:             * 2) an object in principal set that doesn't implement Principal interface.
1136:             */
1137:            public void test_PrincipalSetInvalidSerForm() throws Exception {
1138:
1139:                // The array was produced in the following way:
1140:                // 1) A check that verifies a passed principal object for null
1141:                //    value was disabled in Subject class.
1142:                // 2) Subject object was created
1143:                // 3) A null was added to subject's principal set by invoking
1144:                //        getPrincipals().add(null);
1145:                // 4) ByteArrayOutputStream class was used to write
1146:                //    subject's principal set object and to get resulting array of bytes 
1147:                byte[] nullElement = new byte[] { (byte) 0xac, (byte) 0xed,
1148:                        (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72,
1149:                        (byte) 0x00, (byte) 0x25, (byte) 0x6a, (byte) 0x61,
1150:                        (byte) 0x76, (byte) 0x61, (byte) 0x78, (byte) 0x2e,
1151:                        (byte) 0x73, (byte) 0x65, (byte) 0x63, (byte) 0x75,
1152:                        (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79,
1153:                        (byte) 0x2e, (byte) 0x61, (byte) 0x75, (byte) 0x74,
1154:                        (byte) 0x68, (byte) 0x2e, (byte) 0x53, (byte) 0x75,
1155:                        (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63,
1156:                        (byte) 0x74, (byte) 0x24, (byte) 0x53, (byte) 0x65,
1157:                        (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x65,
1158:                        (byte) 0x53, (byte) 0x65, (byte) 0x74, (byte) 0x6d,
1159:                        (byte) 0xcc, (byte) 0x32, (byte) 0x80, (byte) 0x17,
1160:                        (byte) 0x55, (byte) 0x7e, (byte) 0x27, (byte) 0x03,
1161:                        (byte) 0x00, (byte) 0x02, (byte) 0x4c, (byte) 0x00,
1162:                        (byte) 0x08, (byte) 0x65, (byte) 0x6c, (byte) 0x65,
1163:                        (byte) 0x6d, (byte) 0x65, (byte) 0x6e, (byte) 0x74,
1164:                        (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x16,
1165:                        (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
1166:                        (byte) 0x61, (byte) 0x2f, (byte) 0x75, (byte) 0x74,
1167:                        (byte) 0x69, (byte) 0x6c, (byte) 0x2f, (byte) 0x4c,
1168:                        (byte) 0x69, (byte) 0x6e, (byte) 0x6b, (byte) 0x65,
1169:                        (byte) 0x64, (byte) 0x4c, (byte) 0x69, (byte) 0x73,
1170:                        (byte) 0x74, (byte) 0x3b, (byte) 0x4c, (byte) 0x00,
1171:                        (byte) 0x06, (byte) 0x74, (byte) 0x68, (byte) 0x69,
1172:                        (byte) 0x73, (byte) 0x24, (byte) 0x30, (byte) 0x74,
1173:                        (byte) 0x00, (byte) 0x1d, (byte) 0x4c, (byte) 0x6a,
1174:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x78,
1175:                        (byte) 0x2f, (byte) 0x73, (byte) 0x65, (byte) 0x63,
1176:                        (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74,
1177:                        (byte) 0x79, (byte) 0x2f, (byte) 0x61, (byte) 0x75,
1178:                        (byte) 0x74, (byte) 0x68, (byte) 0x2f, (byte) 0x53,
1179:                        (byte) 0x75, (byte) 0x62, (byte) 0x6a, (byte) 0x65,
1180:                        (byte) 0x63, (byte) 0x74, (byte) 0x3b, (byte) 0x78,
1181:                        (byte) 0x70, (byte) 0x73, (byte) 0x72, (byte) 0x00,
1182:                        (byte) 0x14, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
1183:                        (byte) 0x61, (byte) 0x2e, (byte) 0x75, (byte) 0x74,
1184:                        (byte) 0x69, (byte) 0x6c, (byte) 0x2e, (byte) 0x4c,
1185:                        (byte) 0x69, (byte) 0x6e, (byte) 0x6b, (byte) 0x65,
1186:                        (byte) 0x64, (byte) 0x4c, (byte) 0x69, (byte) 0x73,
1187:                        (byte) 0x74, (byte) 0x0c, (byte) 0x29, (byte) 0x53,
1188:                        (byte) 0x5d, (byte) 0x4a, (byte) 0x60, (byte) 0x88,
1189:                        (byte) 0x22, (byte) 0x03, (byte) 0x00, (byte) 0x00,
1190:                        (byte) 0x78, (byte) 0x70, (byte) 0x77, (byte) 0x04,
1191:                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
1192:                        (byte) 0x70, (byte) 0x78, (byte) 0x73, (byte) 0x72,
1193:                        (byte) 0x00, (byte) 0x1b, (byte) 0x6a, (byte) 0x61,
1194:                        (byte) 0x76, (byte) 0x61, (byte) 0x78, (byte) 0x2e,
1195:                        (byte) 0x73, (byte) 0x65, (byte) 0x63, (byte) 0x75,
1196:                        (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79,
1197:                        (byte) 0x2e, (byte) 0x61, (byte) 0x75, (byte) 0x74,
1198:                        (byte) 0x68, (byte) 0x2e, (byte) 0x53, (byte) 0x75,
1199:                        (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63,
1200:                        (byte) 0x74, (byte) 0x8c, (byte) 0xb2, (byte) 0x32,
1201:                        (byte) 0x93, (byte) 0x00, (byte) 0x33, (byte) 0xfa,
1202:                        (byte) 0x68, (byte) 0x03, (byte) 0x00, (byte) 0x02,
1203:                        (byte) 0x5a, (byte) 0x00, (byte) 0x0a, (byte) 0x69,
1204:                        (byte) 0x73, (byte) 0x52, (byte) 0x65, (byte) 0x61,
1205:                        (byte) 0x64, (byte) 0x4f, (byte) 0x6e, (byte) 0x6c,
1206:                        (byte) 0x79, (byte) 0x4c, (byte) 0x00, (byte) 0x0a,
1207:                        (byte) 0x70, (byte) 0x72, (byte) 0x69, (byte) 0x6e,
1208:                        (byte) 0x63, (byte) 0x69, (byte) 0x70, (byte) 0x61,
1209:                        (byte) 0x6c, (byte) 0x73, (byte) 0x74, (byte) 0x00,
1210:                        (byte) 0x0f, (byte) 0x4c, (byte) 0x6a, (byte) 0x61,
1211:                        (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x75,
1212:                        (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x2f,
1213:                        (byte) 0x53, (byte) 0x65, (byte) 0x74, (byte) 0x3b,
1214:                        (byte) 0x78, (byte) 0x70, (byte) 0x00, (byte) 0x71,
1215:                        (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x03,
1216:                        (byte) 0x78, (byte) 0x78 };
1217:
1218:                // The array was produced in the following way:
1219:                // 1) A check for verifying that passed principal object 
1220:                //    implements Principal interface was disabled in Subject class.
1221:                // 2) Subject object was created
1222:                // 3) A serializable object was added to subject's principal
1223:                //    set by invoking: getPrincipals().add(object);
1224:                // 4) ByteArrayOutputStream class was used to write
1225:                //    subject's principal set object and to get resulting array of bytes 
1226:                byte[] notPrincipalElement = new byte[] { (byte) 0xac,
1227:                        (byte) 0xed, (byte) 0x00, (byte) 0x05, (byte) 0x73,
1228:                        (byte) 0x72, (byte) 0x00, (byte) 0x25, (byte) 0x6a,
1229:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x78,
1230:                        (byte) 0x2e, (byte) 0x73, (byte) 0x65, (byte) 0x63,
1231:                        (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74,
1232:                        (byte) 0x79, (byte) 0x2e, (byte) 0x61, (byte) 0x75,
1233:                        (byte) 0x74, (byte) 0x68, (byte) 0x2e, (byte) 0x53,
1234:                        (byte) 0x75, (byte) 0x62, (byte) 0x6a, (byte) 0x65,
1235:                        (byte) 0x63, (byte) 0x74, (byte) 0x24, (byte) 0x53,
1236:                        (byte) 0x65, (byte) 0x63, (byte) 0x75, (byte) 0x72,
1237:                        (byte) 0x65, (byte) 0x53, (byte) 0x65, (byte) 0x74,
1238:                        (byte) 0x6d, (byte) 0xcc, (byte) 0x32, (byte) 0x80,
1239:                        (byte) 0x17, (byte) 0x55, (byte) 0x7e, (byte) 0x27,
1240:                        (byte) 0x03, (byte) 0x00, (byte) 0x02, (byte) 0x4c,
1241:                        (byte) 0x00, (byte) 0x08, (byte) 0x65, (byte) 0x6c,
1242:                        (byte) 0x65, (byte) 0x6d, (byte) 0x65, (byte) 0x6e,
1243:                        (byte) 0x74, (byte) 0x73, (byte) 0x74, (byte) 0x00,
1244:                        (byte) 0x16, (byte) 0x4c, (byte) 0x6a, (byte) 0x61,
1245:                        (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x75,
1246:                        (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x2f,
1247:                        (byte) 0x4c, (byte) 0x69, (byte) 0x6e, (byte) 0x6b,
1248:                        (byte) 0x65, (byte) 0x64, (byte) 0x4c, (byte) 0x69,
1249:                        (byte) 0x73, (byte) 0x74, (byte) 0x3b, (byte) 0x4c,
1250:                        (byte) 0x00, (byte) 0x06, (byte) 0x74, (byte) 0x68,
1251:                        (byte) 0x69, (byte) 0x73, (byte) 0x24, (byte) 0x30,
1252:                        (byte) 0x74, (byte) 0x00, (byte) 0x1d, (byte) 0x4c,
1253:                        (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
1254:                        (byte) 0x78, (byte) 0x2f, (byte) 0x73, (byte) 0x65,
1255:                        (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x69,
1256:                        (byte) 0x74, (byte) 0x79, (byte) 0x2f, (byte) 0x61,
1257:                        (byte) 0x75, (byte) 0x74, (byte) 0x68, (byte) 0x2f,
1258:                        (byte) 0x53, (byte) 0x75, (byte) 0x62, (byte) 0x6a,
1259:                        (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x3b,
1260:                        (byte) 0x78, (byte) 0x70, (byte) 0x73, (byte) 0x72,
1261:                        (byte) 0x00, (byte) 0x14, (byte) 0x6a, (byte) 0x61,
1262:                        (byte) 0x76, (byte) 0x61, (byte) 0x2e, (byte) 0x75,
1263:                        (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x2e,
1264:                        (byte) 0x4c, (byte) 0x69, (byte) 0x6e, (byte) 0x6b,
1265:                        (byte) 0x65, (byte) 0x64, (byte) 0x4c, (byte) 0x69,
1266:                        (byte) 0x73, (byte) 0x74, (byte) 0x0c, (byte) 0x29,
1267:                        (byte) 0x53, (byte) 0x5d, (byte) 0x4a, (byte) 0x60,
1268:                        (byte) 0x88, (byte) 0x22, (byte) 0x03, (byte) 0x00,
1269:                        (byte) 0x00, (byte) 0x78, (byte) 0x70, (byte) 0x77,
1270:                        (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
1271:                        (byte) 0x01, (byte) 0x73, (byte) 0x72, (byte) 0x00,
1272:                        (byte) 0x28, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
1273:                        (byte) 0x61, (byte) 0x78, (byte) 0x2e, (byte) 0x73,
1274:                        (byte) 0x65, (byte) 0x63, (byte) 0x75, (byte) 0x72,
1275:                        (byte) 0x69, (byte) 0x74, (byte) 0x79, (byte) 0x2e,
1276:                        (byte) 0x61, (byte) 0x75, (byte) 0x74, (byte) 0x68,
1277:                        (byte) 0x2e, (byte) 0x53, (byte) 0x75, (byte) 0x62,
1278:                        (byte) 0x6a, (byte) 0x65, (byte) 0x63, (byte) 0x74,
1279:                        (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74,
1280:                        (byte) 0x24, (byte) 0x4d, (byte) 0x79, (byte) 0x4f,
1281:                        (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63,
1282:                        (byte) 0x74, (byte) 0xf7, (byte) 0xbc, (byte) 0xdc,
1283:                        (byte) 0x95, (byte) 0xb2, (byte) 0x33, (byte) 0x3a,
1284:                        (byte) 0x0f, (byte) 0x02, (byte) 0x00, (byte) 0x00,
1285:                        (byte) 0x78, (byte) 0x70, (byte) 0x78, (byte) 0x73,
1286:                        (byte) 0x72, (byte) 0x00, (byte) 0x1b, (byte) 0x6a,
1287:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x78,
1288:                        (byte) 0x2e, (byte) 0x73, (byte) 0x65, (byte) 0x63,
1289:                        (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74,
1290:                        (byte) 0x79, (byte) 0x2e, (byte) 0x61, (byte) 0x75,
1291:                        (byte) 0x74, (byte) 0x68, (byte) 0x2e, (byte) 0x53,
1292:                        (byte) 0x75, (byte) 0x62, (byte) 0x6a, (byte) 0x65,
1293:                        (byte) 0x63, (byte) 0x74, (byte) 0x8c, (byte) 0xb2,
1294:                        (byte) 0x32, (byte) 0x93, (byte) 0x00, (byte) 0x33,
1295:                        (byte) 0xfa, (byte) 0x68, (byte) 0x03, (byte) 0x00,
1296:                        (byte) 0x02, (byte) 0x5a, (byte) 0x00, (byte) 0x0a,
1297:                        (byte) 0x69, (byte) 0x73, (byte) 0x52, (byte) 0x65,
1298:                        (byte) 0x61, (byte) 0x64, (byte) 0x4f, (byte) 0x6e,
1299:                        (byte) 0x6c, (byte) 0x79, (byte) 0x4c, (byte) 0x00,
1300:                        (byte) 0x0a, (byte) 0x70, (byte) 0x72, (byte) 0x69,
1301:                        (byte) 0x6e, (byte) 0x63, (byte) 0x69, (byte) 0x70,
1302:                        (byte) 0x61, (byte) 0x6c, (byte) 0x73, (byte) 0x74,
1303:                        (byte) 0x00, (byte) 0x0f, (byte) 0x4c, (byte) 0x6a,
1304:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f,
1305:                        (byte) 0x75, (byte) 0x74, (byte) 0x69, (byte) 0x6c,
1306:                        (byte) 0x2f, (byte) 0x53, (byte) 0x65, (byte) 0x74,
1307:                        (byte) 0x3b, (byte) 0x78, (byte) 0x70, (byte) 0x00,
1308:                        (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00,
1309:                        (byte) 0x03, (byte) 0x78, (byte) 0x78 };
1310:
1311:                ByteArrayInputStream in = new ByteArrayInputStream(nullElement);
1312:                ObjectInputStream sIn = new ObjectInputStream(in);
1313:
1314:                try {
1315:                    sIn.readObject();
1316:                    if (!testing) {
1317:                        fail("No expected NullPointerException");
1318:                    }
1319:                } catch (NullPointerException e) {
1320:                } finally {
1321:                    sIn.close();
1322:                }
1323:
1324:                in = new ByteArrayInputStream(notPrincipalElement);
1325:                sIn = new ObjectInputStream(in);
1326:
1327:                try {
1328:                    sIn.readObject();
1329:                    if (!testing) {
1330:                        fail("No expected IllegalArgumentException");
1331:                    }
1332:                } catch (IllegalArgumentException e) {
1333:                } finally {
1334:                    sIn.close();
1335:                }
1336:            }
1337:
1338:            /**
1339:             * Test subject's private credential set deserialization in case
1340:             * of invalid null element.
1341:             */
1342:            public void test_PrivateCredentialSetInvalidSerForm()
1343:                    throws Exception {
1344:
1345:                // The array was produced in the following way:
1346:                // 1) A check that verifies a passed private credential object for null
1347:                //    value was disabled in Subject class.
1348:                // 2) Subject object was created
1349:                // 3) A null was added to subject's private credential set by invoking
1350:                //        getPrivateCredentials().add(null);
1351:                // 4) ByteArrayOutputStream class was used to write
1352:                //    subject's private credential set object
1353:                //    and to get resulting array of bytes 
1354:                byte[] nullElement = new byte[] { (byte) 0xac, (byte) 0xed,
1355:                        (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72,
1356:                        (byte) 0x00, (byte) 0x25, (byte) 0x6a, (byte) 0x61,
1357:                        (byte) 0x76, (byte) 0x61, (byte) 0x78, (byte) 0x2e,
1358:                        (byte) 0x73, (byte) 0x65, (byte) 0x63, (byte) 0x75,
1359:                        (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79,
1360:                        (byte) 0x2e, (byte) 0x61, (byte) 0x75, (byte) 0x74,
1361:                        (byte) 0x68, (byte) 0x2e, (byte) 0x53, (byte) 0x75,
1362:                        (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63,
1363:                        (byte) 0x74, (byte) 0x24, (byte) 0x53, (byte) 0x65,
1364:                        (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x65,
1365:                        (byte) 0x53, (byte) 0x65, (byte) 0x74, (byte) 0x6d,
1366:                        (byte) 0xcc, (byte) 0x32, (byte) 0x80, (byte) 0x17,
1367:                        (byte) 0x55, (byte) 0x7e, (byte) 0x27, (byte) 0x03,
1368:                        (byte) 0x00, (byte) 0x03, (byte) 0x49, (byte) 0x00,
1369:                        (byte) 0x07, (byte) 0x73, (byte) 0x65, (byte) 0x74,
1370:                        (byte) 0x54, (byte) 0x79, (byte) 0x70, (byte) 0x65,
1371:                        (byte) 0x4c, (byte) 0x00, (byte) 0x08, (byte) 0x65,
1372:                        (byte) 0x6c, (byte) 0x65, (byte) 0x6d, (byte) 0x65,
1373:                        (byte) 0x6e, (byte) 0x74, (byte) 0x73, (byte) 0x74,
1374:                        (byte) 0x00, (byte) 0x16, (byte) 0x4c, (byte) 0x6a,
1375:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f,
1376:                        (byte) 0x75, (byte) 0x74, (byte) 0x69, (byte) 0x6c,
1377:                        (byte) 0x2f, (byte) 0x4c, (byte) 0x69, (byte) 0x6e,
1378:                        (byte) 0x6b, (byte) 0x65, (byte) 0x64, (byte) 0x4c,
1379:                        (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x3b,
1380:                        (byte) 0x4c, (byte) 0x00, (byte) 0x06, (byte) 0x74,
1381:                        (byte) 0x68, (byte) 0x69, (byte) 0x73, (byte) 0x24,
1382:                        (byte) 0x30, (byte) 0x74, (byte) 0x00, (byte) 0x1d,
1383:                        (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
1384:                        (byte) 0x61, (byte) 0x78, (byte) 0x2f, (byte) 0x73,
1385:                        (byte) 0x65, (byte) 0x63, (byte) 0x75, (byte) 0x72,
1386:                        (byte) 0x69, (byte) 0x74, (byte) 0x79, (byte) 0x2f,
1387:                        (byte) 0x61, (byte) 0x75, (byte) 0x74, (byte) 0x68,
1388:                        (byte) 0x2f, (byte) 0x53, (byte) 0x75, (byte) 0x62,
1389:                        (byte) 0x6a, (byte) 0x65, (byte) 0x63, (byte) 0x74,
1390:                        (byte) 0x3b, (byte) 0x78, (byte) 0x70, (byte) 0x00,
1391:                        (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x73,
1392:                        (byte) 0x72, (byte) 0x00, (byte) 0x14, (byte) 0x6a,
1393:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2e,
1394:                        (byte) 0x75, (byte) 0x74, (byte) 0x69, (byte) 0x6c,
1395:                        (byte) 0x2e, (byte) 0x4c, (byte) 0x69, (byte) 0x6e,
1396:                        (byte) 0x6b, (byte) 0x65, (byte) 0x64, (byte) 0x4c,
1397:                        (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x0c,
1398:                        (byte) 0x29, (byte) 0x53, (byte) 0x5d, (byte) 0x4a,
1399:                        (byte) 0x60, (byte) 0x88, (byte) 0x22, (byte) 0x03,
1400:                        (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70,
1401:                        (byte) 0x77, (byte) 0x04, (byte) 0x00, (byte) 0x00,
1402:                        (byte) 0x00, (byte) 0x01, (byte) 0x70, (byte) 0x78,
1403:                        (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x1b,
1404:                        (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
1405:                        (byte) 0x78, (byte) 0x2e, (byte) 0x73, (byte) 0x65,
1406:                        (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x69,
1407:                        (byte) 0x74, (byte) 0x79, (byte) 0x2e, (byte) 0x61,
1408:                        (byte) 0x75, (byte) 0x74, (byte) 0x68, (byte) 0x2e,
1409:                        (byte) 0x53, (byte) 0x75, (byte) 0x62, (byte) 0x6a,
1410:                        (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x8c,
1411:                        (byte) 0xb2, (byte) 0x32, (byte) 0x93, (byte) 0x00,
1412:                        (byte) 0x33, (byte) 0xfa, (byte) 0x68, (byte) 0x03,
1413:                        (byte) 0x00, (byte) 0x02, (byte) 0x5a, (byte) 0x00,
1414:                        (byte) 0x0a, (byte) 0x69, (byte) 0x73, (byte) 0x52,
1415:                        (byte) 0x65, (byte) 0x61, (byte) 0x64, (byte) 0x4f,
1416:                        (byte) 0x6e, (byte) 0x6c, (byte) 0x79, (byte) 0x4c,
1417:                        (byte) 0x00, (byte) 0x0a, (byte) 0x70, (byte) 0x72,
1418:                        (byte) 0x69, (byte) 0x6e, (byte) 0x63, (byte) 0x69,
1419:                        (byte) 0x70, (byte) 0x61, (byte) 0x6c, (byte) 0x73,
1420:                        (byte) 0x74, (byte) 0x00, (byte) 0x0f, (byte) 0x4c,
1421:                        (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
1422:                        (byte) 0x2f, (byte) 0x75, (byte) 0x74, (byte) 0x69,
1423:                        (byte) 0x6c, (byte) 0x2f, (byte) 0x53, (byte) 0x65,
1424:                        (byte) 0x74, (byte) 0x3b, (byte) 0x78, (byte) 0x70,
1425:                        (byte) 0x00, (byte) 0x73, (byte) 0x71, (byte) 0x00,
1426:                        (byte) 0x7e, (byte) 0x00, (byte) 0x00, (byte) 0x00,
1427:                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x73,
1428:                        (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00,
1429:                        (byte) 0x04, (byte) 0x77, (byte) 0x04, (byte) 0x00,
1430:                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x78,
1431:                        (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00,
1432:                        (byte) 0x08, (byte) 0x78, (byte) 0x78, (byte) 0x78 };
1433:
1434:                ByteArrayInputStream in = new ByteArrayInputStream(nullElement);
1435:                ObjectInputStream sIn = new ObjectInputStream(in);
1436:
1437:                try {
1438:                    sIn.readObject();
1439:                    if (!testing) {
1440:                        fail("No expected NullPointerException");
1441:                    }
1442:                } catch (NullPointerException e) {
1443:                } finally {
1444:                    sIn.close();
1445:                }
1446:            }
1447:
1448:            public static class PermissionTest extends SecurityTest {
1449:
1450:                private final Subject subject = new Subject();
1451:
1452:                /*
1453:                 * FIXME??? presence of unaccessible element
1454:                 * forbids all operations except adding new elements  
1455:                 */
1456:                public void testForbiddenElement() {
1457:
1458:                    grantMode(); // no permissions
1459:                    grantPermission(new AuthPermission(
1460:                            "modifyPrivateCredentials"));
1461:
1462:                    Principal privCr1 = new MyClass1();
1463:                    Object privCr2 = new Object();
1464:
1465:                    HashSet<Object> hash = new HashSet<Object>();
1466:                    hash.add(privCr1);
1467:                    hash.add(new Object());
1468:
1469:                    Set<Object> set = subject.getPrivateCredentials();
1470:
1471:                    // Adding is not prohibited
1472:                    set.add(privCr1);
1473:
1474:                    set.add(privCr2);
1475:
1476:                    try {
1477:                        set.clear();
1478:                        fail("No expected AccessControlException");
1479:                    } catch (AccessControlException e) {
1480:                        // PrivateCredentialPermission check goes first
1481:                        assertEquals(e, PrivateCredentialPermission.class);
1482:                    }
1483:
1484:                    try {
1485:                        set.contains(privCr1);
1486:                        fail("No expected AccessControlException");
1487:                    } catch (AccessControlException e) {
1488:                        assertEquals(e, PrivateCredentialPermission.class);
1489:                    }
1490:
1491:                    try {
1492:                        set.contains(new Object());
1493:                        fail("No expected AccessControlException");
1494:                    } catch (AccessControlException e) {
1495:                        assertEquals(e, PrivateCredentialPermission.class);
1496:                    }
1497:
1498:                    assertTrue(set.equals(set));
1499:                    assertFalse(set.equals(new HashSet<Object>()));
1500:                    try {
1501:                        // set with equal size initiates iteration
1502:                        set.equals(hash);
1503:                        fail("No expected AccessControlException");
1504:                    } catch (AccessControlException e) {
1505:                        assertEquals(e, PrivateCredentialPermission.class);
1506:                    }
1507:
1508:                    set.isEmpty();
1509:
1510:                    try {
1511:                        set.hashCode();
1512:                        fail("No expected AccessControlException");
1513:                    } catch (AccessControlException e) {
1514:                        assertEquals(e, PrivateCredentialPermission.class);
1515:                    }
1516:
1517:                    try {
1518:                        set.remove(privCr1);
1519:                        fail("No expected AccessControlException");
1520:                    } catch (AccessControlException e) {
1521:                        // PrivateCredentialPermission check goes first
1522:                        assertEquals(e, PrivateCredentialPermission.class);
1523:                    }
1524:
1525:                    try {
1526:                        set.remove(new Object());
1527:                        fail("No expected AccessControlException");
1528:                    } catch (AccessControlException e) {
1529:                        // PrivateCredentialPermission check goes first
1530:                        assertEquals(e, PrivateCredentialPermission.class);
1531:                    }
1532:
1533:                    try {
1534:                        set.retainAll(new HashSet<Object>());
1535:                        fail("No expected AccessControlException");
1536:                    } catch (AccessControlException e) {
1537:                        // PrivateCredentialPermission check goes first
1538:                        assertEquals(e, PrivateCredentialPermission.class);
1539:                    }
1540:
1541:                    try {
1542:                        set.toArray();
1543:                        fail("No expected AccessControlException");
1544:                    } catch (AccessControlException e) {
1545:                        assertEquals(e, PrivateCredentialPermission.class);
1546:                    }
1547:
1548:                    try {
1549:                        set.toArray(new Object[5]);
1550:                        fail("No expected AccessControlException");
1551:                    } catch (AccessControlException e) {
1552:                        assertEquals(e, PrivateCredentialPermission.class);
1553:                    }
1554:                }
1555:
1556:                public void testIteratorNext_EmptySet() {
1557:
1558:                    grantMode(); // no permissions
1559:                    try {
1560:                        (new Subject()).getPrivateCredentials().iterator()
1561:                                .next();
1562:                        fail("No expected NoSuchElementException");
1563:                    } catch (NoSuchElementException e) {
1564:                    } catch (IndexOutOfBoundsException e) {
1565:                        if (!testing) {
1566:                            throw e;
1567:                        }
1568:                    }
1569:                }
1570:
1571:                public void testIteratorNext() {
1572:
1573:                    subject.getPrincipals().add(new MyClass1());
1574:
1575:                    Set<Object> set = subject.getPrivateCredentials();
1576:
1577:                    Object obj1 = new Object();
1578:                    Object obj2 = new Object();
1579:                    Object obj3 = new Object();
1580:
1581:                    set.add(obj1);
1582:                    set.add(new HashSet<Object>());
1583:                    set.add(obj2);
1584:                    set.add(new HashSet<Object>());
1585:                    set.add(obj3);
1586:
1587:                    grantMode(); // no permissions
1588:
1589:                    HashSet<Object> hash = new HashSet<Object>();
1590:
1591:                    grantPermission(new PrivateCredentialPermission(
1592:                            "java.lang.Object * \"*\"", "read"));
1593:
1594:                    Iterator<Object> it = set.iterator();
1595:                    while (it.hasNext()) {
1596:                        try {
1597:                            hash.add(it.next());
1598:                        } catch (AccessControlException e) {
1599:                            assertEquals(e, PrivateCredentialPermission.class);
1600:                        }
1601:                    }
1602:
1603:                    assertEquals("Size: ", 3, hash.size());
1604:                    assertTrue("1 element", hash.contains(obj1));
1605:                    assertTrue("2 element", hash.contains(obj2));
1606:                    assertTrue("3 element", hash.contains(obj3));
1607:                }
1608:
1609:                public void test_Remove_NotExistingElement_EmptySet() {
1610:
1611:                    denyPermission(new PrivateCredentialPermission("* * \"*\"",
1612:                            "read"));
1613:
1614:                    subject.getPrivateCredentials().remove(new Object());
1615:                }
1616:
1617:                public void test_PrivateCredentialPermission() {
1618:
1619:                    if (!testing) {
1620:                        class P implements  Principal {
1621:                            public String getName() {
1622:                                return "name";
1623:                            }
1624:                        }
1625:
1626:                        P p = new P();
1627:                        HashSet<Principal> hash = new HashSet<Principal>();
1628:                        hash.add(p);
1629:
1630:                        PrivateCredentialPermission p1 = new PrivateCredentialPermission(
1631:                                "java.lang.Object", hash);
1632:
1633:                        PrivateCredentialPermission p2 = new PrivateCredentialPermission(
1634:                                "java.lang.Object " + P.class.getName()
1635:                                        + " \"name\"", "read");
1636:
1637:                        assertTrue(p1.implies(p2));
1638:                        assertTrue(p2.implies(p1));
1639:                    }
1640:
1641:                    PrivateCredentialPermission p3 = new PrivateCredentialPermission(
1642:                            "java.lang.Object * \"*\"", "read");
1643:                    PrivateCredentialPermission p4 = new PrivateCredentialPermission(
1644:                            "java.lang.Object", new HashSet<Principal>());
1645:
1646:                    assertTrue(p3.implies(p4));
1647:                }
1648:
1649:                public void test_Principal() {
1650:
1651:                    Principal p1 = new MyClass1();
1652:                    Principal p2 = new MyClass2();
1653:
1654:                    HashSet<Principal> hash = new HashSet<Principal>();
1655:                    hash.add(p2);
1656:
1657:                    Set<Object> set = subject.getPrivateCredentials();
1658:
1659:                    set.add(new Object());
1660:
1661:                    grantMode(); // no permissions
1662:
1663:                    grantPermission(new AuthPermission("modifyPrincipals"));
1664:                    grantPermission(getPermission("java.lang.Object", hash));
1665:
1666:                    Iterator<Object> it = set.iterator();
1667:                    it.next();
1668:
1669:                    subject.getPrincipals().add(p1);
1670:                    it = set.iterator();
1671:                    try {
1672:                        it.next();
1673:                        fail("No expected AccessControlException");
1674:                    } catch (AccessControlException e) {
1675:                        assertEquals(e, PrivateCredentialPermission.class);
1676:                    }
1677:
1678:                    subject.getPrincipals().add(p2);
1679:
1680:                    it = set.iterator();
1681:                    it.next();
1682:                }
1683:
1684:                public void test_Serialization() throws Exception {
1685:
1686:                    subject.getPrivateCredentials().add(new MyClass1());
1687:
1688:                    denyPermission(new PrivateCredentialPermission("* * \"*\"",
1689:                            "read"));
1690:
1691:                    ByteArrayOutputStream out = new ByteArrayOutputStream();
1692:                    ObjectOutputStream sOut = new ObjectOutputStream(out);
1693:
1694:                    try {
1695:                        sOut.writeObject(subject.getPrivateCredentials());
1696:                        fail("No expected AccessControlException");
1697:                    } catch (AccessControlException e) {
1698:                        assertEquals(e, PrivateCredentialPermission.class);
1699:                    } finally {
1700:                        sOut.close();
1701:                    }
1702:                }
1703:
1704:                @SuppressWarnings("unchecked")
1705:                public void testGetClass() {
1706:
1707:                    HashSet hash = new HashSet();
1708:                    hash.add(new MyClass1());
1709:
1710:                    subject.getPrincipals().add(new MyClass1());
1711:
1712:                    subject.getPrivateCredentials().add(new MyClass1());
1713:                    subject.getPrivateCredentials().add(new MyClass2());
1714:
1715:                    grantMode(); // no permissions
1716:
1717:                    try {
1718:                        subject.getPrivateCredentials(MyClass1.class);
1719:                        fail("No expected AccessControlException");
1720:                    } catch (AccessControlException e) {
1721:                        assertEquals(e, PrivateCredentialPermission.class);
1722:                    }
1723:
1724:                    try {
1725:                        subject.getPrivateCredentials(MyClass2.class);
1726:                        fail("No expected AccessControlException");
1727:                    } catch (AccessControlException e) {
1728:                        assertEquals(e, PrivateCredentialPermission.class);
1729:                    }
1730:
1731:                    // subject hash partial permissions (only for MyClass1 class)
1732:                    grantPermission(getPermission(MyClass1.class.getName(),
1733:                            hash));
1734:
1735:                    // FIXME why security exception is thrown? 
1736:                    // the spec. require permissions for requested class only
1737:                    try {
1738:                        subject.getPrivateCredentials(MyClass1.class);
1739:                        fail("No expected AccessControlException");
1740:                    } catch (AccessControlException e) {
1741:                        assertEquals(e, PrivateCredentialPermission.class);
1742:                    }
1743:
1744:                    try {
1745:                        subject.getPrivateCredentials(MyClass2.class);
1746:                        fail("No expected AccessControlException");
1747:                    } catch (AccessControlException e) {
1748:                        assertEquals(e, PrivateCredentialPermission.class);
1749:                    }
1750:
1751:                    // now subject has all permissions 
1752:                    grantPermission(getPermission(MyClass2.class.getName(),
1753:                            hash));
1754:
1755:                    subject.getPrivateCredentials(MyClass1.class);
1756:                    subject.getPrivateCredentials(MyClass2.class);
1757:                }
1758:
1759:                public PrivateCredentialPermission getPermission(String c,
1760:                        Set<? extends Principal> p) {
1761:                    StringBuffer buf = new StringBuffer(c);
1762:
1763:                    for (Iterator<? extends Principal> it = p.iterator(); it
1764:                            .hasNext();) {
1765:                        Object o = it.next();
1766:                        buf.append(" ");
1767:                        buf.append(o.getClass().getName());
1768:                        buf.append(" \"");
1769:                        buf.append(((Principal) o).getName());
1770:                        buf.append("\"");
1771:                    }
1772:                    return new PrivateCredentialPermission(buf.toString(),
1773:                            "read");
1774:                }
1775:            }
1776:
1777:            /**
1778:             * Test subject's public credential set deserialization in case
1779:             * of invalid null element.
1780:             */
1781:            public void test_PublicCredentialInvalidSerForm() throws Exception {
1782:
1783:                // The array was produced in the following way:
1784:                // 1) A check that verifies a passed public credential object for null
1785:                //    value was disabled in Subject class.
1786:                // 2) Subject object was created
1787:                // 3) A null was added to subject's public credential set by invoking
1788:                //        getPublicCredentials().add(null);
1789:                // 4) ByteArrayOutputStream class was used to write
1790:                //    subject's public credential set object
1791:                //    and to get resulting array of bytes 
1792:                byte[] nullElement = new byte[] { (byte) 0xac, (byte) 0xed,
1793:                        (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72,
1794:                        (byte) 0x00, (byte) 0x25, (byte) 0x6a, (byte) 0x61,
1795:                        (byte) 0x76, (byte) 0x61, (byte) 0x78, (byte) 0x2e,
1796:                        (byte) 0x73, (byte) 0x65, (byte) 0x63, (byte) 0x75,
1797:                        (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79,
1798:                        (byte) 0x2e, (byte) 0x61, (byte) 0x75, (byte) 0x74,
1799:                        (byte) 0x68, (byte) 0x2e, (byte) 0x53, (byte) 0x75,
1800:                        (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63,
1801:                        (byte) 0x74, (byte) 0x24, (byte) 0x53, (byte) 0x65,
1802:                        (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x65,
1803:                        (byte) 0x53, (byte) 0x65, (byte) 0x74, (byte) 0x6d,
1804:                        (byte) 0xcc, (byte) 0x32, (byte) 0x80, (byte) 0x17,
1805:                        (byte) 0x55, (byte) 0x7e, (byte) 0x27, (byte) 0x03,
1806:                        (byte) 0x00, (byte) 0x03, (byte) 0x49, (byte) 0x00,
1807:                        (byte) 0x07, (byte) 0x73, (byte) 0x65, (byte) 0x74,
1808:                        (byte) 0x54, (byte) 0x79, (byte) 0x70, (byte) 0x65,
1809:                        (byte) 0x4c, (byte) 0x00, (byte) 0x08, (byte) 0x65,
1810:                        (byte) 0x6c, (byte) 0x65, (byte) 0x6d, (byte) 0x65,
1811:                        (byte) 0x6e, (byte) 0x74, (byte) 0x73, (byte) 0x74,
1812:                        (byte) 0x00, (byte) 0x16, (byte) 0x4c, (byte) 0x6a,
1813:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f,
1814:                        (byte) 0x75, (byte) 0x74, (byte) 0x69, (byte) 0x6c,
1815:                        (byte) 0x2f, (byte) 0x4c, (byte) 0x69, (byte) 0x6e,
1816:                        (byte) 0x6b, (byte) 0x65, (byte) 0x64, (byte) 0x4c,
1817:                        (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x3b,
1818:                        (byte) 0x4c, (byte) 0x00, (byte) 0x06, (byte) 0x74,
1819:                        (byte) 0x68, (byte) 0x69, (byte) 0x73, (byte) 0x24,
1820:                        (byte) 0x30, (byte) 0x74, (byte) 0x00, (byte) 0x1d,
1821:                        (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
1822:                        (byte) 0x61, (byte) 0x78, (byte) 0x2f, (byte) 0x73,
1823:                        (byte) 0x65, (byte) 0x63, (byte) 0x75, (byte) 0x72,
1824:                        (byte) 0x69, (byte) 0x74, (byte) 0x79, (byte) 0x2f,
1825:                        (byte) 0x61, (byte) 0x75, (byte) 0x74, (byte) 0x68,
1826:                        (byte) 0x2f, (byte) 0x53, (byte) 0x75, (byte) 0x62,
1827:                        (byte) 0x6a, (byte) 0x65, (byte) 0x63, (byte) 0x74,
1828:                        (byte) 0x3b, (byte) 0x78, (byte) 0x70, (byte) 0x00,
1829:                        (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x73,
1830:                        (byte) 0x72, (byte) 0x00, (byte) 0x14, (byte) 0x6a,
1831:                        (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2e,
1832:                        (byte) 0x75, (byte) 0x74, (byte) 0x69, (byte) 0x6c,
1833:                        (byte) 0x2e, (byte) 0x4c, (byte) 0x69, (byte) 0x6e,
1834:                        (byte) 0x6b, (byte) 0x65, (byte) 0x64, (byte) 0x4c,
1835:                        (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x0c,
1836:                        (byte) 0x29, (byte) 0x53, (byte) 0x5d, (byte) 0x4a,
1837:                        (byte) 0x60, (byte) 0x88, (byte) 0x22, (byte) 0x03,
1838:                        (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70,
1839:                        (byte) 0x77, (byte) 0x04, (byte) 0x00, (byte) 0x00,
1840:                        (byte) 0x00, (byte) 0x01, (byte) 0x70, (byte) 0x78,
1841:                        (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x1b,
1842:                        (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
1843:                        (byte) 0x78, (byte) 0x2e, (byte) 0x73, (byte) 0x65,
1844:                        (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x69,
1845:                        (byte) 0x74, (byte) 0x79, (byte) 0x2e, (byte) 0x61,
1846:                        (byte) 0x75, (byte) 0x74, (byte) 0x68, (byte) 0x2e,
1847:                        (byte) 0x53, (byte) 0x75, (byte) 0x62, (byte) 0x6a,
1848:                        (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x8c,
1849:                        (byte) 0xb2, (byte) 0x32, (byte) 0x93, (byte) 0x00,
1850:                        (byte) 0x33, (byte) 0xfa, (byte) 0x68, (byte) 0x03,
1851:                        (byte) 0x00, (byte) 0x02, (byte) 0x5a, (byte) 0x00,
1852:                        (byte) 0x0a, (byte) 0x69, (byte) 0x73, (byte) 0x52,
1853:                        (byte) 0x65, (byte) 0x61, (byte) 0x64, (byte) 0x4f,
1854:                        (byte) 0x6e, (byte) 0x6c, (byte) 0x79, (byte) 0x4c,
1855:                        (byte) 0x00, (byte) 0x0a, (byte) 0x70, (byte) 0x72,
1856:                        (byte) 0x69, (byte) 0x6e, (byte) 0x63, (byte) 0x69,
1857:                        (byte) 0x70, (byte) 0x61, (byte) 0x6c, (byte) 0x73,
1858:                        (byte) 0x74, (byte) 0x00, (byte) 0x0f, (byte) 0x4c,
1859:                        (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
1860:                        (byte) 0x2f, (byte) 0x75, (byte) 0x74, (byte) 0x69,
1861:                        (byte) 0x6c, (byte) 0x2f, (byte) 0x53, (byte) 0x65,
1862:                        (byte) 0x74, (byte) 0x3b, (byte) 0x78, (byte) 0x70,
1863:                        (byte) 0x00, (byte) 0x73, (byte) 0x71, (byte) 0x00,
1864:                        (byte) 0x7e, (byte) 0x00, (byte) 0x00, (byte) 0x00,
1865:                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x73,
1866:                        (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00,
1867:                        (byte) 0x04, (byte) 0x77, (byte) 0x04, (byte) 0x00,
1868:                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x78,
1869:                        (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00,
1870:                        (byte) 0x08, (byte) 0x78, (byte) 0x78, (byte) 0x78 };
1871:
1872:                ByteArrayInputStream in = new ByteArrayInputStream(nullElement);
1873:                ObjectInputStream sIn = new ObjectInputStream(in);
1874:
1875:                try {
1876:                    sIn.readObject();
1877:                    if (!testing) {
1878:                        fail("No expected NullPointerException");
1879:                    }
1880:                } catch (NullPointerException e) {
1881:                } finally {
1882:                    sIn.close();
1883:                }
1884:            }
1885:
1886:            @SuppressWarnings("serial")
1887:            public static class MyClass1 implements  Principal, Serializable {
1888:                public String getName() {
1889:                    return "MyClass1";
1890:                }
1891:            }
1892:
1893:            public static class MyClass2 implements  Principal {
1894:                public String getName() {
1895:                    return "MyClass2";
1896:                }
1897:            }
1898:
1899:            @SuppressWarnings("serial")
1900:            public static class MyObject implements  Serializable {
1901:            }
1902:
1903:            public static class PrincipalTestSuite extends TestSuite {
1904:
1905:                public PrincipalTestSuite() {
1906:                    super ("Principal");
1907:
1908:                    TestSuite iterator = new TestSuite("Iterator");
1909:
1910:                    iterator.addTest(new TestSuite(IteratorInterface.class,
1911:                            "Interface"));
1912:                    iterator.addTest(new TestSuite(IteratorReadOnly.class,
1913:                            "ReadOnly"));
1914:                    iterator.addTest(new TestSuite(IteratorSecure.class,
1915:                            "Secure"));
1916:
1917:                    TestSuite set = new TestSuite("Set");
1918:                    set.addTest(new TestSuite(SetInterface.class, "Interface"));
1919:                    set.addTest(new TestSuite(UnsupportedNull.class,
1920:                            "UnsupportedNull"));
1921:                    set.addTest(new TestSuite(IneligibleElement.class,
1922:                            "IneligibleElement"));
1923:                    set.addTest(new TestSuite(ReadOnlySet.class, "ReadOnly"));
1924:                    set.addTest(new TestSuite(SecureSet.class, "Secure"));
1925:
1926:                    TestSuite object = new TestSuite("Object");
1927:                    object.addTest(new TestSuite(SObjectTest.class, "Object"));
1928:
1929:                    addTest(iterator);
1930:                    addTest(set);
1931:                    addTest(object);
1932:                }
1933:
1934:                public static class IteratorInterface extends
1935:                        SecurityTest.IteratorTest {
1936:                    public IteratorInterface() {
1937:                        set = (new Subject()).getPrincipals();
1938:                        element = principal;
1939:                    }
1940:                }
1941:
1942:                public static class IteratorReadOnly extends
1943:                        SecurityTest.ReadOnlyIteratorTest {
1944:
1945:                    private final Subject subject = new Subject();
1946:
1947:                    public IteratorReadOnly() {
1948:                        set = subject.getPrincipals();
1949:                        element = principal;
1950:                    }
1951:
1952:                    @Override
1953:                    public void setReadOnly() {
1954:                        subject.setReadOnly();
1955:                    }
1956:                }
1957:
1958:                public static class IteratorSecure extends
1959:                        SecurityTest.SecureIteratorTest {
1960:
1961:                    public IteratorSecure() {
1962:                        set = (new Subject()).getPrincipals();
1963:                        element = principal;
1964:                    }
1965:
1966:                    @Override
1967:                    public void setSecure() {
1968:                        denyPermission(new AuthPermission("modifyPrincipals"));
1969:                    }
1970:                }
1971:
1972:                public static class SetInterface extends SecurityTest.SetTest {
1973:                    public SetInterface() {
1974:                        set = (new Subject()).getPrincipals();
1975:                        element = principal;
1976:                    }
1977:                }
1978:
1979:                public static class UnsupportedNull extends
1980:                        SecurityTest.UnsupportedNullTest {
1981:
1982:                    public UnsupportedNull() {
1983:                        set = (new Subject()).getPrincipals();
1984:                        element = principal;
1985:                    }
1986:                }
1987:
1988:                public static class IneligibleElement extends
1989:                        SecurityTest.IneligibleElementTest {
1990:
1991:                    public IneligibleElement() {
1992:                        set = (new Subject()).getPrincipals();
1993:                        element = principal;
1994:                        iElement = new Object();
1995:                    }
1996:                }
1997:
1998:                public static class ReadOnlySet extends
1999:                        SecurityTest.ReadOnlySetTest {
2000:                    private final Subject subject = new Subject();
2001:
2002:                    public ReadOnlySet() {
2003:                        set = subject.getPrincipals();
2004:                        element = principal;
2005:                    }
2006:
2007:                    @Override
2008:                    public void setReadOnly() {
2009:                        subject.setReadOnly();
2010:                    }
2011:                }
2012:
2013:                public static class SecureSet extends
2014:                        SecurityTest.SecureSetTest {
2015:
2016:                    public SecureSet() {
2017:                        set = (new Subject()).getPrincipals();
2018:                        element = principal;
2019:                    }
2020:
2021:                    @Override
2022:                    public void setSecure() {
2023:                        denyPermission(new AuthPermission("modifyPrincipals"));
2024:                    }
2025:                }
2026:
2027:                public static class SObjectTest extends
2028:                        SecurityTest.SubjectSetObjectTest {
2029:                    public SObjectTest() {
2030:                        obj1 = subject.getPrincipals();
2031:
2032:                        //intentionally another set
2033:                        obj2 = subject.getPrivateCredentials();
2034:                    }
2035:                }
2036:            }
2037:
2038:            public static class PrivateCredentialTestSuite extends TestSuite {
2039:
2040:                public PrivateCredentialTestSuite() {
2041:                    super ("PrivateCredential");
2042:
2043:                    TestSuite iterator = new TestSuite("Iterator");
2044:
2045:                    iterator.addTest(new TestSuite(IteratorInterface.class,
2046:                            "Interface"));
2047:                    iterator.addTest(new TestSuite(IteratorReadOnly.class,
2048:                            "ReadOnly"));
2049:                    iterator.addTest(new TestSuite(IteratorSecure.class,
2050:                            "Secure"));
2051:
2052:                    TestSuite set = new TestSuite("Set");
2053:                    set.addTest(new TestSuite(SetInterface.class, "Interface"));
2054:                    set.addTest(new TestSuite(UnsupportedNull.class,
2055:                            "UnsupportedNull"));
2056:                    set.addTest(new TestSuite(ReadOnlySet.class, "ReadOnly"));
2057:                    set.addTest(new TestSuite(SecureSet.class, "Secure"));
2058:                    set.addTest(new TestSuite(PermissionTest.class,
2059:                            "PermissionTest"));
2060:
2061:                    TestSuite object = new TestSuite("Object");
2062:                    object.addTest(new TestSuite(SObjectTest.class, "Object"));
2063:
2064:                    addTest(iterator);
2065:                    addTest(set);
2066:                    addTest(object);
2067:                }
2068:
2069:                public static class IteratorInterface extends
2070:                        SecurityTest.IteratorTest {
2071:                    public IteratorInterface() {
2072:                        set = (new Subject()).getPrivateCredentials();
2073:                        element = principal;
2074:                    }
2075:
2076:                    @Override
2077:                    public void testNext_EmptySet_NoSuchElementException() {
2078:
2079:                        if (testing) {
2080:                            //Unexpected: IndexOutOfBoundsException
2081:                            try {
2082:                                super 
2083:                                        .testNext_EmptySet_NoSuchElementException();
2084:                            } catch (IndexOutOfBoundsException e) {
2085:                            }
2086:                        } else {
2087:                            super .testNext_EmptySet_NoSuchElementException();
2088:                        }
2089:                    }
2090:
2091:                    @Override
2092:                    public void testNext_NoSuchElementException() {
2093:                        if (testing) {
2094:                            //Unexpected: IndexOutOfBoundsException
2095:                            try {
2096:                                super .testNext_NoSuchElementException();
2097:                            } catch (IndexOutOfBoundsException e) {
2098:                            }
2099:                        } else {
2100:                            super .testNext_NoSuchElementException();
2101:                        }
2102:                    }
2103:                }
2104:
2105:                public static class IteratorReadOnly extends
2106:                        SecurityTest.ReadOnlyIteratorTest {
2107:
2108:                    private final Subject subject = new Subject();
2109:
2110:                    public IteratorReadOnly() {
2111:                        set = subject.getPrivateCredentials();
2112:                        element = principal;
2113:                    }
2114:
2115:                    @Override
2116:                    public void setReadOnly() {
2117:                        subject.setReadOnly();
2118:                    }
2119:
2120:                    @Override
2121:                    public void testNext_EmptySet_NoSuchElementException() {
2122:
2123:                        if (testing) {
2124:                            //Unexpected: IndexOutOfBoundsException
2125:                            try {
2126:                                super 
2127:                                        .testNext_EmptySet_NoSuchElementException();
2128:                            } catch (IndexOutOfBoundsException e) {
2129:                            }
2130:                        } else {
2131:                            super .testNext_EmptySet_NoSuchElementException();
2132:                        }
2133:                    }
2134:
2135:                    @Override
2136:                    public void testNext_NoSuchElementException() {
2137:                        if (testing) {
2138:                            //Unexpected: IndexOutOfBoundsException
2139:                            try {
2140:                                super .testNext_NoSuchElementException();
2141:                            } catch (IndexOutOfBoundsException e) {
2142:                            }
2143:                        } else {
2144:                            super .testNext_NoSuchElementException();
2145:                        }
2146:                    }
2147:                }
2148:
2149:                public static class IteratorSecure extends
2150:                        SecurityTest.SecureIteratorTest {
2151:
2152:                    public IteratorSecure() {
2153:                        set = (new Subject()).getPrivateCredentials();
2154:                        element = principal;
2155:                    }
2156:
2157:                    @Override
2158:                    public void setSecure() {
2159:                        denyPermission(new AuthPermission(
2160:                                "modifyPrivateCredentials"));
2161:                    }
2162:
2163:                    @Override
2164:                    public void testNext_EmptySet_NoSuchElementException() {
2165:
2166:                        if (testing) {
2167:                            //Unexpected: IndexOutOfBoundsException
2168:                            try {
2169:                                super 
2170:                                        .testNext_EmptySet_NoSuchElementException();
2171:                            } catch (IndexOutOfBoundsException e) {
2172:                            }
2173:                        } else {
2174:                            super .testNext_EmptySet_NoSuchElementException();
2175:                        }
2176:                    }
2177:
2178:                    @Override
2179:                    public void testNext_NoSuchElementException() {
2180:                        if (testing) {
2181:                            //Unexpected: IndexOutOfBoundsException
2182:                            try {
2183:                                super .testNext_NoSuchElementException();
2184:                            } catch (IndexOutOfBoundsException e) {
2185:                            }
2186:                        } else {
2187:                            super .testNext_NoSuchElementException();
2188:                        }
2189:                    }
2190:                }
2191:
2192:                public static class SetInterface extends SecurityTest.SetTest {
2193:                    public SetInterface() {
2194:                        set = (new Subject()).getPrivateCredentials();
2195:                        element = principal;
2196:                    }
2197:                }
2198:
2199:                public static class UnsupportedNull extends
2200:                        SecurityTest.UnsupportedNullTest {
2201:
2202:                    public UnsupportedNull() {
2203:                        set = (new Subject()).getPrivateCredentials();
2204:                        element = principal;
2205:                    }
2206:                }
2207:
2208:                public static class ReadOnlySet extends
2209:                        SecurityTest.ReadOnlySetTest {
2210:                    private final Subject subject = new Subject();
2211:
2212:                    public ReadOnlySet() {
2213:                        set = subject.getPrivateCredentials();
2214:                        element = principal;
2215:                    }
2216:
2217:                    @Override
2218:                    public void setReadOnly() {
2219:                        subject.setReadOnly();
2220:                    }
2221:                }
2222:
2223:                public static class SecureSet extends
2224:                        SecurityTest.SecureSetTest {
2225:
2226:                    public SecureSet() {
2227:                        set = (new Subject()).getPrivateCredentials();
2228:                        element = principal;
2229:                    }
2230:
2231:                    @Override
2232:                    public void setSecure() {
2233:                        denyPermission(new AuthPermission(
2234:                                "modifyPrivateCredentials"));
2235:                    }
2236:                }
2237:
2238:                public static class SObjectTest extends
2239:                        SecurityTest.SubjectSetObjectTest {
2240:                    public SObjectTest() {
2241:                        obj1 = subject.getPrivateCredentials();
2242:
2243:                        //intentionally another set
2244:                        obj2 = subject.getPublicCredentials();
2245:                    }
2246:                }
2247:            }
2248:
2249:            public static class PublicCredentialTestSuite extends TestSuite {
2250:
2251:                public PublicCredentialTestSuite() {
2252:                    super ("PublicCredential");
2253:
2254:                    TestSuite iterator = new TestSuite("Iterator");
2255:
2256:                    iterator.addTest(new TestSuite(IteratorInterface.class,
2257:                            "Interface"));
2258:                    iterator.addTest(new TestSuite(IteratorReadOnly.class,
2259:                            "ReadOnly"));
2260:                    iterator.addTest(new TestSuite(IteratorSecure.class,
2261:                            "Secure"));
2262:
2263:                    TestSuite set = new TestSuite("Set");
2264:                    set.addTest(new TestSuite(SetInterface.class, "Interface"));
2265:                    set.addTest(new TestSuite(UnsupportedNull.class,
2266:                            "UnsupportedNull"));
2267:                    set.addTest(new TestSuite(ReadOnlySet.class, "ReadOnly"));
2268:                    set.addTest(new TestSuite(SecureSet.class, "Secure"));
2269:
2270:                    TestSuite object = new TestSuite("Object");
2271:                    object.addTest(new TestSuite(SObjectTest.class, "Object"));
2272:
2273:                    addTest(iterator);
2274:                    addTest(set);
2275:                    addTest(object);
2276:                }
2277:
2278:                public static class IteratorInterface extends
2279:                        SecurityTest.IteratorTest {
2280:                    public IteratorInterface() {
2281:                        set = (new Subject()).getPublicCredentials();
2282:                        element = principal;
2283:                    }
2284:                }
2285:
2286:                public static class IteratorReadOnly extends
2287:                        SecurityTest.ReadOnlyIteratorTest {
2288:
2289:                    private final Subject subject = new Subject();
2290:
2291:                    public IteratorReadOnly() {
2292:                        set = subject.getPublicCredentials();
2293:                        element = principal;
2294:                    }
2295:
2296:                    @Override
2297:                    public void setReadOnly() {
2298:                        subject.setReadOnly();
2299:                    }
2300:                }
2301:
2302:                public static class IteratorSecure extends
2303:                        SecurityTest.SecureIteratorTest {
2304:
2305:                    public IteratorSecure() {
2306:                        set = (new Subject()).getPublicCredentials();
2307:                        element = principal;
2308:                    }
2309:
2310:                    @Override
2311:                    public void setSecure() {
2312:                        denyPermission(new AuthPermission(
2313:                                "modifyPublicCredentials"));
2314:                    }
2315:                }
2316:
2317:                public static class SetInterface extends SecurityTest.SetTest {
2318:                    public SetInterface() {
2319:                        set = (new Subject()).getPublicCredentials();
2320:                        element = principal;
2321:                    }
2322:                }
2323:
2324:                public static class UnsupportedNull extends
2325:                        SecurityTest.UnsupportedNullTest {
2326:
2327:                    public UnsupportedNull() {
2328:                        set = (new Subject()).getPublicCredentials();
2329:                        element = principal;
2330:                    }
2331:                }
2332:
2333:                public static class ReadOnlySet extends
2334:                        SecurityTest.ReadOnlySetTest {
2335:                    private final Subject subject = new Subject();
2336:
2337:                    public ReadOnlySet() {
2338:                        set = subject.getPublicCredentials();
2339:                        element = principal;
2340:                    }
2341:
2342:                    @Override
2343:                    public void setReadOnly() {
2344:                        subject.setReadOnly();
2345:                    }
2346:                }
2347:
2348:                public static class SecureSet extends
2349:                        SecurityTest.SecureSetTest {
2350:
2351:                    public SecureSet() {
2352:                        set = (new Subject()).getPublicCredentials();
2353:                        element = principal;
2354:                    }
2355:
2356:                    @Override
2357:                    public void setSecure() {
2358:                        denyPermission(new AuthPermission(
2359:                                "modifyPublicCredentials"));
2360:                    }
2361:                }
2362:
2363:                public static class SObjectTest extends
2364:                        SecurityTest.SubjectSetObjectTest {
2365:                    public SObjectTest() {
2366:                        obj1 = subject.getPublicCredentials();
2367:
2368:                        //intentionally another set
2369:                        obj2 = subject.getPrincipals();
2370:                    }
2371:                }
2372:            }
2373:
2374:            public static class PrincipalClassTestSuite extends TestSuite {
2375:
2376:                public PrincipalClassTestSuite() {
2377:                    super ("PrincipalClass");
2378:
2379:                    TestSuite set = new TestSuite("Set");
2380:                    set.addTest(new TestSuite(SetInterface.class, "Interface"));
2381:                    set.addTest(new TestSuite(UnsupportedNull.class,
2382:                            "UnsupportedNull"));
2383:                    set.addTest(new TestSuite(IneligibleElement.class,
2384:                            "IneligibleElement"));
2385:
2386:                    TestSuite object = new TestSuite("Object");
2387:                    object.addTest(new TestSuite(SObjectTest.class, "Object"));
2388:
2389:                    addTest(set);
2390:                    addTest(object);
2391:                }
2392:
2393:                public static class SetInterface extends SecurityTest.SetTest {
2394:                    public SetInterface() {
2395:                        set = (new Subject()).getPrincipals(MyClass1.class);
2396:                        element = new MyClass1();
2397:                    }
2398:                }
2399:
2400:                public static class UnsupportedNull extends
2401:                        SecurityTest.UnsupportedNullTest {
2402:
2403:                    public UnsupportedNull() {
2404:                        set = (new Subject()).getPrincipals(MyClass1.class);
2405:                        element = new MyClass1();
2406:                    }
2407:                }
2408:
2409:                public static class IneligibleElement extends
2410:                        SecurityTest.IneligibleElementTest {
2411:
2412:                    public IneligibleElement() {
2413:                        set = (new Subject()).getPrincipals(MyClass1.class);
2414:                        element = new MyClass1();
2415:                        iElement = new MyClass2();
2416:                    }
2417:                }
2418:
2419:                public static class SObjectTest extends
2420:                        SecurityTest.SubjectSetObjectTest {
2421:                    public SObjectTest() {
2422:                        obj1 = subject.getPrincipals(MyClass1.class);
2423:
2424:                        //intentionally another set
2425:                        obj2 = subject.getPrivateCredentials(MyClass1.class);
2426:                    }
2427:                }
2428:            }
2429:
2430:            public static class PrivateCredentialClassTestSuite extends
2431:                    TestSuite {
2432:
2433:                public PrivateCredentialClassTestSuite() {
2434:                    super ("PrivateCredentialClass");
2435:
2436:                    TestSuite set = new TestSuite("Set");
2437:                    set.addTest(new TestSuite(SetInterface.class, "Interface"));
2438:                    set.addTest(new TestSuite(UnsupportedNull.class,
2439:                            "UnsupportedNull"));
2440:                    set.addTest(new TestSuite(IneligibleElement.class,
2441:                            "IneligibleElement"));
2442:
2443:                    TestSuite object = new TestSuite("Object");
2444:                    object.addTest(new TestSuite(SObjectTest.class, "Object"));
2445:
2446:                    addTest(set);
2447:                    addTest(object);
2448:                }
2449:
2450:                public static class SetInterface extends SecurityTest.SetTest {
2451:                    public SetInterface() {
2452:                        set = (new Subject())
2453:                                .getPrivateCredentials(MyClass1.class);
2454:                        element = new MyClass1();
2455:                    }
2456:                }
2457:
2458:                public static class UnsupportedNull extends
2459:                        SecurityTest.UnsupportedNullTest {
2460:
2461:                    public UnsupportedNull() {
2462:                        set = (new Subject())
2463:                                .getPrivateCredentials(MyClass1.class);
2464:                        element = new MyClass1();
2465:                    }
2466:                }
2467:
2468:                public static class IneligibleElement extends
2469:                        SecurityTest.IneligibleElementTest {
2470:
2471:                    public IneligibleElement() {
2472:                        set = (new Subject())
2473:                                .getPrivateCredentials(MyClass1.class);
2474:                        element = new MyClass1();
2475:                        iElement = new MyClass2();
2476:                    }
2477:                }
2478:
2479:                public static class SObjectTest extends
2480:                        SecurityTest.SubjectSetObjectTest {
2481:                    public SObjectTest() {
2482:                        obj1 = subject.getPrivateCredentials(MyClass1.class);
2483:
2484:                        //intentionally another set
2485:                        obj2 = subject.getPublicCredentials(MyClass1.class);
2486:                    }
2487:                }
2488:            }
2489:
2490:            public static class PublicCredentialClassTestSuite extends
2491:                    TestSuite {
2492:
2493:                public PublicCredentialClassTestSuite() {
2494:                    super ("PublicCredentialClass");
2495:
2496:                    TestSuite set = new TestSuite("Set");
2497:                    set.addTest(new TestSuite(SetInterface.class, "Interface"));
2498:                    set.addTest(new TestSuite(UnsupportedNull.class,
2499:                            "UnsupportedNull"));
2500:                    set.addTest(new TestSuite(IneligibleElement.class,
2501:                            "IneligibleElement"));
2502:
2503:                    TestSuite object = new TestSuite("Object");
2504:                    object.addTest(new TestSuite(SObjectTest.class, "Object"));
2505:
2506:                    addTest(set);
2507:                    addTest(object);
2508:                }
2509:
2510:                public static class SetInterface extends SecurityTest.SetTest {
2511:                    public SetInterface() {
2512:                        set = (new Subject())
2513:                                .getPublicCredentials(MyClass1.class);
2514:                        element = new MyClass1();
2515:                    }
2516:                }
2517:
2518:                public static class UnsupportedNull extends
2519:                        SecurityTest.UnsupportedNullTest {
2520:
2521:                    public UnsupportedNull() {
2522:                        set = (new Subject())
2523:                                .getPublicCredentials(MyClass1.class);
2524:                        element = new MyClass1();
2525:                    }
2526:                }
2527:
2528:                public static class IneligibleElement extends
2529:                        SecurityTest.IneligibleElementTest {
2530:
2531:                    public IneligibleElement() {
2532:                        set = (new Subject())
2533:                                .getPublicCredentials(MyClass1.class);
2534:                        element = new MyClass1();
2535:                        iElement = new MyClass2();
2536:                    }
2537:                }
2538:
2539:                public static class SObjectTest extends
2540:                        SecurityTest.SubjectSetObjectTest {
2541:                    public SObjectTest() {
2542:                        obj1 = subject.getPublicCredentials(MyClass1.class);
2543:
2544:                        //intentionally another set
2545:                        obj2 = subject.getPrincipals(MyClass1.class);
2546:                    }
2547:                }
2548:            }
2549:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.