/*
* Danet GmbH
* Beratung und Software-Entwicklung
* Gesch�ftstelle AN
*
* $Id: STProjectLoginContext.java 1699 2006-10-10 15:36:53Z drmlipp $
*
* $Log$
* Revision 1.2 2006/06/22 22:04:40 mlipp
* Systemtests running again.
*
* Revision 1.1.1.2 2003/12/19 13:01:46 drmlipp
* Updated to 1.1rc1
*
* Revision 1.3 2003/11/25 08:13:36 lipp
* WLS support.
*
* Revision 1.2 2003/05/22 11:36:22 lipp
* Cleaned up usage of security domains.
*
* Revision 1.1 2003/04/26 16:46:55 lipp
* Made unittests and systemtests coexist in eclipse.
*
* Revision 1.1 2003/04/16 19:58:49 lipp
* Adapted to jdk 1.4
*
* Revision 1.1 2002/11/01 09:02:01 weidauer
* initial version
*
* Revision 1.1 2001/12/10 15:27:51 lipp
* Adapting to secure beans.
*
*/
package common;
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.TextOutputCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
/**
* Simple login context for unit tests.
*/
public class STProjectLoginContext extends LoginContext {
private static class CBH implements CallbackHandler {
public void handle (Callback[] callbacks)
throws UnsupportedCallbackException, IOException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof TextOutputCallback) {
// display the message according to the specified type
TextOutputCallback toc = (TextOutputCallback)callbacks[i];
switch (toc.getMessageType()) {
case TextOutputCallback.INFORMATION:
System.err.println(toc.getMessage());
break;
case TextOutputCallback.ERROR:
System.err.println("ERROR: " + toc.getMessage());
break;
case TextOutputCallback.WARNING:
System.err.println("WARNING: " + toc.getMessage());
break;
default:
throw new IOException("Unsupported message type: "
+ toc.getMessageType());
}
} else if (callbacks[i] instanceof NameCallback) {
// prompt the user for a username
NameCallback nc = (NameCallback)callbacks[i];
nc.setName("ML");
} else if (callbacks[i] instanceof PasswordCallback) {
// prompt the user for sensitive information
PasswordCallback pc = (PasswordCallback)callbacks[i];
pc.setPassword("ML".toCharArray());
} else if (callbacks[i].getClass().getName().equals
("weblogic.security.auth.callback.URLCallback")) {
} else {
throw new UnsupportedCallbackException
(callbacks[i], "Unrecognized Callback");
}
}
}
}
public STProjectLoginContext () throws LoginException {
super ("danetworkflow", new CBH());
}
}