List of usage examples for javax.security.sasl RealmCallback getDefaultText
public String getDefaultText()
From source file:org.hawkular.wildfly.agent.itest.util.AbstractITest.java
protected static ModelControllerClient newModelControllerClient(final String host, final int managementPort) { final CallbackHandler callbackHandler = new CallbackHandler() { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback current : callbacks) { if (current instanceof NameCallback) { NameCallback ncb = (NameCallback) current; log.fine("ModelControllerClient is sending a username [" + managementUser + "]"); ncb.setName(managementUser); } else if (current instanceof PasswordCallback) { PasswordCallback pcb = (PasswordCallback) current; log.fine("ModelControllerClient is sending a password [" + managementPasword + "]"); pcb.setPassword(managementPasword.toCharArray()); } else if (current instanceof RealmCallback) { RealmCallback rcb = (RealmCallback) current; log.fine("ModelControllerClient is sending a realm [" + rcb.getDefaultText() + "]"); rcb.setText(rcb.getDefaultText()); } else { throw new UnsupportedCallbackException(current); }/*w w w .j ava 2 s . c o m*/ } } }; try { InetAddress inetAddr = InetAddress.getByName(host); log.fine("Connecting a ModelControllerClient to [" + host + ":" + managementPort + "]"); return ModelControllerClient.Factory.create(inetAddr, managementPort, callbackHandler); } catch (Exception e) { throw new RuntimeException("Failed to create management client", e); } }
From source file:org.apache.accumulo.core.rpc.SaslClientDigestCallbackHandler.java
@Override public void handle(Callback[] callbacks) throws UnsupportedCallbackException { NameCallback nc = null;/*from www. ja va2 s . c om*/ PasswordCallback pc = null; RealmCallback rc = null; for (Callback callback : callbacks) { if (callback instanceof RealmChoiceCallback) { continue; } else if (callback instanceof NameCallback) { nc = (NameCallback) callback; } else if (callback instanceof PasswordCallback) { pc = (PasswordCallback) callback; } else if (callback instanceof RealmCallback) { rc = (RealmCallback) callback; } else { throw new UnsupportedCallbackException(callback, "Unrecognized SASL client callback"); } } if (nc != null) { log.debug("SASL client callback: setting username: {}", userName); nc.setName(userName); } if (pc != null) { log.debug("SASL client callback: setting userPassword"); pc.setPassword(userPassword); } if (rc != null) { log.debug("SASL client callback: setting realm: {}", rc.getDefaultText()); rc.setText(rc.getDefaultText()); } }
From source file:org.apache.directory.server.ldap.handlers.sasl.AbstractSaslCallbackHandler.java
/** * SaslServer will use this method to call various callbacks, depending on the SASL * mechanism in use for a session.// w w w.j a v a2s . c o m * * @param callbacks An array of one or more callbacks. */ public void handle(Callback[] callbacks) { for (int i = 0; i < callbacks.length; i++) { Callback callback = callbacks[i]; if (LOG.isDebugEnabled()) { LOG.debug("Processing callback {} of {}: {}", callback.getClass(), (i + 1), callbacks.length); } if (callback instanceof NameCallback) { NameCallback nameCB = (NameCallback) callback; LOG.debug("NameCallback default name: {}", nameCB.getDefaultName()); username = nameCB.getDefaultName(); } else if (callback instanceof RealmCallback) { RealmCallback realmCB = (RealmCallback) callback; LOG.debug("RealmCallback default text: {}", realmCB.getDefaultText()); realm = realmCB.getDefaultText(); } else if (callback instanceof PasswordCallback) { PasswordCallback passwordCB = (PasswordCallback) callback; Attribute userPassword = lookupPassword(getUsername(), getRealm()); if (userPassword != null) { // We assume that we have only one password available byte[] password = userPassword.get().getBytes(); String strPassword = Strings.utf8ToString(password); passwordCB.setPassword(strPassword.toCharArray()); } } else if (callback instanceof AuthorizeCallback) { AuthorizeCallback authorizeCB = (AuthorizeCallback) callback; // hnelson (CRAM-MD5, DIGEST-MD5) // hnelson@EXAMPLE.COM (GSSAPI) LOG.debug("AuthorizeCallback authnID: {}", authorizeCB.getAuthenticationID()); // hnelson (CRAM-MD5, DIGEST-MD5) // hnelson@EXAMPLE.COM (GSSAPI) LOG.debug("AuthorizeCallback authzID: {}", authorizeCB.getAuthorizationID()); // null (CRAM-MD5, DIGEST-MD5, GSSAPI) LOG.debug("AuthorizeCallback authorizedID: {}", authorizeCB.getAuthorizedID()); // false (CRAM-MD5, DIGEST-MD5, GSSAPI) LOG.debug("AuthorizeCallback isAuthorized: {}", authorizeCB.isAuthorized()); try { authorize(authorizeCB); } catch (Exception e) { // TODO - figure out how to handle this properly. throw new RuntimeException(I18n.err(I18n.ERR_677), e); } } } }