/*
* 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 4919147
* @summary Support for token-based KeyStores
*/
public class TokenStore {
"grant { permission java.security.AllPermission; };";
"keystore \"file:${test.src}${/}TokenStore.keystore\";" +
"grant signedby \"POLICY_URL\" {" +
" permission java.security.AllPermission;" +
"};" ;
"keystore \"file:${test.src}${/}TokenStore.keystore\", \"JKS\";"+
"grant signedby \"POLICY_URL_T\" {" +
" permission java.security.AllPermission;" +
"};" ;
"keystore \"file:${test.src}${/}TokenStore.keystore\"," +
" \"JKS\", \"SUN\";" +
"grant signedby \"POLICY_URL_T_P\" {" +
" permission java.security.AllPermission;" +
"};" ;
"keystore \"file:${test.src}${/}TokenStore.keystore\";" +
"keystorePasswordURL \"file:${test.src}${/}TokenStore.pwd\";" +
"grant signedby \"POLICY_URL\" {" +
" permission java.security.AllPermission;" +
"};" ;
"keystore \"file:${test.src}${/}TokenStore.keystore\"," +
" \"JKS\", \"SUN\";" +
"keystorePasswordURL \"file:${test.src}${/}TokenStore.pwd\";" +
"grant signedby \"POLICY_URL_T_P\" {" +
" permission java.security.AllPermission;" +
"};" ;
"keystorePasswordURL \"file:${test.src}${/}TokenStore.pwd\";" +
"grant signedby \"POLICY_URL_T_P\" {" +
" permission java.security.AllPermission;" +
"};" ;
// test no key store in policy
PolicyParser p = new PolicyParser();
doNoStore(p);
doNoStore(p);
// test policy keystore + URL
p = new PolicyParser();
doURL(p, true);
sw = new StringWriter();
newP = new PolicyParser();
doURL(p, true);
// test policy keystore + URL + type
p = new PolicyParser();
doURL_T(p, true);
sw = new StringWriter();
newP = new PolicyParser();
doURL_T(p, true);
// test policy keystore + URL + type + provider
p = new PolicyParser();
doURL_T_P(p, true);
sw = new StringWriter();
newP = new PolicyParser();
doURL_T_P(p, true);
// test policy keystore + URL + password
p = new PolicyParser();
doURL(p, false);
doPwd(p);
sw = new StringWriter();
newP = new PolicyParser();
doURL(p, false);
doPwd(p);
// test policy keystore + URL + type + provider + password
p = new PolicyParser();
doURL_T_P(p, false);
doPwd(p);
sw = new StringWriter();
newP = new PolicyParser();
doURL_T_P(p, false);
doPwd(p);
// test policy password with no keystore
p = new PolicyParser();
try {
throw new SecurityException("expected parsing exception");
// good
}
}
Enumeration e = p.grantElements();
boolean foundOne = false;
while (e.hasMoreElements()) {
e.nextElement();
throw new SecurityException("expected non-null perms");
} else {
foundOne = true;
}
}
if (!foundOne) {
throw new SecurityException("expected non-null grant entries");
}
}
if (p.getKeyStoreUrl() != null ||
p.getKeyStoreType() != null ||
p.getKeyStoreProvider() != null ||
p.getStorePassURL() != null) {
throw new SecurityException("expected null keystore");
}
checkPerm(p);
}
throws Exception {
if (p.getKeyStoreUrl() == null ||
p.getKeyStoreType() != null ||
p.getKeyStoreProvider() != null) {
throw new SecurityException("invalid keystore values");
}
if (checkPwd) {
if (p.getStorePassURL() != null) {
throw new SecurityException("invalid keystore values");
}
}
checkPerm(p);
}
throws Exception {
if (p.getKeyStoreUrl() == null ||
p.getKeyStoreType() == null ||
p.getKeyStoreProvider() != null) {
throw new SecurityException("invalid keystore values");
}
if (checkPwd) {
if (p.getStorePassURL() != null) {
throw new SecurityException("invalid keystore values");
}
}
checkPerm(p);
}
throws Exception {
if (p.getKeyStoreUrl() == null ||
p.getKeyStoreType() == null ||
p.getKeyStoreProvider() == null ||
throw new SecurityException("invalid keystore values");
}
if (checkPwd) {
if (p.getStorePassURL() != null) {
throw new SecurityException("invalid keystore values");
}
}
checkPerm(p);
}
if (p.getStorePassURL() == null ||
throw new SecurityException("invalid password values");
}
}
}