Path: blob/master/test/jdk/java/security/UnresolvedPermission/AccessorMethods.java
41149 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 476528126* @summary provide accessor methods for UnresolvedPermission27*/2829import java.io.*;30import java.security.UnresolvedPermission;31import java.security.cert.*;3233public class AccessorMethods {3435private static final String SIGNER1 = "AccessorMethods.signer1";36private static final String SIGNER2 = "AccessorMethods.signer2";37private static final String CA = "AccessorMethods.ca";3839public static void main(String[] args) throws Exception {4041// set CA cert in chain42File f = new File(System.getProperty("test.src", "."), CA);43FileInputStream fis = new FileInputStream(f);44CertificateFactory fac = CertificateFactory.getInstance("X.509");45Certificate cacert = fac.generateCertificate(fis);46Certificate[] signercerts = new Certificate[4];47signercerts[1] = cacert;48signercerts[3] = cacert;4950// set signer certs51f = new File(System.getProperty("test.src", "."), SIGNER1);52fis = new FileInputStream(f);53Certificate signer1 = fac.generateCertificate(fis);54signercerts[0] = signer1;5556f = new File(System.getProperty("test.src", "."), SIGNER2);57fis = new FileInputStream(f);58Certificate signer2 = fac.generateCertificate(fis);59signercerts[2] = signer2;6061UnresolvedPermission up = new UnresolvedPermission62("type", "name", "actions", signercerts);63if (!up.getUnresolvedType().equals("type") ||64!up.getUnresolvedName().equals("name") ||65!up.getUnresolvedActions().equals("actions")) {66throw new SecurityException("Test 1 Failed");67}6869Certificate[] certs = up.getUnresolvedCerts();70if (certs == null || certs.length != 2) {71throw new SecurityException("Test 2 Failed");72}7374boolean foundSigner1 = false;75boolean foundSigner2 = false;76if (certs[0].equals(signer1) || certs[1].equals(signer1)) {77foundSigner1 = true;78}79if (certs[0].equals(signer2) || certs[1].equals(signer2)) {80foundSigner2 = true;81}82if (!foundSigner1 || !foundSigner2) {83throw new SecurityException("Test 3 Failed");84}85}86}878889