test/jdk/sun/security/util/Resources/Format.java
author prr
Fri, 25 May 2018 12:12:24 -0700
changeset 50347 b2f046ae8eb6
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14182
3041082abb40 7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @author Charlie Lai
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 4394746
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary     Resources should not be loaded until necessar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @run main/othervm/policy=Format.policy -Djava.security.auth.login.config=file:${test.src}/Format.config Format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.security.auth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.security.auth.login.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.security.auth.callback.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.security.auth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class Format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    implements java.io.Serializable, java.security.Principal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public String getName() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            PrivateCredentialPermission pcp = new PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                ("test", "write");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            throw new SecurityException("test 1 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            System.out.println("Test 1: " + iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            PrivateCredentialPermission pcp = new PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                ("Format", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            throw new SecurityException("test 2 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            System.out.println("Test 2: " + iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            PrivateCredentialPermission pcp = new PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                ("Format Format", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            throw new SecurityException("test 3 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            System.out.println("Test 3: " + iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            PrivateCredentialPermission pcp = new PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                ("Format Format Format", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            throw new SecurityException("test 4 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            System.out.println("Test 4: " + iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            PrivateCredentialPermission pcp = new PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                ("Format Format \"Format", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            throw new SecurityException("test 5 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            System.out.println("Test 5: " + iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            PrivateCredentialPermission pcp = new PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                ("Format * \"Format\"", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            throw new SecurityException("test 6 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            System.out.println("Test 6: " + iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            javax.security.auth.x500.X500Principal p =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                new javax.security.auth.x500.X500Principal((String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            throw new SecurityException("test 7 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            System.out.println("Test 7: " + npe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            Subject s = new Subject(false, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            throw new SecurityException("test 8 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.out.println("Test 8: " + npe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            Subject.getSubject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw new SecurityException("test 9 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            System.out.println("Test 9: " + npe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            Subject.doAs(null, (java.security.PrivilegedAction)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throw new SecurityException("test 10 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            System.out.println("Test 10: " + npe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            Subject s = new Subject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            s.getPrincipals(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new SecurityException("test 11 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            System.out.println("Test 11: " + npe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            Subject s = new Subject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            s.getPrincipals().add(new javax.security.auth.x500.X500Principal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                        ("cn=test1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            s.getPublicCredentials().add(new Format());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            s.getPrivateCredentials().add(new Format());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            System.out.println("Test 12, s.toString() = " + s.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } catch (Exception e) {
14182
3041082abb40 7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents: 5506
diff changeset
   153
            throw new SecurityException("test 12 failed: e.toString()", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            Subject s = new Subject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            s.getPrincipals().add(new javax.security.auth.x500.X500Principal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                        ("cn=test1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            s.setReadOnly();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            java.util.Iterator i = s.getPrincipals().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            i.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            throw new SecurityException("test 13 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } catch (IllegalStateException ise) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            System.out.println("Test 13: " + ise.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            Subject s = new Subject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            s.getPrincipals().add(new Format());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            throw new SecurityException("test 14 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            System.out.println("Test 14: " + se.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            Subject s = new Subject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            s.getPrincipals((Class)Format.class).add(new Subject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            throw new SecurityException("test 15 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            System.out.println("Test 15: " + se.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            LoginContext lc = new LoginContext(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new SecurityException("test 16 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        } catch (LoginException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            System.out.println("Test 16: " + le.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            LoginContext lc = new LoginContext("nothing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            throw new SecurityException("test 17 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        } catch (LoginException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            System.out.println("Test 17: " + le.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            LoginContext lc = new LoginContext("test", (Subject)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            throw new SecurityException("test 18 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } catch (LoginException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            System.out.println("Test 18: " + le.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            LoginContext lc = new LoginContext("test", (CallbackHandler)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            throw new SecurityException("test 19 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        } catch (LoginException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            System.out.println("Test 19: " + le.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            LoginContext lc = new LoginContext("test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            lc.logout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            throw new SecurityException("test 20 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        } catch (LoginException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            System.out.println("Test 20: " + le.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            LoginContext lc = new LoginContext("test2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            lc.login();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            throw new SecurityException("test 21 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        } catch (LoginException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            System.out.println("Test 21: " + le.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        /***    TESTS FOR THE COM PACKAGE RESOURCES     ***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            NTDomainPrincipal p = new NTDomainPrincipal(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            throw new SecurityException("test 22 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        } catch (NullPointerException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            System.out.println("Test 22: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            NTDomainPrincipal p = new NTDomainPrincipal("test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            System.out.println("NTDomainPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            throw new SecurityException("test 23 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            NTNumericCredential p = new NTNumericCredential(1L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            System.out.println("NTNumericCredential = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw new SecurityException("test 24 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            NTSid p = new NTSid("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            throw new SecurityException("test 25 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            System.out.println("Test 25: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            NTSid p = new NTSid("test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            System.out.println("NTSid = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            throw new SecurityException("test 26 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            NTSidDomainPrincipal p = new NTSidDomainPrincipal("test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            System.out.println("NTSidDomainPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            throw new SecurityException("test 27 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            NTSidGroupPrincipal p = new NTSidGroupPrincipal("test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            System.out.println("NTSidGroupPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            throw new SecurityException("test 28 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            NTSidPrimaryGroupPrincipal p =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                new NTSidPrimaryGroupPrincipal("test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            System.out.println("NTSidPrimaryGroupPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            throw new SecurityException("test 29 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            NTSidUserPrincipal p = new NTSidUserPrincipal("test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            System.out.println("NTSidUserPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            throw new SecurityException("test 30 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            NTUserPrincipal p = new NTUserPrincipal("test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            System.out.println("NTUserPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            throw new SecurityException("test 31 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            UnixNumericGroupPrincipal p = new UnixNumericGroupPrincipal("0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                                                true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            System.out.println("NTPrimaryGroupPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            throw new SecurityException("test 32 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            UnixNumericGroupPrincipal p = new UnixNumericGroupPrincipal("1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                                                                false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            System.out.println("UnixNumericGroupPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            throw new SecurityException("test 33 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            UnixNumericUserPrincipal p = new UnixNumericUserPrincipal("2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            System.out.println("UnixNumericUserPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            throw new SecurityException("test 34 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            UnixPrincipal p = new UnixPrincipal("test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            System.out.println("UnixPrincipal = " + p.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            throw new SecurityException("test 35 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        System.out.println("Format test succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
}