📄 authserverimpl.java
字号:
/*------------------------------------------------------------------------------Name: AuthServerImpl.javaProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileComment: Implementing the CORBA xmlBlaster-server interfaceVersion: $Id: AuthServerImpl.java 14915 2006-03-12 20:48:39Z ruff $Author: xmlBlaster@marcelruff.info------------------------------------------------------------------------------*/package org.xmlBlaster.protocol.corba;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.util.Global;import org.xmlBlaster.protocol.I_Authenticate;import org.xmlBlaster.protocol.I_XmlBlaster;import org.xmlBlaster.protocol.corba.authenticateIdl.*;import org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException;import org.xmlBlaster.protocol.corba.serverIdl.ServerHelper;import org.xmlBlaster.engine.qos.AddressServer;import org.xmlBlaster.engine.qos.ConnectQosServer;import org.xmlBlaster.engine.qos.ConnectReturnQosServer;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.engine.qos.DisconnectQosServer;import org.xmlBlaster.util.protocol.corba.OrbInstanceFactory;import org.xmlBlaster.util.qos.address.ServerRef;import org.xmlBlaster.protocol.corba.serverIdl.ServerPOATie;import org.omg.PortableServer.*;/* Obtain remote IP address (from jacorb mailing list):I'm not sure, but I think, the only standard way to achieve this, is to usePortableInterceptors on the client side too, adding some information toPortableInterceptor::ClientRequestInfo_ptr, or not?Then, you don't need the cast. public void receive_request(ServerRequestInfo requestInfo) throws ForwardRequest { java.net.InetAddress remoteAddress = getRemoteAddress(requestInfo); ... etc ... public java.net.InetAddress getRemoteAddress(ServerRequestInfo requestInfo) { try { org.jacorb.orb.portableInterceptor.ServerRequestInfoImpl serverRequestInfo = (org.jacorb.orb.portableInterceptor.ServerRequestInfoImpl)requestInfo; org.jacorb.orb.dsi.ServerRequest serverRequest = serverRequestInfo.request; org.jacorb.orb.giop.GIOPConnection giopConnection = serverRequest.getConnection(); org.jacorb.orb.iiop.ServerIIOPConnection serverIIOPTransport = (org.jacorb.orb.iiop.ServerIIOPConnection)giopConnection.getTransport(); java.net.Socket socket = serverIIOPTransport.getSocket(); java.net.InetSocketAddress remoteSockAddr = (java.net.InetSocketAddress)socket.getRemoteSocketAddress(); java.net.InetAddress remoteInetAddr = remoteSockAddr.getAddress(); return remoteInetAddr; } catch(ClassCastException e) { e.printStackTrace(); } return null;}*//** * Implements the xmlBlaster AuthServer CORBA Interface. * <br> * All real work is directly delegated to org.xmlBlaster.authentication.Authenticate *///public class AuthServerImpl extends ServerPOA { // inheritance approachpublic class AuthServerImpl implements AuthServerOperations { // tie approach private final static String ME = "AuthServerImpl"; private final Global glob; private static Logger log = Logger.getLogger(AuthServerImpl.class.getName()); private final org.omg.CORBA.ORB orb; private final I_Authenticate authenticate; /** This specialized POA controlles the xmlBlaster server */ private final String xmlBlasterPOA_name = "xmlBlaster-POA"; /** We use our own, customized POA */ private POA xmlBlasterPOA; /** The root POA */ private org.omg.PortableServer.POA rootPOA; // USING TIE: private ServerPOATie xmlBlasterServant; // extends org.omg.PortableServer.Servant // NOT TIE /** extends org.omg.PortableServer.Servant */ //private ServerImpl xmlBlasterServant; private AddressServer addressServer; /** * One instance implements a server. * * Authenticate creates a singlorg.xmlBlaster.SimpleRunLevelTeste instance of the xmlBlaster.Server. * Clients need first to do a login, from where they get * an IOR which serves them, one thread for each request.<p> * * Every client has its own IOR, but in reality this IOR is mapped * to a single servant.<p> * This allows:<br> * - Identification of the client thru its unique IOR<br> * - Only a few threads are enough to serve many clients * * @param The orb * @param authenticate The authentication service * @param blaster The interface to access xmlBlaster */ public AuthServerImpl(Global glob, org.omg.CORBA.ORB orb, AddressServer addressServer, I_Authenticate authenticate, I_XmlBlaster blaster) { this.glob = glob; this.orb = orb; this.authenticate = authenticate; this.addressServer = addressServer; if (log.isLoggable(Level.FINER)) log.finer("Entering constructor with ORB argument"); try { rootPOA = org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA")); POAManager poaMgr = rootPOA.the_POAManager(); // Create a customized POA: // - Allows a single servant for multiple clients // - Allows one thread per request (per invocation of a server method) // - Allows to recognize the calling client (thru one IOR per client) // so the clients do not need to send a sessionId as a method parameter // - Allows thousands of clients simultaneously, as there is only one servant org.omg.CORBA.Policy [] policies = new org.omg.CORBA.Policy[2]; policies[0] = rootPOA.create_request_processing_policy(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT); policies[1] = rootPOA.create_id_uniqueness_policy(IdUniquenessPolicyValue.MULTIPLE_ID); // policies[] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID); // policies[] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); xmlBlasterPOA = rootPOA.create_POA(xmlBlasterPOA_name, poaMgr, policies); for (int i=0; i<policies.length; i++) policies[i].destroy(); // This single servant handles all requests (with the policies from above) // USING TIE: xmlBlasterServant = new ServerPOATie(new ServerImpl(glob, orb, this.addressServer, blaster)); // NOT TIE: //xmlBlasterServant = new ServerImpl(glob, orb, blaster); xmlBlasterPOA.set_servant(xmlBlasterServant); // set as default servant poaMgr.activate(); // orb.run(); // log.info(ME, "Default Active Object Map ID=" + default_oid); if (log.isLoggable(Level.FINE)) log.fine("Default xmlBlasterServant activated"); } catch ( Exception e ) { e.printStackTrace(); log.severe(e.toString()); } if (log.isLoggable(Level.FINER)) log.fine("Leaving constructor"); } public org.omg.CORBA.ORB getOrb() { return orb; } public I_Authenticate getAuthenticationService() { return authenticate; } /** * Authentication of a client. * @return The Server reference */ public org.xmlBlaster.protocol.corba.serverIdl.Server login(String loginName, String passwd, String qos_literal) throws XmlBlasterException { if (log.isLoggable(Level.FINER)) log.finer("Entering login(loginName=" + loginName/* + ", qos=" + qos_literal */ + ")"); if (loginName==null || passwd==null || qos_literal==null) { log.severe("login failed: please use no null arguments for login()"); throw OrbInstanceFactory.convert(new org.xmlBlaster.util.XmlBlasterException(glob, ErrorCode.USER_SECURITY_AUTHENTICATION_ILLEGALARGUMENT, ME, "Login failed: please use no null arguments for login()"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -