/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 4703361
* @summary can not specify Configuration to LoginContext constructor
*
* @run main/othervm/policy=ConfigConstructor.policy -Djava.security.auth.login.config=file:${test.src}/ConfigConstructor.config ConfigConstructor
*
*/
/**
* This test shares the login config with ConfigConstructorNoPerm.
* This test has all necessary permissions configured in the policy
* (ConfigConstructorNoPerm has no perms and checks for SecurityExceptions).
*/
public class ConfigConstructor {
private static Configuration c = new MyConfig();
// test non-null behavior with provided config
("module1",
s,
ch,
c);
// test null behavior with provided config
("module2",
null,
null,
c);
// test null config
("module3",
s,
ch,
null);
// test null config
("module4",
null,
null,
null);
// test security (without permission)
try {
("module5",
null,
null,
c);
throw new SecurityException("test failed - security check failed");
} catch (LoginException le) {
// test passed
} else {
throw new SecurityException("test failed: " +
"LoginException did not have chained SecurityException");
}
}
// test security (with permission)
("module6",
null,
null,
c);
// test other
("goToOther",
null,
null,
c);
// test other old constructor
("goToOther");
}
public MyConfig() { }
("ConfigConstructor$MyModule1",
map);
("ConfigConstructor$MyModule2",
map);
("ConfigConstructor$MyModule3",
map);
("ConfigConstructor$MyModule4",
map);
("ConfigConstructor$MyModule5",
map);
("ConfigConstructor$MyModule6",
map);
("ConfigConstructor$MyModule2",
map);
} else {
}
return entries;
}
public void refresh() { }
}
public MyModule1() { }
if (s != ConfigConstructor.s ||
throw new SecurityException("Module 1 failed");
}
}
}
public MyModule2() { }
if (s == ConfigConstructor.s ||
throw new SecurityException("Module 2 failed");
}
}
}
public MyModule3() { }
if (s != ConfigConstructor.s ||
throw new SecurityException("Module 3 failed");
}
}
}
public MyModule4() { }
if (s == ConfigConstructor.s ||
throw new SecurityException("Module 4 failed");
}
}
}
public MyModule5() { }
// do something security-sensitive
return true;
}
}
public MyModule6() { }
// do something security-sensitive
return true;
}
}
}