mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 20:14:43 +02:00
8231365: ServicePermission::equals doesn't comply to the spec
8231196: DelegationPermission allows to create an instance that thows NPE on ::equals call Reviewed-by: mullan
This commit is contained in:
parent
055a49a266
commit
026a05d0c6
5 changed files with 106 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -78,7 +78,8 @@ public final class DelegationPermission extends BasicPermission
|
||||||
* @param principals the name of the subordinate and target principals
|
* @param principals the name of the subordinate and target principals
|
||||||
*
|
*
|
||||||
* @throws NullPointerException if {@code principals} is {@code null}.
|
* @throws NullPointerException if {@code principals} is {@code null}.
|
||||||
* @throws IllegalArgumentException if {@code principals} is empty.
|
* @throws IllegalArgumentException if {@code principals} is empty,
|
||||||
|
* or does not contain a pair of principals, or is improperly quoted
|
||||||
*/
|
*/
|
||||||
public DelegationPermission(String principals) {
|
public DelegationPermission(String principals) {
|
||||||
super(principals);
|
super(principals);
|
||||||
|
@ -94,7 +95,8 @@ public final class DelegationPermission extends BasicPermission
|
||||||
* @param actions should be null.
|
* @param actions should be null.
|
||||||
*
|
*
|
||||||
* @throws NullPointerException if {@code principals} is {@code null}.
|
* @throws NullPointerException if {@code principals} is {@code null}.
|
||||||
* @throws IllegalArgumentException if {@code principals} is empty.
|
* @throws IllegalArgumentException if {@code principals} is empty,
|
||||||
|
* or does not contain a pair of principals, or is improperly quoted
|
||||||
*/
|
*/
|
||||||
public DelegationPermission(String principals, String actions) {
|
public DelegationPermission(String principals, String actions) {
|
||||||
super(principals, actions);
|
super(principals, actions);
|
||||||
|
@ -116,10 +118,15 @@ public final class DelegationPermission extends BasicPermission
|
||||||
} else {
|
} else {
|
||||||
t = new StringTokenizer(target, "\"", false);
|
t = new StringTokenizer(target, "\"", false);
|
||||||
subordinate = t.nextToken();
|
subordinate = t.nextToken();
|
||||||
if (t.countTokens() == 2) {
|
switch (t.countTokens()) {
|
||||||
|
case 2:
|
||||||
t.nextToken(); // bypass whitespace
|
t.nextToken(); // bypass whitespace
|
||||||
service = t.nextToken();
|
service = t.nextToken();
|
||||||
} else if (t.countTokens() > 0) {
|
break;
|
||||||
|
case 0:
|
||||||
|
throw new IllegalArgumentException
|
||||||
|
("service principal not provided");
|
||||||
|
default:
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("service principal [" + t.nextToken() +
|
("service principal [" + t.nextToken() +
|
||||||
"] syntax invalid: " +
|
"] syntax invalid: " +
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -238,7 +238,7 @@ public final class ServicePermission extends Permission
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ServicePermission that = (ServicePermission) obj;
|
ServicePermission that = (ServicePermission) obj;
|
||||||
return ((this.mask & that.mask) == that.mask) &&
|
return (this.mask == that.mask) &&
|
||||||
this.getName().equals(that.getName());
|
this.getName().equals(that.getName());
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
* published by the Free Software Foundation.
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
*
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import javax.security.auth.kerberos.DelegationPermission;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8231196
|
||||||
|
* @summary DelegationPermission allows to create an instance that thows NPE on ::equals call
|
||||||
|
* @run main/fail DelegationPermissionInit
|
||||||
|
*/
|
||||||
|
public class DelegationPermissionInit {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new DelegationPermission("\"user@REALM\"");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8231365
|
||||||
|
* @library /test/lib
|
||||||
|
* @summary ServicePermission::equals doesn't comply to the spec
|
||||||
|
*/
|
||||||
|
|
||||||
|
import jdk.test.lib.Asserts;
|
||||||
|
|
||||||
|
import javax.security.auth.kerberos.ServicePermission;
|
||||||
|
|
||||||
|
public class ServicePermissionEquals {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
ServicePermission p1 = new ServicePermission("user@REALM", "initiate");
|
||||||
|
ServicePermission p2 = new ServicePermission("user@REALM", "accept");
|
||||||
|
ServicePermission p3 = new ServicePermission("user@REALM", "initiate,accept");
|
||||||
|
|
||||||
|
Asserts.assertNotEquals(p1.hashCode(), p2.hashCode());
|
||||||
|
Asserts.assertNotEquals(p1.hashCode(), p3.hashCode());
|
||||||
|
Asserts.assertNotEquals(p3.hashCode(), p2.hashCode());
|
||||||
|
|
||||||
|
Asserts.assertFalse(p1.equals(p2));
|
||||||
|
Asserts.assertFalse(p1.equals(p3));
|
||||||
|
Asserts.assertFalse(p3.equals(p2));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue