📄 worksessionserverimpl.java
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * . Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * . Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * . Neither the name of the "OpenWFE" nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: WorkSessionServerImpl.java,v 1.8 2005/05/17 16:40:16 jmettraux Exp $ *///// WorkSessionServerImpl.java//// jmettraux@openwfe.org//// generated with // jtmpl 1.1.00 16.08.2003 John Mettraux (jmettraux@openwfe.org)//package openwfe.org.rmi.session;import javax.security.auth.login.LoginContext;import javax.security.auth.login.LoginException;import openwfe.org.ApplicationContext;import openwfe.org.auth.OwfeCallbackHandler;/** * Half an implementation of a WorkSessionServer... * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: WorkSessionServerImpl.java,v 1.8 2005/05/17 16:40:16 jmettraux Exp $ </font> * * @author jmettraux@openwfe.org */public class WorkSessionServerImpl extends java.rmi.server.UnicastRemoteObject implements WorkSessionServer { private final static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(WorkSessionServerImpl.class.getName()); // // CONSTANTS & co public final static String LOGIN_CONTEXT = "loginContext"; public final static String REMOTE_SESSION_IMPL_CLASS = "remoteSessionImplClass"; public final static String CALLBACK_HANDLER_CLASS = "callbackHandlerClass"; // // FIELDS protected String serviceName = null; protected ApplicationContext context = null; protected java.util.Map params = null; protected String loginContextName = null; protected Class sessionImplClass = null; protected Class callbackHandlerClass = null; // // CONSTRUCTORS public WorkSessionServerImpl () throws java.rmi.RemoteException { super(); } public void init (String serviceName, ApplicationContext context, java.util.Map serviceParams) throws java.rmi.RemoteException { this.serviceName = serviceName; this.context = context; this.params = serviceParams; // // fetch login context name this.loginContextName = (String)serviceParams.get(LOGIN_CONTEXT); if (this.loginContextName == null) { throw new java.rmi.RemoteException ("Parameter '"+LOGIN_CONTEXT+ "' is mandatory for WorkSessionServerImpl"); } // // fetch remote session impl class String remoteSessionImplClassName = (String)serviceParams .get(REMOTE_SESSION_IMPL_CLASS); if (remoteSessionImplClassName == null) { throw new java.rmi.RemoteException ("Parameter '"+REMOTE_SESSION_IMPL_CLASS+ "' is mandatory for WorkSessionServerImpl"); } try { this.sessionImplClass = Class.forName(remoteSessionImplClassName); } catch (Exception e) { throw new java.rmi.RemoteException ("Failed to load sessionImplClass '"+ remoteSessionImplClassName+"'", e); } log.info ("RemoteSessionImplClass set to '"+remoteSessionImplClassName+"'"); // // fetch callback handler class String callbackHandlerClassName = (String)serviceParams .get(CALLBACK_HANDLER_CLASS); if (callbackHandlerClassName == null) { callbackHandlerClassName = openwfe.org.auth.StupidCallbackHandler.class.getName(); } try { this.callbackHandlerClass = Class.forName(callbackHandlerClassName); } catch (Exception e) { throw new java.rmi.RemoteException ("Failed to load callbackHandlerClass '"+ callbackHandlerClassName+"'", e); } log.info ("callbackHandlerClass set to '"+callbackHandlerClassName+"'"); } // // METHODS from WorkSessionServerImpl public RemoteSession login (String username, String password) throws java.rmi.RemoteException { OwfeCallbackHandler callbackHandler = null; try { callbackHandler = (OwfeCallbackHandler)this.callbackHandlerClass.newInstance(); callbackHandler.init(new String[] { username, password }); } catch (Exception e) { log.debug("Failed to set up callback handler", e); throw new java.rmi.RemoteException ("Failed to set up callback handler", e); } return login(callbackHandler); } public RemoteSession login (java.security.Principal principal) throws java.rmi.RemoteException { OwfeCallbackHandler callbackHandler = null; try { callbackHandler = (OwfeCallbackHandler)this.callbackHandlerClass.newInstance(); callbackHandler.init(principal); } catch (Exception e) { log.debug("Failed to set up callback handler", e); throw new java.rmi.RemoteException ("Failed to set up callback handler", e); } return login(callbackHandler); } private RemoteSession login (OwfeCallbackHandler callbackHandler) throws java.rmi.RemoteException { // // login LoginContext lc = null; try { lc = new LoginContext (this.loginContextName, callbackHandler); lc.login(); } catch (LoginException le) { log.debug("Login failed", le); throw new java.rmi.RemoteException("Login failed", le); } // // set up worksession RemoteSession session = null; try { session = (RemoteSession)this.sessionImplClass.newInstance(); } catch (Exception e) { throw new java.rmi.RemoteException ("Failed to instantiate session of class '"+ this.sessionImplClass.getName()+"'", e); } session.init(this.context, this.params, lc.getSubject()); log.debug("Spawned a session for a subject"); return session; } // // METHODS}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -