Get the Keystore alias and relevant passwords. Retrieve the alias's principal and credentials from the Keystore.
@exception FailedLoginException if the authentication fails.
@return true in all cases (this LoginModuleshould not be ignored).
LoginModule
96979899100101102103104105106
Subject s = new Subject(); Map options = new HashMap(); options.put(O_TYPE, P11KEYSTORE); m.initialize(s, null, null, options); try { m.login(); throw new SecurityException("expected exception"); } catch (LoginException le) { // good //le.printStackTrace(); System.out.println("test " + testnum++ + " passed");
113114115116117118119120121122123
options.put(O_TYPE, P11KEYSTORE); options.put(O_URL, NONE); options.put(O_KPASS_URL, KPASS_URL); m.initialize(s, null, null, options); try { m.login(); throw new SecurityException("expected exception"); } catch (LoginException le) { // good //le.printStackTrace(); System.out.println("test " + testnum++ + " passed");
128129130131132133134135136137138
options = new HashMap(); options.put(O_PPATH, "true"); options.put(O_SPASS_URL, SPASS_URL); m.initialize(s, null, null, options); try { m.login(); throw new SecurityException("expected exception"); } catch (LoginException le) { // good //le.printStackTrace(); System.out.println("test " + testnum++ + " passed");
143144145146147148149150151152153
options = new HashMap(); options.put(O_PPATH, "true"); options.put(O_KPASS_URL, KPASS_URL); m.initialize(s, null, null, options); try { m.login(); throw new SecurityException("expected exception"); } catch (LoginException le) { // good //le.printStackTrace(); System.out.println("test " + testnum++ + " passed");
161162163164165166167168169170171
KeyStoreLoginModule m = new KeyStoreLoginModule(); Subject s = new Subject(); Map options = new HashMap(); m.initialize(s, null, null, options); try { m.login(); throw new SecurityException("expected exception"); } catch (LoginException le) { // good //le.printStackTrace(); System.out.println("test " + testnum++ + " passed");
174175176177178179180181182183184
// missing passwords options.put(O_ALIAS, ALIAS); m.initialize(s, null, null, options); try { m.login(); throw new SecurityException("expected exception"); } catch (LoginException le) { // good //le.printStackTrace(); System.out.println("test " + testnum++ + " passed");
188189190191192193194195196197198
// (private key password is different from store password) options.put(O_SPASS_URL, SPASS_URL); m.initialize(s, null, null, options); try { m.login(); throw new SecurityException("expected exception"); } catch (LoginException le) { // good //le.printStackTrace(); System.out.println("test " + testnum++ + " passed");
202203204205206207208209210211212
// (private key password is different from store password) options.put(O_URL, URL); options.put(O_KPASS_URL, KPASS_URL); m.initialize(s, null, null, options); m.login(); System.out.println("test " + testnum++ + " passed"); } private static void testWithCallbackHandler() throws Exception {
215216217218219220221222223224225
Map options = new HashMap(); options.put(O_URL, URL); CallbackHandler goodHandler = new MyCallbackHandler(true); m.initialize(s, goodHandler, null, options); m.login(); System.out.println("test " + testnum++ + " passed"); CallbackHandler badHandler = new MyCallbackHandler(false); m.initialize(s, badHandler, null, options); try {
221222223224225226227228229230231
System.out.println("test " + testnum++ + " passed"); CallbackHandler badHandler = new MyCallbackHandler(false); m.initialize(s, badHandler, null, options); try { m.login(); throw new SecurityException("expected LoginException"); } catch (LoginException le) { // good System.out.println("test " + testnum++ + " passed"); }