📄 serverfactory.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * ServerFactory.java * * Created on 1 April 2003, 02:32 *//** * <p>A factory object that is responsible for creating Server objects * with predefined bindings to a particular tomcat instance for * remote XML data exchange.</p> * */package crms.util;import crms.module.PermissionModule;import crms.applet.PanelManager;public class ServerFactory { private static ServerFactory _instance = null; private String hostName = null; private int port = -1; private String path = null; private String user = null; private String key = null; /** Creates a new instance of ServerFactory */ private ServerFactory(String hostName, int port, String path) { this.hostName = hostName; this.port = port; this.path = path; } public static ServerFactory getInstance(String hostName, int port, String path) { if (_instance == null) { _instance = new ServerFactory(hostName,port,path); } return _instance; } public static ServerFactory getInstance() { if (_instance == null) { throw new RuntimeException("ServerFactory has not been initialised!"); } return _instance; } public Server getServer() { Server server = new Server(hostName, port, path); server.setUser(getUser()); return server; } /** * <p>Sets the current user for all commands sent back and forth to * the server. This setting is passed on to all instances of 'Server' * that are created from this factory, and subsequently onto all * 'ServerCommand's that are created from that 'Server'.</p> * @param userName User name to set as current user. */ private void setUser(String userName) { this.user = userName; } public String getUser() { return user; } public void setKey(String key) { this.key = key; } public String getKey() { return key; } /** * <p>Authenticates a user to the "middle-tier". This operation abstracts * away from the actual method of authentication, but ensures that * authentication can occur.<p> * <p>In the Squirrelmail embedded CRMS, the username and key are * obtained from the squirrelmail runtime and passed through * to the applet.</p> * <p>Note: The key is base64 encoded to avoid plain-text passwords * travelling around the network. <b>However</b>, such a string * can be trivially decoded.</p> * @param userName Username passed into applet as applet parameter. * @param key A Base64 encoded string representing the credentials * the user is presenting for authentication. */ public void authenticate(String userName, String key) { System.out.println("ServerFactory.authenticate: user = " + userName); setUser(userName); Server authServer = getServer(); ServerCommand command = new ServerCommand(PermissionModule.PERM_AUTHENTICATE); command.setParameter(PermissionModule.PARAM_KEY, key); ServerResponse authResponse = authServer.sendCommand(command); if (authResponse.getPart("acknowledge").equals("okay")) { PanelManager.getInstance().setAuthenticatedUser(userName, key); setKey(key); System.out.println("User authenticated..."); } else { throw new RuntimeException("User authentication failed."); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -