Path: blob/master/test/jdk/javax/security/auth/PrivateCredentialPermission/Equals.java
41153 views
/*1* Copyright (c) 2000, 2001, 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 436484826* @bug 436485127* @summary PrivateCredentialPermission doesn't ignore principal order28* PrivateCredentialPermission incorrectly ignores case29*/3031import javax.security.auth.*;3233public class Equals {3435public static void main(String[] args) {3637// test regular equals and implies38PrivateCredentialPermission pcp1 = new PrivateCredentialPermission39("a b \"pcp1\" c \"pcp2\"", "read");40PrivateCredentialPermission pcp2 = new PrivateCredentialPermission41("a b \"pcp1\" c \"pcp2\"", "read");42if (!pcp1.equals(pcp2) || !pcp2.equals(pcp1))43throw new SecurityException("Equals test failed: #1");44if (!pcp1.implies(pcp2) || !pcp2.implies(pcp1))45throw new SecurityException("Equals test failed: #2");4647// reverse principals48pcp1 = new PrivateCredentialPermission49("a c \"pcp2\" b \"pcp1\"", "read");50pcp2 = new PrivateCredentialPermission51("a b \"pcp1\" c \"pcp2\"", "read");52if (!pcp1.equals(pcp2) || !pcp2.equals(pcp1))53throw new SecurityException("Equals test failed: #3");54if (!pcp1.implies(pcp2) || !pcp2.implies(pcp1))55throw new SecurityException("Equals test failed: #4");5657// test equals/implies failure58pcp1 = new PrivateCredentialPermission59("a b \"pcp1\"", "read");60if (pcp1.equals(pcp2) || pcp2.equals(pcp1))61throw new SecurityException("Equals test failed: #5");62if (!pcp1.implies(pcp2) || pcp2.implies(pcp1))63throw new SecurityException("Equals test failed: #6");6465// test wildcards66pcp1 = new PrivateCredentialPermission67("* b \"pcp1\" c \"pcp2\"", "read");68if (pcp1.equals(pcp2) || pcp2.equals(pcp1))69throw new SecurityException("Equals test failed: #7");70if (!pcp1.implies(pcp2) || pcp2.implies(pcp1))71throw new SecurityException("Equals test failed: #8");7273pcp1 = new PrivateCredentialPermission74("a c \"pcp2\" b \"*\"", "read");75if (pcp1.equals(pcp2) || pcp2.equals(pcp1))76throw new SecurityException("Equals test failed: #9");77if (!pcp1.implies(pcp2) || pcp2.implies(pcp1))78throw new SecurityException("Equals test failed: #10");7980pcp2 = new PrivateCredentialPermission81("a b \"*\" c \"pcp2\"", "read");82if (!pcp1.equals(pcp2) || !pcp2.equals(pcp1))83throw new SecurityException("Equals test failed: #11");84if (!pcp1.implies(pcp2) || !pcp2.implies(pcp1))85throw new SecurityException("Equals test failed: #12");8687System.out.println("Equals test passed");88}89}909192