Java Code Examples for javax.security.auth.callback.PasswordCallback#setPassword()
The following examples show how to use
javax.security.auth.callback.PasswordCallback#setPassword() .
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 openjdk-jdk8u-backup 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: 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 3
Source File: BurpExtender.java From Berserko with GNU Affero General Public License v3.0 | 6 votes |
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback nc = (NameCallback) callback; if (user == null) { nc.setName(usernameToPrincipal("berserkotest")); } else { nc.setName(usernameToPrincipal(user)); } } else if (callback instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callback; if (user == null) { pc.setPassword("berserkotest".toCharArray()); } else { pc.setPassword(password.toCharArray()); } } else { throw new UnsupportedCallbackException(callback, "Unknown Callback"); } } }
Example 4
Source File: DynamicConfigurationTest.java From openjdk-jdk9 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 5
Source File: Authentication.java From netbeans with Apache License 2.0 | 6 votes |
private CallbackHandler createCallBackHandler(){ return new CallbackHandler() { @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback current : callbacks) { if (current instanceof NameCallback) { NameCallback nameCallback = (NameCallback) current; nameCallback.setName(username); } else if (current instanceof PasswordCallback) { PasswordCallback pwdCallback = (PasswordCallback) current; pwdCallback.setPassword(password); } else if (current instanceof RealmCallback) { RealmCallback realmCallback = (RealmCallback) current; realmCallback.setText(realmCallback.getDefaultText()); } else { throw new UnsupportedCallbackException(current); } } } }; }
Example 6
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 7
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 8
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 9
Source File: LdapCallbackHandler.java From lams with GNU General Public License v2.0 | 6 votes |
protected void setPasswordCallbackValue(Object thePass, PasswordCallback passwdCallback) { String tmp; if(thePass instanceof String) { tmp = (String) thePass; passwdCallback.setPassword(tmp.toCharArray()); } else if(thePass instanceof char[]) { passwdCallback.setPassword((char[])thePass); } else if(thePass instanceof byte[]) { byte[] theBytes = (byte[]) thePass; passwdCallback.setPassword((new String(theBytes).toCharArray())); } else { throw PicketBoxMessages.MESSAGES.invalidPasswordType(thePass != null ? thePass.getClass() : null); } }
Example 10
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 11
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 12
Source File: KerberosAuthenticator2.java From Transwarp-Sample-Code with MIT License | 6 votes |
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback ncb = (NameCallback) callback; ncb.setName(username); } else if (callback instanceof PasswordCallback) { PasswordCallback pwcb = (PasswordCallback) callback; pwcb.setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException( callback, "We got a " + callback.getClass().getCanonicalName() + ", but only NameCallback and PasswordCallback is supported"); } } }
Example 13
Source File: P11KeyStore.java From openjdk-jdk8u 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 14
Source File: P11KeyStore.java From TencentKona-8 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 15
Source File: P11KeyStore.java From dragonwell8_jdk 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 16
Source File: P11KeyStore.java From openjdk-jdk8u-backup 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 17
Source File: JaasKrbUtil.java From deprecated-security-advanced-modules with Apache License 2.0 | 5 votes |
@Override public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof PasswordCallback) { final PasswordCallback pc = (PasswordCallback) callbacks[i]; if (pc.getPrompt().contains(principal)) { pc.setPassword(password.toCharArray()); break; } } } }
Example 18
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 19
Source File: SaslCallbackHandler.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void handle( Callback[] callbacks ) throws IOException, UnsupportedCallbackException { for ( Callback cb : callbacks ) { if ( cb instanceof NameCallback ) { NameCallback ncb = ( NameCallback ) cb; String name = saslReq.getUsername(); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04153_SENDING_NAME_IN_CALLBACK, name ) ); } ncb.setName( name ); } else if ( cb instanceof PasswordCallback ) { PasswordCallback pcb = ( PasswordCallback ) cb; if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04154_SENDING_CREDS_IN_CALLBACK ) ); } pcb.setPassword( Strings.utf8ToString( saslReq.getCredentials() ).toCharArray() ); } else if ( cb instanceof RealmCallback ) { RealmCallback rcb = ( RealmCallback ) cb; if ( saslReq.getRealmName() != null ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04155_SENDING_USER_REALM_IN_CALLBACK, saslReq.getRealmName() ) ); } rcb.setText( saslReq.getRealmName() ); } else { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04156_SENDING_DEFAULT_REALM_IN_CALLBACK, rcb.getDefaultText() ) ); } rcb.setText( rcb.getDefaultText() ); } } else if ( cb instanceof RealmChoiceCallback ) { RealmChoiceCallback rccb = ( RealmChoiceCallback ) cb; boolean foundRealmName = false; String[] realmNames = rccb.getChoices(); for ( int i = 0; i < realmNames.length; i++ ) { String realmName = realmNames[i]; if ( realmName.equals( saslReq.getRealmName() ) ) { foundRealmName = true; if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04157_SENDING_USER_REALM_IN_CALLBACK, realmName ) ); } rccb.setSelectedIndex( i ); break; } } if ( !foundRealmName ) { throw new IOException( I18n.err( I18n.ERR_04171_CANNOT_PARSE_MATCHED_DN, saslReq.getRealmName(), getRealmNamesAsString( realmNames ) ) ); } } } }
Example 20
Source File: JBossCallbackHandler.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Handle a {@code Callback} * @param c callback * @throws UnsupportedCallbackException If the callback is not supported by this handler */ protected void handleCallBack( Callback c ) throws UnsupportedCallbackException { if (c instanceof SecurityAssociationCallback) { SecurityAssociationCallback sac = (SecurityAssociationCallback) c; sac.setPrincipal(principal); sac.setCredential(credential); } else if (c instanceof ObjectCallback) { ObjectCallback oc = (ObjectCallback) c; oc.setCredential(credential); } else if (c instanceof NameCallback) { NameCallback nc = (NameCallback) c; if (principal != null) nc.setName(principal.getName()); } else if (c instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) c; char[] password = getPassword(); if (password != null) pc.setPassword(password); } else { try { CallbackHandler handler = SecurityActions.getContextCallbackHandler(); if( handler != null ) { Callback[] unknown = {c}; handler.handle(unknown); return; } } catch (Exception e) { } throw PicketBoxMessages.MESSAGES.unableToHandleCallback(c, this.getClass().getName(), c.getClass().getCanonicalName()); } }