0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4703361
0N/A * @summary can not specify Configuration to LoginContext constructor
0N/A *
0N/A * @run main/othervm/policy=ConfigConstructorNoPerm.policy -Djava.security.auth.login.config=file:${test.src}/ConfigConstructor.config ConfigConstructorNoPerm
0N/A */
0N/A
0N/A/**
0N/A * This test shares the login config with ConfigConstructor.
0N/A * This test has no configured permissions
0N/A * (ConfigConstructor tests code with perms configured).
0N/A */
0N/A
0N/Aimport java.util.Map;
0N/Aimport javax.security.auth.*;
0N/Aimport javax.security.auth.login.*;
0N/Aimport javax.security.auth.spi.*;
0N/Aimport javax.security.auth.callback.*;
0N/A
0N/Apublic class ConfigConstructorNoPerm {
0N/A
0N/A private static Subject s = new Subject();
0N/A private static CallbackHandler ch =
0N/A new com.sun.security.auth.callback.TextCallbackHandler();
0N/A private static Configuration c = new MyConfig();
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A // test old constructor with no permission
0N/A try {
0N/A LoginContext lc1 = new LoginContext
0N/A ("module1",
0N/A s,
0N/A ch);
0N/A throw new RuntimeException("Test 1 Failed");
0N/A } catch (SecurityException se) {
0N/A // test passed
0N/A }
0N/A System.out.println("Test 1 Succeeded");
0N/A
0N/A // test new constructor (null config) with no permission
0N/A try {
0N/A LoginContext lc2 = new LoginContext
0N/A ("module1",
0N/A s,
0N/A ch,
0N/A null);
0N/A throw new RuntimeException("Test 2 Failed");
0N/A } catch (SecurityException se) {
0N/A // test passed
0N/A }
0N/A System.out.println("Test 2 Succeeded");
0N/A
0N/A // test new constructor (config) - no permission needed
0N/A // (and none configured)
0N/A LoginContext lc3 = new LoginContext
0N/A ("module1",
0N/A s,
0N/A ch,
0N/A c);
0N/A System.out.println("Test 3 Succeeded");
0N/A
0N/A // test old constructor with no permission for other
0N/A try {
0N/A LoginContext lc4 = new LoginContext
0N/A ("goToOther",
0N/A s,
0N/A ch);
0N/A throw new RuntimeException("Test 4 Failed");
0N/A } catch (SecurityException se) {
0N/A // test passed
0N/A }
0N/A System.out.println("Test 4 Succeeded");
0N/A
0N/A // test new constructor with no permission for other
0N/A try {
0N/A LoginContext lc5 = new LoginContext
0N/A ("goToOther",
0N/A s,
0N/A ch,
0N/A null);
0N/A throw new RuntimeException("Test 5 Failed");
0N/A } catch (SecurityException se) {
0N/A // test passed
0N/A }
0N/A System.out.println("Test 5 Succeeded");
0N/A }
0N/A
0N/A private static class MyConfig extends Configuration {
0N/A public MyConfig() { }
0N/A public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
0N/A java.util.HashMap map = new java.util.HashMap();
0N/A AppConfigurationEntry[] entries = new AppConfigurationEntry[1];
0N/A
0N/A if (name.equals("module1")) {
0N/A AppConfigurationEntry entry = new AppConfigurationEntry
0N/A ("ConfigConstructor$MyModule1",
0N/A AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
0N/A map);
0N/A entries[0] = entry;
0N/A } else {
0N/A entries = null;
0N/A }
0N/A return entries;
0N/A }
0N/A public void refresh() { }
0N/A }
0N/A}