author | jjg |
Fri, 09 Aug 2019 15:22:43 -0700 | |
changeset 57706 | 7ac414640ad5 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
30438
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
1 |
/* |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
4 |
* |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
8 |
* |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
13 |
* accompanied this code). |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
14 |
* |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
18 |
* |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
21 |
* questions. |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
22 |
*/ |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
23 |
|
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
24 |
/* |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
25 |
* @test |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
26 |
* @bug 8034820 |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
27 |
* @summary Check that adding Principal subclasses to Subject works |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
28 |
*/ |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
29 |
|
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
30 |
import java.security.Principal; |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
31 |
import java.util.Collections; |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
32 |
import java.util.Set; |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
33 |
import javax.security.auth.Subject; |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
34 |
|
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
35 |
public class AddPrincipalSubclass { |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
36 |
|
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
37 |
public static void main(String[] args) throws Exception { |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
38 |
|
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
39 |
// create Subject with no principals and then add TestPrincipal |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
40 |
Subject subject = new Subject(); |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
41 |
Set<Principal> principals = subject.getPrincipals(Principal.class); |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
42 |
Principal principal = new TestPrincipal(); |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
43 |
if (!principals.add(principal)) { |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
44 |
throw new Exception("add returned false instead of true"); |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
45 |
} |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
46 |
if (!principals.contains(principal)) { |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
47 |
throw new Exception("set does not contain principal"); |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
48 |
} |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
49 |
|
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
50 |
// pre-populate Subject with TestPrincipal |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
51 |
subject = new Subject(false, |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
52 |
Collections.singleton(principal), |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
53 |
Collections.emptySet(), Collections.emptySet()); |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
54 |
principals = subject.getPrincipals(Principal.class); |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
55 |
if (!principals.contains(principal)) { |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
56 |
throw new Exception("set does not contain principal"); |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
57 |
} |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
58 |
} |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
59 |
|
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
60 |
private static class TestPrincipal implements Principal { |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
61 |
@Override |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
62 |
public String getName() { |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
63 |
return "TestPrincipal"; |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
64 |
} |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
65 |
} |
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
diff
changeset
|
66 |
} |