All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.schooner.MemCached.PlainCallbackHandler Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
package com.schooner.MemCached;

import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;

public class PlainCallbackHandler implements CallbackHandler {
	private String username;
	private String password;

	public PlainCallbackHandler(String username, String password) {
		super();
		this.username = username;
		this.password = password;
	}

	public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
		for (Callback callback : callbacks) {
			if (callback instanceof NameCallback) {
				((NameCallback) callback).setName(this.username);
			} else if (callback instanceof PasswordCallback) {
				((PasswordCallback) callback).setPassword(password.toCharArray());
			} else
				throw new UnsupportedCallbackException(callback);
		}

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy