Java Code Examples for javax.security.auth.callback.PasswordCallback

The following are top voted examples for showing how to use javax.security.auth.callback.PasswordCallback. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: boutique-de-jus   File: LoginModuleAuthSupport.java   Source Code and License 7 votes vote down vote up
@Override
public Optional<Subject> map(final Optional<Object> wrapper) {
    try {
        LOG.info("logging in user as {}", username);
        LoginContext lc = new LoginContext("PropertyFile", callbacks -> {
            LOG.info("Callback Handler invoked ");
            Stream.of(callbacks).forEach(cb -> {
                if (cb instanceof NameCallback) {
                    ((NameCallback) cb).setName(username);
                } else if (cb instanceof PasswordCallback) {
                    ((PasswordCallback) cb).setPassword(password.toCharArray());
                }
            });
        });
        lc.login();
        return Optional.of(lc.getSubject());
    } catch (LoginException e) {
        LOG.error("Authentication failed", e);
        return Optional.empty();
    }
}
 
Example 2
Project: fcrepo3-security-jaas   File: AuthFilterJAAS.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback c: callbacks) {
        if (c instanceof NameCallback) {
            ((NameCallback) c).setName(username);
        } else if (c instanceof PasswordCallback) {
            ((PasswordCallback) c).setPassword(password.toCharArray());
        }
        else if (c instanceof KeyChoiceCallback) {
            KeyChoiceCallback kcc = (KeyChoiceCallback)c;
            try {
                int idx = kcc.lookupKey(key);
                kcc.setSelectedIndex(idx);
            }
            catch (IllegalArgumentException e) {
                throw new MissingCredsException(kcc);
            }
        }
        else {
            throw new UnsupportedCallbackException(c);
        }
    }
}
 
Example 3
Project: springboot-shiro-cas-mybatis   File: MockLoginModule.java   Source Code and License 6 votes vote down vote up
@Override
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if ("test".equals(userName) && "test".equals(password)) {
        return true;
    }

    throw new LoginException();
}
 
Example 4
Project: springboot-shiro-cas-mybatis   File: MockLoginModule.java   Source Code and License 6 votes vote down vote up
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if ("test".equals(userName) && "test".equals(password)) {
        return true;
    }

    throw new LoginException();
}
 
Example 5
Project: OpenDiabetes   File: JaasAuthBean.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks)
        throws UnsupportedCallbackException {
    boolean didSetName = false;
    boolean didSetPassword = false;
    for (Callback cb : callbacks)
        if (cb instanceof NameCallback) {
            ((NameCallback) cb).setName(u);
            didSetName = true;
        } else if (cb instanceof PasswordCallback) {
            ((PasswordCallback) cb).setPassword(p);
            didSetPassword = true;
        } else {
            throw new UnsupportedCallbackException(cb,
                    "Unsupported Callback type: "
                    + cb.getClass().getName());
        }
    if (!didSetName)
        throw new IllegalStateException(
                "Supplied Callbacks does not include a NameCallback");
    if (!didSetPassword)
        throw new IllegalStateException("Supplied Callbacks "
                + "does not include a PasswordCallback");
}
 
Example 6
Project: cas-5.1.0   File: JaasAuthenticationHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
    Arrays.stream(callbacks).filter(callback -> {
        if (callback.getClass().equals(NameCallback.class)) {
            ((NameCallback) callback).setName(this.userName);
            return false;
        }
        if (callback.getClass().equals(PasswordCallback.class)) {
            ((PasswordCallback) callback).setPassword(this.password.toCharArray());
            return false;
        }
        return true;
    }).findFirst().ifPresent(callback -> {
        throw new RuntimeException(new UnsupportedCallbackException(callback, "Unrecognized Callback"));
    });
}
 
Example 7
Project: cas-5.1.0   File: MockLoginModule.java   Source Code and License 6 votes vote down vote up
@Override
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if ("test".equals(userName) && "test".equals(password)) {
        return true;
    }

    throw new LoginException();
}
 
Example 8
Project: cas4.0.x-server-wechat   File: MockLoginModule.java   Source Code and License 6 votes vote down vote up
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if (userName.equals("test") && password.equals("test")) {
        return true;
    }

    throw new LoginException();
}
 
Example 9
Project: message-broker   File: PlainSaslCallbackHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    if (callbacks != null) {
        for (Callback callback : callbacks) {
            if (callback instanceof NameCallback) {
                ((NameCallback) callback).setName(username);
            } else if (callback instanceof PasswordCallback) {
                ((PasswordCallback) callback).setPassword(password);
            } else {
                throw new UnsupportedCallbackException(callback);

            }
        }
        clearCredentials();
    }
}
 
Example 10
Project: oscm   File: UserCredentialsHandler.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieve or display the information requested in the provided Callbacks.
 * 
 * @param callbacks
 *            an array of <code>Callback</code> objects provided by an
 *            underlying security service which contains the information
 *            requested to be retrieved or displayed.
 * 
 * @throws IOException
 *             if an input or output error occurs.
 * 
 * @throws UnsupportedCallbackException
 *             if the implementation of this method does not support one or
 *             more of the Callbacks specified in the <code>callbacks</code>
 *             parameter.
 */
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(wsProxyInfo
                    .getUserCredentials().getUser());
        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword(wsProxyInfo
                    .getUserCredentials().getPassword().toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
Example 11
Project: oscm   File: WSCallbackHandler.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks)
        throws IOException, UnsupportedCallbackException {
    System.out.println("Callback Handler - handle called");
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callbacks[i];
            nameCallback.setName(name);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];
            passwordCallback.setPassword(password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callbacks[i],
                    "The submitted Callback is unsupported");
        }
    }
}
 
Example 12
Project: mongosql-auth-java   File: Plain.java   Source Code and License 6 votes vote down vote up
static SaslClient createSaslClient(final String user, final String password) throws SaslException {
    return Sasl.createSaslClient(new String[]{"PLAIN"}, user, null, null, null,
            new CallbackHandler() {
                @Override
                public void handle(final Callback[] callbacks)
                        throws IOException, UnsupportedCallbackException {
                    for (final Callback callback : callbacks) {
                        if (callback instanceof PasswordCallback) {
                            ((PasswordCallback) callback).setPassword(password.toCharArray());
                        } else if (callback instanceof NameCallback) {
                            ((NameCallback) callback).setName(user);
                        }
                    }
                }
            });
}
 
Example 13
Project: Transwarp-Sample-Code   File: KerberosAuthenticator2.java   Source Code and License 6 votes vote down vote up
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 14
Project: dev-courses   File: JaasAuthBean.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks)
        throws UnsupportedCallbackException {
    boolean didSetName = false;
    boolean didSetPassword = false;
    for (Callback cb : callbacks)
        if (cb instanceof NameCallback) {
            ((NameCallback) cb).setName(u);
            didSetName = true;
        } else if (cb instanceof PasswordCallback) {
            ((PasswordCallback) cb).setPassword(p);
            didSetPassword = true;
        } else {
            throw new UnsupportedCallbackException(cb,
                    "Unsupported Callback type: "
                    + cb.getClass().getName());
        }
    if (!didSetName)
        throw new IllegalStateException(
                "Supplied Callbacks does not include a NameCallback");
    if (!didSetPassword)
        throw new IllegalStateException("Supplied Callbacks "
                + "does not include a PasswordCallback");
}
 
Example 15
Project: jerrydog   File: JAASCallbackHandler.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieve the information requested in the provided Callbacks.  This
 * implementation only recognizes <code>NameCallback</code> and
 * <code>PasswordCallback</code> instances.
 *
 * @param callbacks The set of callbacks to be processed
 *
 * @exception IOException if an input/output error occurs
 * @exception UnsupportedCallbackException if the login method requests
 *  an unsupported callback type
 */
public void handle(Callback callbacks[])
    throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {

        if (callbacks[i] instanceof NameCallback) {
            if (realm.getDebug() >= 3)
                realm.log("Returning username " + username);
            ((NameCallback) callbacks[i]).setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            if (realm.getDebug() >= 3)
                realm.log("Returning password " + password);
            ((PasswordCallback) callbacks[i]).setPassword
                (password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }


    }

}
 
Example 16
Project: libcwfincore   File: GdaxExchangeConnection.java   Source Code and License 6 votes vote down vote up
@Override
public ExchangeSession openSession(ExchangeLogin login) {
    ApiKeyCallback apiKey = new ApiKeyCallback();
    ApiSecretCallback apiSecret = new ApiSecretCallback();
    PasswordCallback password = new PasswordCallback("GDAX passphrase", false);

    Callback[] callbacks = new Callback[]{
            apiKey,
            apiSecret,
            password
    };
    CallbackHandler callbackHandler = login.getCallbackHandler();
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new RuntimeException(e);
    }

    String apiKeyTxt = apiKey.getApiKey();
    char[] passphrase = password.getPassword();
    SecretKeySpec keySpec = new SecretKeySpec(apiSecret.getSecretData(), "HmacSHA256");
    return new GdaxExchangeSession(this, apiKeyTxt, keySpec, passphrase);
}
 
Example 17
Project: libcwfincore   File: GdaxExchangeCredentials.java   Source Code and License 6 votes vote down vote up
@Override
public CallbackHandler getCallbackHandler() {
    return callbacks -> {
        for (Callback cb : callbacks) {
            if (cb instanceof ApiKeyCallback) {
                ((ApiKeyCallback) cb).setApiKey(apiKey);
            } else if (cb instanceof ApiSecretCallback) {
                ((ApiSecretCallback) cb).setSecretData(apiSecret);
            } else if (cb instanceof PasswordCallback) {
                ((PasswordCallback) cb).setPassword(passphrase);
            } else {
                throw new UnsupportedCallbackException(cb);
            }
        }
    };
}
 
Example 18
Project: OperatieBRP   File: JMXCallbackHandler.java   Source Code and License 6 votes vote down vote up
/**
 * Handles the callbacks; only supports {@link NameCallback} and {@link PasswordCallback}.
 * @throws UnsupportedCallbackException if an unsupported callback is encountered
 */
@Override
public void handle(final Callback[] callbacks)
        throws UnsupportedCallbackException {

    for (final Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(username);

        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback)
                    .setPassword(password.toCharArray());

        } else {
            throw new UnsupportedCallbackException
                    (callback, "Unrecognized Callback");
        }
    }
}
 
Example 19
Project: kafka-0.11.0.0-src-with-comment   File: TestDigestLoginModule.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callback;
            nameCallback.setName(nameCallback.getDefaultName());
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callback;
            passwordCallback.setPassword(TestJaasConfig.PASSWORD.toCharArray());
        } else if (callback instanceof RealmCallback) {
            RealmCallback realmCallback = (RealmCallback) callback;
            realmCallback.setText(realmCallback.getDefaultText());
        } else if (callback instanceof AuthorizeCallback) {
            AuthorizeCallback authCallback = (AuthorizeCallback) callback;
            if (TestJaasConfig.USERNAME.equals(authCallback.getAuthenticationID())) {
                authCallback.setAuthorized(true);
                authCallback.setAuthorizedID(authCallback.getAuthenticationID());
            }
        }
    }
}
 
Example 20
Project: ditb   File: TestHBaseSaslRpcClient.java   Source Code and License 6 votes vote down vote up
@Test
public void testSaslClientCallbackHandler() throws UnsupportedCallbackException {
  final Token<? extends TokenIdentifier> token = createTokenMock();
  when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes());
  when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes());

  final NameCallback nameCallback = mock(NameCallback.class);
  final PasswordCallback passwordCallback = mock(PasswordCallback.class);
  final RealmCallback realmCallback = mock(RealmCallback.class);
  final RealmChoiceCallback realmChoiceCallback = mock(RealmChoiceCallback.class);

  Callback[] callbackArray = {nameCallback, passwordCallback,
      realmCallback, realmChoiceCallback};
  final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
  saslClCallbackHandler.handle(callbackArray);
  verify(nameCallback).setName(anyString());
  verify(realmCallback).setText(anyString());
  verify(passwordCallback).setPassword(any(char[].class));
}
 
