javax.security.auth.callback.PasswordCallback Java Examples
The following examples show how to use
javax.security.auth.callback.PasswordCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicConfigurationTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback nc = (NameCallback) callback; nc.setName(userName); } else if (callback instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callback; pc.setPassword(password); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
Example #2
Source File: DynamicConfigurationTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback nc = (NameCallback) callback; nc.setName(userName); } else if (callback instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callback; pc.setPassword(password); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
Example #3
Source File: DynamicConfigurationTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback nc = (NameCallback) callback; nc.setName(userName); } else if (callback instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callback; pc.setPassword(password); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
Example #4
Source File: AbstractPasswordFilePrincipalDatabase.java From qpid-broker-j with Apache License 2.0 | 6 votes |
/** * SASL Callback Mechanism - sets the Password in the PasswordCallback based on the value in the PasswordFile * If you want to change the password for a user, use updatePassword instead. * * @param principal The Principal to set the password for * @param callback The PasswordCallback to call setPassword on * * @throws javax.security.auth.login.AccountNotFoundException If the Principal cannot be found in this Database */ @Override public final void setPassword(Principal principal, PasswordCallback callback) throws AccountNotFoundException { if (_passwordFile == null) { throw new AccountNotFoundException("Unable to locate principal since no password file was specified during initialisation"); } if (principal == null) { throw new IllegalArgumentException("principal must not be null"); } char[] pwd = lookupPassword(principal.getName()); if (pwd != null) { callback.setPassword(pwd); } else { throw new AccountNotFoundException("No account found for principal " + principal); } }
Example #5
Source File: NegotiateCallbackHandler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public void handle(Callback[] callbacks) throws UnsupportedCallbackException, IOException { for (int i=0; i<callbacks.length; i++) { Callback callBack = callbacks[i]; if (callBack instanceof NameCallback) { getAnswer(); ((NameCallback)callBack).setName(username); } else if (callBack instanceof PasswordCallback) { getAnswer(); ((PasswordCallback)callBack).setPassword(password); if (password != null) Arrays.fill(password, ' '); } else { throw new UnsupportedCallbackException(callBack, "Call back not supported"); } } }
Example #6
Source File: DynamicConfigurationTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback nc = (NameCallback) callback; nc.setName(userName); } else if (callback instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callback; pc.setPassword(password); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
Example #7
Source File: NegotiateCallbackHandler.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void handle(Callback[] callbacks) throws UnsupportedCallbackException, IOException { for (int i=0; i<callbacks.length; i++) { Callback callBack = callbacks[i]; if (callBack instanceof NameCallback) { getAnswer(); ((NameCallback)callBack).setName(username); } else if (callBack instanceof PasswordCallback) { getAnswer(); ((PasswordCallback)callBack).setPassword(password); if (password != null) Arrays.fill(password, ' '); } else { throw new UnsupportedCallbackException(callBack, "Call back not supported"); } } }
Example #8
Source File: NegotiateCallbackHandler.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void handle(Callback[] callbacks) throws UnsupportedCallbackException, IOException { for (int i=0; i<callbacks.length; i++) { Callback callBack = callbacks[i]; if (callBack instanceof NameCallback) { getAnswer(); ((NameCallback)callBack).setName(username); } else if (callBack instanceof PasswordCallback) { getAnswer(); ((PasswordCallback)callBack).setPassword(password); if (password != null) Arrays.fill(password, ' '); } else { throw new UnsupportedCallbackException(callBack, "Call back not supported"); } } }
Example #9
Source File: SSLAndKerberosTest.java From atlas with Apache License 2.0 | 6 votes |
protected Subject loginTestUser() throws LoginException, IOException { LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() { @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof PasswordCallback) { PasswordCallback passwordCallback = (PasswordCallback) callback; passwordCallback.setPassword(TESTPASS.toCharArray()); } if (callback instanceof NameCallback) { NameCallback nameCallback = (NameCallback) callback; nameCallback.setName(TESTUSER); } } } }); // attempt authentication lc.login(); return lc.getSubject(); }
Example #10
Source File: AtlasAuthenticationKerberosFilterTest.java From atlas with Apache License 2.0 | 6 votes |
protected Subject loginTestUser() throws LoginException, IOException { LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() { @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof PasswordCallback) { PasswordCallback passwordCallback = (PasswordCallback) callback; passwordCallback.setPassword(TESTPASS.toCharArray()); } if (callback instanceof NameCallback) { NameCallback nameCallback = (NameCallback) callback; nameCallback.setName(TESTUSER); } } } }); // attempt authentication lc.login(); return lc.getSubject(); }
Example #11
Source File: KeyStoreLoginModule.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void saveStorePass(PasswordCallback c) { keyStorePassword = c.getPassword(); if (keyStorePassword == null) { /* Treat a NULL password as an empty password */ keyStorePassword = new char[0]; } c.clearPassword(); }
Example #12
Source File: Helper.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public void handle(Callback[] callbacks) throws UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword( password.toCharArray()); } else if (callback instanceof NameCallback) { ((NameCallback)callback).setName(name); } else { throw new UnsupportedCallbackException(callback); } } }
Example #13
Source File: CleanState.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void go() throws Exception { Krb5LoginModule krb5 = new Krb5LoginModule(); final String name = OneKDC.USER; final char[] password = OneKDC.PASS; char[] badpassword = "hellokitty".toCharArray(); Map<String,String> map = new HashMap<>(); map.put("useTicketCache", "false"); map.put("doNotPrompt", "false"); map.put("tryFirstPass", "true"); Map<String,Object> shared = new HashMap<>(); shared.put("javax.security.auth.login.name", name); shared.put("javax.security.auth.login.password", badpassword); krb5.initialize(new Subject(), new CallbackHandler() { @Override public void handle(Callback[] callbacks) { for(Callback callback: callbacks) { if (callback instanceof NameCallback) { ((NameCallback)callback).setName(name); } if (callback instanceof PasswordCallback) { ((PasswordCallback)callback).setPassword(password); } } } }, shared, map); krb5.login(); }
Example #14
Source File: OkAsDelegateXRealm.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { ((NameCallback) callback).setName("dummy"); } if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword("bogus".toCharArray()); } } }
Example #15
Source File: DisabledMechanisms.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { String authorizationId = "username"; String protocol = "ldap"; String serverName = "server1"; Map props = Collections.emptyMap(); String disabled = System.getProperty("disabledMechanisms"); if (disabled != null) { Security.setProperty("jdk.sasl.disabledMechanisms", disabled); } CallbackHandler callbackHandler = callbacks -> { for (Callback cb : callbacks) { if (cb instanceof PasswordCallback) { ((PasswordCallback) cb).setPassword("password".toCharArray()); } } }; SaslClient client = Sasl.createSaslClient( new String[]{"DIGEST-MD5", "NTLM"}, authorizationId, protocol, serverName, props, callbackHandler); Asserts.assertEQ(client == null ? null : client.getMechanismName(), args[0].equals("null") ? null : args[0]); SaslServer server = Sasl.createSaslServer( "DIGEST-MD5", protocol, serverName, props, callbackHandler); Asserts.assertEQ(server == null ? null : server.getMechanismName(), args[1].equals("null") ? null : args[1]); }
Example #16
Source File: CrossRealm.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { ((NameCallback) callback).setName("dummy"); } if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword("bogus".toCharArray()); } } }
Example #17
Source File: JaasAuthenticationHandler.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Override public void handle(final Callback[] callbacks) throws UnsupportedCallbackException { for (final Callback callback : callbacks) { if (callback.getClass().equals(NameCallback.class)) { ((NameCallback) callback).setName(this.userName); } else if (callback.getClass().equals(PasswordCallback.class)) { ((PasswordCallback) callback).setPassword(this.password .toCharArray()); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
Example #18
Source File: LoginModuleOptions.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void handle(Callback[] callbacks) { for (Callback callback : callbacks) { System.err.println(callback); if (callback instanceof NameCallback) { System.err.println("name is " + name); ((NameCallback) callback).setName(name); } if (callback instanceof PasswordCallback) { System.err.println("pass is " + new String(password)); ((PasswordCallback) callback).setPassword(password); } } }
Example #19
Source File: JaasAuthenticationHandler.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException { for (final Callback callback : callbacks) { if (callback.getClass().equals(NameCallback.class)) { ((NameCallback) callback).setName(this.userName); } else if (callback.getClass().equals(PasswordCallback.class)) { ((PasswordCallback) callback).setPassword(this.password .toCharArray()); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
Example #20
Source File: P11KeyStore.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { if (!(callbacks[0] instanceof PasswordCallback)) { throw new UnsupportedCallbackException(callbacks[0]); } PasswordCallback pc = (PasswordCallback)callbacks[0]; pc.setPassword(password); // this clones the password if not null }
Example #21
Source File: ClientCertificateTest.java From davmail with GNU General Public License v2.0 | 5 votes |
protected KeyStore.ProtectionParameter getProtectionParameter(String password) { if (password != null && password.length() > 0) { // password provided: create a PasswordProtection return new KeyStore.PasswordProtection(password.toCharArray()); } else { // request password at runtime through a callback return new KeyStore.CallbackHandlerProtection(callbacks -> { if (callbacks.length > 0 && callbacks[0] instanceof PasswordCallback) { PasswordPromptDialog passwordPromptDialog = new PasswordPromptDialog(((PasswordCallback) callbacks[0]).getPrompt()); ((PasswordCallback) callbacks[0]).setPassword(passwordPromptDialog.getPassword()); } }); } }
Example #22
Source File: KeyStoreLoginModule.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void saveStorePass(PasswordCallback c) { keyStorePassword = c.getPassword(); if (keyStorePassword == null) { /* Treat a NULL password as an empty password */ keyStorePassword = new char[0]; } c.clearPassword(); }
Example #23
Source File: Helper.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public void handle(Callback[] callbacks) throws UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword( password.toCharArray()); } else if (callback instanceof NameCallback) { ((NameCallback)callback).setName(name); } else { throw new UnsupportedCallbackException(callback); } } }
Example #24
Source File: KeyStoreLoginModule.java From JDKSourceCode1.8 with MIT License | 5 votes |
private void saveKeyPass(PasswordCallback c) { privateKeyPassword = c.getPassword(); if (privateKeyPassword == null || privateKeyPassword.length == 0) { /* * Use keystore password if no private key password is * specified. */ privateKeyPassword = keyStorePassword; } c.clearPassword(); }
Example #25
Source File: KeyStoreLoginModule.java From JDKSourceCode1.8 with MIT License | 5 votes |
private void saveStorePass(PasswordCallback c) { keyStorePassword = c.getPassword(); if (keyStorePassword == null) { /* Treat a NULL password as an empty password */ keyStorePassword = new char[0]; } c.clearPassword(); }
Example #26
Source File: UniversalLoginModule.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Called by login() to acquire the username and password strings for authentication. This method does no validation * of either. * * @return String[], [0] = username, [1] = password */ private String[] getUsernameAndPassword() throws LoginException { if (callbackHandler == null) { throw new LoginException("No CallbackHandler available to collect authentication information"); } NameCallback nc = new NameCallback("User name: ", "guest"); PasswordCallback pc = new PasswordCallback("Password: ", false); Callback[] callbacks = { nc, pc }; String username = null; String password = null; try { callbackHandler.handle(callbacks); username = nc.getName(); char[] tmpPassword = pc.getPassword(); if (tmpPassword != null) { credential = new char[tmpPassword.length]; System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length); pc.clearPassword(); password = new String(credential); } } catch (IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("CallbackHandler does not support: " + uce.getCallback()); } return new String[] { username, password }; }
Example #27
Source File: UsernamePasswordHandler.java From lams with GNU General Public License v2.0 | 5 votes |
/** Sets any NameCallback name property to the instance username, sets any PasswordCallback password property to the instance, and any password. @exception UnsupportedCallbackException, thrown if any callback of type other than NameCallback or PasswordCallback are seen. */ public void handle(Callback[] callbacks) throws UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { Callback c = callbacks[i]; if (c instanceof NameCallback) { NameCallback nc = (NameCallback) c; nc.setName(username); } else if (c instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) c; if( password == null ) { // We were given an opaque Object credential but a char[] is requested? if( credential != null ) { String tmp = credential.toString(); password = tmp.toCharArray(); } } pc.setPassword(password); } else if (c instanceof ObjectCallback) { ObjectCallback oc = (ObjectCallback) c; oc.setCredential(credential); } else { throw PicketBoxMessages.MESSAGES.unableToHandleCallback(c, this.getClass().getName(), c.getClass().getCanonicalName()); } } }
Example #28
Source File: LoginModuleOptions.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void handle(Callback[] callbacks) { for (Callback callback : callbacks) { System.err.println(callback); if (callback instanceof NameCallback) { System.err.println("name is " + name); ((NameCallback) callback).setName(name); } if (callback instanceof PasswordCallback) { System.err.println("pass is " + new String(password)); ((PasswordCallback) callback).setPassword(password); } } }
Example #29
Source File: OneKDC.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void handle(Callback[] callbacks) { String user = OneKDC.USER; char[] pass = OneKDC.PASS; for (Callback callback : callbacks) { if (callback instanceof NameCallback) { System.out.println("Callback for name: " + user); ((NameCallback) callback).setName(user); } if (callback instanceof PasswordCallback) { System.out.println("Callback for pass: " + new String(pass)); ((PasswordCallback) callback).setPassword(pass); } } }
Example #30
Source File: KeyStoreLoginModule.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void saveStorePass(PasswordCallback c) { keyStorePassword = c.getPassword(); if (keyStorePassword == null) { /* Treat a NULL password as an empty password */ keyStorePassword = new char[0]; } c.clearPassword(); }