0N/A/*
2362N/A * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @author Charlie Lai
0N/A * @bug 4394746
0N/A * @summary Resources should not be loaded until necessar
0N/A * @run main/othervm/policy=Format.policy -Djava.security.auth.login.config=file:${test.src}/Format.config Format
0N/A *
0N/A */
0N/A
0N/Aimport javax.security.auth.*;
0N/Aimport javax.security.auth.login.*;
0N/Aimport javax.security.auth.callback.*;
0N/Aimport java.io.*;
0N/Aimport java.util.*;
0N/A
0N/Aimport com.sun.security.auth.*;
0N/A
0N/Apublic class Format
0N/A implements java.io.Serializable, java.security.Principal
0N/A{
0N/A
0N/A public String getName() { return null; }
0N/A
0N/A public static void main(String[] args) {
0N/A
0N/A try {
0N/A PrivateCredentialPermission pcp = new PrivateCredentialPermission
0N/A ("test", "write");
0N/A throw new SecurityException("test 1 failed");
0N/A } catch (IllegalArgumentException iae) {
0N/A // good
0N/A System.out.println("Test 1: " + iae.getMessage());
0N/A }
0N/A
0N/A try {
0N/A PrivateCredentialPermission pcp = new PrivateCredentialPermission
0N/A ("Format", "read");
0N/A throw new SecurityException("test 2 failed");
0N/A } catch (IllegalArgumentException iae) {
0N/A // good
0N/A System.out.println("Test 2: " + iae.getMessage());
0N/A }
0N/A
0N/A try {
0N/A PrivateCredentialPermission pcp = new PrivateCredentialPermission
0N/A ("Format Format", "read");
0N/A throw new SecurityException("test 3 failed");
0N/A } catch (IllegalArgumentException iae) {
0N/A // good
0N/A System.out.println("Test 3: " + iae.getMessage());
0N/A }
0N/A
0N/A try {
0N/A PrivateCredentialPermission pcp = new PrivateCredentialPermission
0N/A ("Format Format Format", "read");
0N/A throw new SecurityException("test 4 failed");
0N/A } catch (IllegalArgumentException iae) {
0N/A // good
0N/A System.out.println("Test 4: " + iae.getMessage());
0N/A }
0N/A
0N/A try {
0N/A PrivateCredentialPermission pcp = new PrivateCredentialPermission
0N/A ("Format Format \"Format", "read");
0N/A throw new SecurityException("test 5 failed");
0N/A } catch (IllegalArgumentException iae) {
0N/A // good
0N/A System.out.println("Test 5: " + iae.getMessage());
0N/A }
0N/A
0N/A try {
0N/A PrivateCredentialPermission pcp = new PrivateCredentialPermission
0N/A ("Format * \"Format\"", "read");
0N/A throw new SecurityException("test 6 failed");
0N/A } catch (IllegalArgumentException iae) {
0N/A // good
0N/A System.out.println("Test 6: " + iae.getMessage());
0N/A }
0N/A
0N/A try {
0N/A javax.security.auth.x500.X500Principal p =
0N/A new javax.security.auth.x500.X500Principal((String)null);
0N/A throw new SecurityException("test 7 failed");
0N/A } catch (NullPointerException npe) {
0N/A // good
0N/A System.out.println("Test 7: " + npe.getMessage());
0N/A }
0N/A
0N/A try {
0N/A Subject s = new Subject(false, null, null, null);
0N/A throw new SecurityException("test 8 failed");
0N/A } catch (NullPointerException npe) {
0N/A // good
0N/A System.out.println("Test 8: " + npe.getMessage());
0N/A }
0N/A
0N/A try {
0N/A Subject.getSubject(null);
0N/A throw new SecurityException("test 9 failed");
0N/A } catch (NullPointerException npe) {
0N/A // good
0N/A System.out.println("Test 9: " + npe.getMessage());
0N/A }
0N/A
0N/A try {
0N/A Subject.doAs(null, (java.security.PrivilegedAction)null);
0N/A throw new SecurityException("test 10 failed");
0N/A } catch (NullPointerException npe) {
0N/A // good
0N/A System.out.println("Test 10: " + npe.getMessage());
0N/A }
0N/A
0N/A try {
0N/A Subject s = new Subject();
0N/A s.getPrincipals(null);
0N/A throw new SecurityException("test 11 failed");
0N/A } catch (NullPointerException npe) {
0N/A // good
0N/A System.out.println("Test 11: " + npe.getMessage());
0N/A }
0N/A
0N/A try {
0N/A Subject s = new Subject();
0N/A s.getPrincipals().add(new javax.security.auth.x500.X500Principal
0N/A ("cn=test1"));
0N/A s.getPublicCredentials().add(new Format());
0N/A s.getPrivateCredentials().add(new Format());
0N/A System.out.println("Test 12, s.toString() = " + s.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 12 failed: e.toString()");
0N/A }
0N/A
0N/A try {
0N/A Subject s = new Subject();
0N/A s.getPrincipals().add(new javax.security.auth.x500.X500Principal
0N/A ("cn=test1"));
0N/A s.setReadOnly();
0N/A java.util.Iterator i = s.getPrincipals().iterator();
0N/A i.next();
0N/A i.remove();
0N/A throw new SecurityException("test 13 failed");
0N/A } catch (IllegalStateException ise) {
0N/A // good
0N/A System.out.println("Test 13: " + ise.getMessage());
0N/A }
0N/A
0N/A try {
0N/A Subject s = new Subject();
0N/A s.getPrincipals().add(new Format());
0N/A throw new SecurityException("test 14 failed");
0N/A } catch (SecurityException se) {
0N/A // good
0N/A System.out.println("Test 14: " + se.getMessage());
0N/A }
0N/A
0N/A try {
0N/A Subject s = new Subject();
0N/A s.getPrincipals((Class)Format.class).add(new Subject());
0N/A throw new SecurityException("test 15 failed");
0N/A } catch (SecurityException se) {
0N/A // good
0N/A System.out.println("Test 15: " + se.getMessage());
0N/A }
0N/A
0N/A try {
0N/A LoginContext lc = new LoginContext(null);
0N/A throw new SecurityException("test 16 failed");
0N/A } catch (LoginException le) {
0N/A // good
0N/A System.out.println("Test 16: " + le.getMessage());
0N/A }
0N/A
0N/A try {
0N/A LoginContext lc = new LoginContext("nothing");
0N/A throw new SecurityException("test 17 failed");
0N/A } catch (LoginException le) {
0N/A // good
0N/A System.out.println("Test 17: " + le.getMessage());
0N/A }
0N/A
0N/A try {
0N/A LoginContext lc = new LoginContext("test", (Subject)null);
0N/A throw new SecurityException("test 18 failed");
0N/A } catch (LoginException le) {
0N/A // good
0N/A System.out.println("Test 18: " + le.getMessage());
0N/A }
0N/A
0N/A try {
0N/A LoginContext lc = new LoginContext("test", (CallbackHandler)null);
0N/A throw new SecurityException("test 19 failed");
0N/A } catch (LoginException le) {
0N/A // good
0N/A System.out.println("Test 19: " + le.getMessage());
0N/A }
0N/A
0N/A try {
0N/A LoginContext lc = new LoginContext("test");
0N/A lc.logout();
0N/A throw new SecurityException("test 20 failed");
0N/A } catch (LoginException le) {
0N/A // good
0N/A System.out.println("Test 20: " + le.getMessage());
0N/A }
0N/A
0N/A try {
0N/A LoginContext lc = new LoginContext("test2");
0N/A lc.login();
0N/A throw new SecurityException("test 21 failed");
0N/A } catch (LoginException le) {
0N/A // good
0N/A System.out.println("Test 21: " + le.getMessage());
0N/A }
0N/A
0N/A /*** TESTS FOR THE COM PACKAGE RESOURCES ***/
0N/A
0N/A try {
0N/A NTDomainPrincipal p = new NTDomainPrincipal(null);
0N/A throw new SecurityException("test 22 failed");
0N/A } catch (NullPointerException e) {
0N/A // good
0N/A System.out.println("Test 22: " + e.getMessage());
0N/A }
0N/A
0N/A try {
0N/A NTDomainPrincipal p = new NTDomainPrincipal("test");
0N/A System.out.println("NTDomainPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 23 failed");
0N/A }
0N/A
0N/A try {
0N/A NTNumericCredential p = new NTNumericCredential(1L);
0N/A System.out.println("NTNumericCredential = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 24 failed");
0N/A }
0N/A
0N/A try {
0N/A NTSid p = new NTSid("");
0N/A throw new SecurityException("test 25 failed");
0N/A } catch (IllegalArgumentException e) {
0N/A // good
0N/A System.out.println("Test 25: " + e.getMessage());
0N/A }
0N/A
0N/A try {
0N/A NTSid p = new NTSid("test");
0N/A System.out.println("NTSid = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 26 failed");
0N/A }
0N/A
0N/A try {
0N/A NTSidDomainPrincipal p = new NTSidDomainPrincipal("test");
0N/A System.out.println("NTSidDomainPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 27 failed");
0N/A }
0N/A
0N/A try {
0N/A NTSidGroupPrincipal p = new NTSidGroupPrincipal("test");
0N/A System.out.println("NTSidGroupPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 28 failed");
0N/A }
0N/A
0N/A try {
0N/A NTSidPrimaryGroupPrincipal p =
0N/A new NTSidPrimaryGroupPrincipal("test");
0N/A System.out.println("NTSidPrimaryGroupPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 29 failed");
0N/A }
0N/A
0N/A try {
0N/A NTSidUserPrincipal p = new NTSidUserPrincipal("test");
0N/A System.out.println("NTSidUserPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 30 failed");
0N/A }
0N/A
0N/A try {
0N/A NTUserPrincipal p = new NTUserPrincipal("test");
0N/A System.out.println("NTUserPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 31 failed");
0N/A }
0N/A
0N/A try {
0N/A UnixNumericGroupPrincipal p = new UnixNumericGroupPrincipal("0",
0N/A true);
0N/A System.out.println("NTPrimaryGroupPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 32 failed");
0N/A }
0N/A
0N/A try {
0N/A UnixNumericGroupPrincipal p = new UnixNumericGroupPrincipal("1",
0N/A false);
0N/A System.out.println("UnixNumericGroupPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 33 failed");
0N/A }
0N/A
0N/A try {
0N/A UnixNumericUserPrincipal p = new UnixNumericUserPrincipal("2");
0N/A System.out.println("UnixNumericUserPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 34 failed");
0N/A }
0N/A
0N/A try {
0N/A UnixPrincipal p = new UnixPrincipal("test");
0N/A System.out.println("UnixPrincipal = " + p.toString());
0N/A } catch (Exception e) {
0N/A throw new SecurityException("test 35 failed");
0N/A }
0N/A
0N/A System.out.println("Format test succeeded");
0N/A }
0N/A}