Path: blob/master/test/jdk/sun/security/pkcs11/Provider/LoginISE.java
51712 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.*;24import java.util.*;25import java.security.*;26import javax.security.auth.callback.*;2728/**29* @test30* @bug 813064831* @summary make sure IllegalStateException is thrown for uninitialized32* SunPKCS11 provider instance33*/34public class LoginISE {3536public static void main(String[] args) throws Exception {3738Provider p = Security.getProvider("SunPKCS11");39if (p == null) {40System.out.println("No un-initialized PKCS11 provider available; skip");41return;42}43if (!(p instanceof AuthProvider)) {44throw new RuntimeException("Error: expect AuthProvider!");45}46AuthProvider ap = (AuthProvider) p;47if (ap.isConfigured()) {48throw new RuntimeException("Fail: isConfigured() should return false");49}50try {51ap.login(null, null);52throw new RuntimeException("Fail: expected ISE not thrown!");53} catch (IllegalStateException ise) {54System.out.println("Expected ISE thrown for login call");55}56try {57ap.logout();58throw new RuntimeException("Fail: expected ISE not thrown!");59} catch (IllegalStateException ise) {60System.out.println("Expected ISE thrown for logout call");61}62try {63ap.setCallbackHandler(new PasswordCallbackHandler());64throw new RuntimeException("Fail: expected ISE not thrown!");65} catch (IllegalStateException ise) {66System.out.println("Expected ISE thrown for logout call");67}6869System.out.println("Test Passed");70}7172public static class PasswordCallbackHandler implements CallbackHandler {73public void handle(Callback[] callbacks)74throws IOException, UnsupportedCallbackException {75}76}77}787980