Save This Page
Home » jexcelapi_2_6_8 » common » [javadoc | source]
    1   /*
    2    * Danet GmbH
    3    * Beratung und Software-Entwicklung
    4    * Gesch?ftstelle AN
    5    *
    6    * $Id: UTLoginContext.java,v 1.4 2003/08/25 15:18:24 lipp Exp $
    7    *
    8    * $Log: UTLoginContext.java,v $
    9    * Revision 1.4  2003/08/25 15:18:24  lipp
   10    * Fixed changes checked in by mistake.
   11    *
   12    * Revision 1.3  2003/08/25 14:23:08  lipp
   13    * Better support for different application servers in the build process.
   14    *
   15    * Revision 1.2  2003/05/22 11:36:22  lipp
   16    * Cleaned up usage of security domains.
   17    *
   18    * Revision 1.1  2003/04/26 16:46:55  lipp
   19    * Made unittests and systemtests coexist in eclipse.
   20    *
   21    * Revision 1.2  2003/04/24 20:51:21  lipp
   22    * Fixed some warnings.
   23    *
   24    * Revision 1.1  2003/04/16 19:25:04  lipp
   25    * Adapted to jdk 1.4
   26    *
   27    * Revision 1.2  2002/11/15 15:41:53  montag
   28    * New session ejb Util.
   29    *
   30    * Revision 1.1  2001/12/10 15:27:51  lipp
   31    * Adapting to secure beans.
   32    *
   33    */
   34   
   35   package common;
   36   import java.io.IOException;
   37   
   38   import javax.security.auth.callback.Callback;
   39   import javax.security.auth.callback.UnsupportedCallbackException;
   40   import javax.security.auth.callback.CallbackHandler;
   41   import javax.security.auth.callback.TextOutputCallback;
   42   import javax.security.auth.callback.NameCallback;
   43   import javax.security.auth.callback.PasswordCallback;
   44   import javax.security.auth.login.LoginContext;
   45   import javax.security.auth.login.LoginException;
   46   
   47   /**
   48    * Simple login context for unit tests.
   49    */
   50   public class UTLoginContext extends LoginContext {
   51   
   52       public final static String USERNAME = "junit";
   53   
   54       private static class CBH implements CallbackHandler {
   55   	public void handle (Callback[] callbacks)
   56   	    throws UnsupportedCallbackException, IOException {
   57   	    for (int i = 0; i < callbacks.length; i++) {
   58   		if (callbacks[i] instanceof TextOutputCallback) {
   59   		    // display the message according to the specified type
   60   		    TextOutputCallback toc = (TextOutputCallback)callbacks[i];
   61   		    switch (toc.getMessageType()) {
   62   		    case TextOutputCallback.INFORMATION:
   63   			System.err.println(toc.getMessage());
   64   			break;
   65   		    case TextOutputCallback.ERROR:
   66   			System.err.println("ERROR: " + toc.getMessage());
   67   			break;
   68   		    case TextOutputCallback.WARNING:
   69   			System.err.println("WARNING: " + toc.getMessage());
   70   			break;
   71   		    default:
   72   			throw new IOException("Unsupported message type: " +
   73   					      toc.getMessageType());
   74   		    }
   75   		} else if (callbacks[i] instanceof NameCallback) {
   76   		    // prompt the user for a username
   77   		    NameCallback nc = (NameCallback)callbacks[i]; 
   78   		    nc.setName(USERNAME);
   79   		} else if (callbacks[i] instanceof PasswordCallback) {
   80   		    // prompt the user for sensitive information
   81   		    PasswordCallback pc = (PasswordCallback)callbacks[i]; 
   82   		    pc.setPassword(USERNAME.toCharArray());
   83   		} else if (callbacks[i].getClass().getName().equals 
   84   			   ("weblogic.security.auth.callback.URLCallback")) {
   85   		} else {
   86   		    throw new UnsupportedCallbackException
   87   			(callbacks[i], "Unrecognized Callback \""
   88   			 + callbacks[i].getClass().getName() + "\"");
   89   		}
   90   	    }
   91   	}
   92       }
   93   
   94       public UTLoginContext () throws LoginException {
   95   	super ("danetworkflow", new CBH());
   96       }
   97   
   98   }

Save This Page
Home » jexcelapi_2_6_8 » common » [javadoc | source]