2362N/A * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 * 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 * 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. 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 0N/A * @summary Retrive a subset of private credentials can be accessed 0N/A * Author : Ram Marti 0N/A * This is a test program to verify the fix for Bug 4326852 0N/A * (impossible to extract a subset of private credentials) 0N/A * The policy file used allows read access only to String classes. 0N/A * permission javax.security.auth.AuthPermission \ 0N/A * "modifyPrivateCredentials"; 0N/A * permission javax.security.auth.PrivateCredentialPermission \ 0N/A * "java.lang.String com.sun.security.auth.SolarisPrincipal \"user"", "read"; 0N/A * The test verifies the following: 0N/A * - String class creds can be retrieved by using 0N/A * getPrivateCredentials(String.class) 0N/A * - The above set is not backed internally 0N/A * - getPrivateCredentials(Boolean or Integer) returns an empty set 0N/A * - Set is returned by getPrivateCredentials() throws 0N/A * security exception when trying to access non-String 0N/A * - The above set is internally backed up and any changes in 0N/A * internal private creds are reflected in the set returned 0N/A * - When the above set throws security exception the iterator 0N/A * - is advanced to the next item in the list of creds. 0N/A * - equals,contains,containsAll,add,remove operations work correctly 0N/A /* Test principals */ 0N/A throw new Exception (
"Error: Exception in containsAll (string coll)!!");
0N/A throw new Exception(
"Error:p1 size should have been 6 and was " +
0N/A throw new Exception(
"Error: p2 size should have been 3 and was " +
0N/A throw new Exception(
"Expected number of exceptions was 2 " +
0N/A // Verify that remove op was successful 0N/A // System.out.println("Exception!!"); 0N/A "Size of ObjCred is " +
0N/A "Size of ObjCred is " +
0N/A /* We can store only string types of creds 0N/A * Let us create a subject with only string type of creds 0N/A * New subject scontain1, set p3, creds4 0N/A // We added two integer creds so there must be two exceptions only 0N/A // We had two integer creds; removed one as a part of coll2; so 0N/A // only one exception must have been thrown 0N/A /* New subject s with creds and privCredSet 0N/A * Since the privCredSet is not backed by internal private 0N/A * creds adding to it should not make any difference to 0N/A * privCredSet and theize should still be 3 0N/A * Let us try to get the elements 0N/A * No exception should occur 0N/A * Can we add and remove the creds 0N/A // We don't have permission to read Boolean creds 0N/A // SInce the creds have no boolean creds we should get an empty 0N/A throw new RuntimeException(
"Error:String PrivcredSet1 of Boolean size should have been 0 and was " +
0N/A * We don't have permission to read Integer creds 0N/A * We should get an empty set even though the private creds 0N/A * has an integer cred. No security exception either ! 0N/A throw new RuntimeException(
"Error:String PrivcredSet1 of Integer size should have been 0 and was " +
0N/A * Since the returned privCredSet2 is internally backed by the 0N/A * private creds, any additions to it should be reflected in 0N/A /* Let us add a couple of Boolean creds */