Example 21
Project: mi-firma-android   File: VerifyApduCommand.java   Source Code and License 6 votes vote down vote up
/** Construye una APDU ISO 7816-4 de verificaci&oacute;n de PIN (CHV, <i>Card Holder Verification</i>).
   * @param cla Clase (CLA) de la APDU.
   * @param pinPc Pin de la tarjeta inteligente. */
  public VerifyApduCommand(final byte cla, final PasswordCallback pinPc) {
      super(
  		cla,																 // CLA
  		VerifyApduCommand.INS_VERIFY, 										 // INS
  		(byte)0x00, 														 // P1
  		(byte)0x81,															 // P2
  		new byte[] {                                                         // Data
  			(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, //  Siempre de 0x10h
  			(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,  //  de tamano
  			(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
  			(byte) 0x00
	},
  		null																 // Le
);
      if (pinPc == null) {
      	throw new IllegalArgumentException(
  			"No se puede verificar el titular con un PasswordCallback nulo" //$NON-NLS-1$
      	);
      }
      this.pwc = pinPc;
  }
 
Example 22
Project: jdk8u-jdk   File: DynamicConfigurationTest.java   Source Code and License 6 votes vote down vote up
@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 23
Project: mi-firma-android   File: VerifyApduCommand.java   Source Code and License 6 votes vote down vote up
private static byte[] charArrayToByteArray(final PasswordCallback pinPc) {
 	if (pinPc == null) {
 		throw new IllegalArgumentException(
	"El PasswordCallback del PIN no puede ser nulo" //$NON-NLS-1$
);
 	}
 	final char[] in = pinPc.getPassword();
 	if (in == null) {
 		return new byte[0];
 	}
 	final byte[] ret = new byte[in.length];
 	for (int i=0; i<in.length; i++) {
 		ret[i] = (byte) in[i];
 	}
 	return ret;
 }
 
Example 24
Project: openjdk-jdk10   File: NegotiateCallbackHandler.java   Source Code and License 6 votes vote down vote up
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 25
Project: openjdk-jdk10   File: TestCallbackHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    System.out.println("TestCallbackHandler will get resolved through"
            + " auth.login.defaultCallbackHandler property.");
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(USER_NAME);
        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword(
                    PASSWORD.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example 26
Project: openjdk-jdk10   File: DynamicConfigurationTest.java   Source Code and License 6 votes vote down vote up
@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 27
Project: mi-firma-android   File: StCard.java   Source Code and License 6 votes vote down vote up
@Override
public void verifyPin(final PasswordCallback pinPc) throws ApduConnectionException,
                                                           PinException {
	if (pinPc == null) {
		throw new BadPinException("No se ha establecido un PasswordCallback"); //$NON-NLS-1$
	}
	final CommandApdu chv = new VerifyApduCommand(CLA, pinPc);
	final ResponseApdu verifyResponse = sendArbitraryApdu(chv);
       if (!verifyResponse.isOk()) {
           if (verifyResponse.getStatusWord().getMsb() == ERROR_PIN_SW1) {
           	throw new BadPinException(verifyResponse.getStatusWord().getLsb() - (byte) 0xC0);
           }
           throw new ApduConnectionException(
       		"Error en el envio de la verificacion de PIN con respuesta: " + verifyResponse.getStatusWord() //$NON-NLS-1$
   		);
       }
}
 
Example 28
Project: fcrepo3-security-jaas   File: XmlUsersFileModule.java   Source Code and License 5 votes vote down vote up
@Override
public boolean login() throws LoginException {
    if (debug) {
        logger.debug(this.getClass().getName() + " login called.");
    }

    if (Constants.FEDORA_HOME == null || "".equals(Constants.FEDORA_HOME.trim())) {
        logger.error("FEDORA_HOME constant is not set");
        return false;
    }

    final NameCallback nc = new NameCallback("username");
    final PasswordCallback pc = new PasswordCallback("password", false);
    final Callback[] callbacks = new Callback[] {
            nc, pc
    };

    try {
        handler.handle(callbacks);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new LoginException("IOException occured: " + ioe.getMessage());
    } catch (UnsupportedCallbackException ucbe) {
        ucbe.printStackTrace();
        throw new LoginException("UnsupportedCallbackException encountered: "
                + ucbe.getMessage());
    }

    // Grab the username and password from the callbacks.
    final String username = nc.getName();
    final String password = new String(pc.getPassword());

    successLogin = authenticate(username, password);

    return successLogin;
}
 
Example 29
Project: springboot-shiro-cas-mybatis   File: JaasAuthenticationHandler.java   Source Code and License 5 votes vote down vote up
@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 30
Project: cas4.0.x-server-wechat   File: JaasAuthenticationHandler.java   Source Code and License 5 votes vote down vote up
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 31
Project: message-broker   File: TestLoginModule.java   Source Code and License 5 votes vote down vote up
@Override
public boolean login() throws LoginException {
    NameCallback userNameCallback = new NameCallback("userName");
    PasswordCallback passwordCallback = new PasswordCallback("password", false);
    Callback[] callbacks = { userNameCallback, passwordCallback };
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new BrokerAuthenticationException("Error while handling callback ", e);
    }
    String userName = userNameCallback.getName();
    char[] password = passwordCallback.getPassword();
    return userName.equals("user") && Arrays.equals(password, new char[] { 'p', 'a', 's', 's' });
}
 
Example 32
Project: fuck_zookeeper   File: SaslServerCallbackHandler.java   Source Code and License 5 votes vote down vote up
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            handleNameCallback((NameCallback) callback);
        } else if (callback instanceof PasswordCallback) {
            handlePasswordCallback((PasswordCallback) callback);
        } else if (callback instanceof RealmCallback) {
            handleRealmCallback((RealmCallback) callback);
        } else if (callback instanceof AuthorizeCallback) {
            handleAuthorizeCallback((AuthorizeCallback) callback);
        }
    }
}
 
Example 33
Project: fuck_zookeeper   File: SaslServerCallbackHandler.java   Source Code and License 5 votes vote down vote up
private void handlePasswordCallback(PasswordCallback pc) {
    if ("super".equals(this.userName) && System.getProperty(SYSPROP_SUPER_PASSWORD) != null) {
        // superuser: use Java system property for password, if available.
        pc.setPassword(System.getProperty(SYSPROP_SUPER_PASSWORD).toCharArray());
    } else if (credentials.containsKey(userName) ) {
        pc.setPassword(credentials.get(userName).toCharArray());
    } else {
        LOG.warn("No password found for user: " + userName);
    }
}
 
Example 34
Project: ats-framework   File: JaasKerberosConfiguration.java   Source Code and License 5 votes vote down vote up
public void handle(
                    Callback[] callbacks ) throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback nc = (NameCallback) callbacks[i];
            nc.setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callbacks[i];
            pc.setPassword(password);
        }
    }
}
 
Example 35
Project: taskana   File: SampleLoginModule.java   Source Code and License 5 votes vote down vote up
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState,
		Map<String, ?> options) {

	try {
		NameCallback nameCallback = new NameCallback("prompt");
		PasswordCallback passwordCallback = new PasswordCallback("prompt", false);

		callbackHandler.handle(new Callback[] { nameCallback, passwordCallback });
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 36
Project: ARCLib   File: PasswordTicketValidator.java   Source Code and License 5 votes vote down vote up
private static CallbackHandler getUsernamePasswordHandler(final String username, final String password) {
    return callbacks -> {
        for (Callback callback : callbacks) {
            if (callback instanceof NameCallback) {
                final NameCallback nameCallback = (NameCallback) callback;
                nameCallback.setName(username);
            } else if (callback instanceof PasswordCallback) {
                final PasswordCallback passCallback = (PasswordCallback) callback;
                passCallback.setPassword(password.toCharArray());
            } else {
                System.err.println("Unsupported Callback: " + callback.getClass().getName());
            }
        }
    };
}
 
Example 37
Project: cas-server-4.2.1   File: JaasAuthenticationHandler.java   Source Code and License 5 votes vote down vote up
@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 38
Project: mi-firma-android   File: CeresVerifyApduCommand.java   Source Code and License 5 votes vote down vote up
/** Construye una APDU ISO 7816-4 de verificaci&oacute;n de PIN (CHV, <i>Card Holder Verification</i>).
   * @param cla Clase (CLA) de la APDU.
   * @param pinPc Pin de la tarjeta inteligente. */
  public CeresVerifyApduCommand(final byte cla, final PasswordCallback pinPc) {
      super(
  		cla,							// CLA
  		INS_VERIFY, 					// INS
  		(byte)0x00, 					// P1
  		(byte)0x00,						// P2
  		charArrayToByteArray(pinPc),	// Data
  		null							// Le
);
  }
 
Example 39
Project: lams   File: UniversalLoginModule.java   Source Code and License 5 votes vote down vote up
/**
    * 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 40
Project: https-github.com-apache-zookeeper   File: SaslServerCallbackHandler.java   Source Code and License 5 votes vote down vote up
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            handleNameCallback((NameCallback) callback);
        } else if (callback instanceof PasswordCallback) {
            handlePasswordCallback((PasswordCallback) callback);
        } else if (callback instanceof RealmCallback) {
            handleRealmCallback((RealmCallback) callback);
        } else if (callback instanceof AuthorizeCallback) {
            handleAuthorizeCallback((AuthorizeCallback) callback);
        }
    }
}