001: /**
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * ScurityLoginImpl
022: * LPS
023: * Oct 24, 2007
024: */package com.bostechcorp.cbesb.console.server;
025:
026: import javax.servlet.http.HttpSession;
027:
028: import com.bostechcorp.cbesb.common.i18n.CoreMessageConstants;
029: import com.bostechcorp.cbesb.common.i18n.Messages;
030: import com.bostechcorp.cbesb.common.util.DerbyControl;
031: import com.bostechcorp.cbesb.common.util.runtimedb.ConsoleUserDB;
032: import com.bostechcorp.cbesb.common.util.runtimedb.vo.ConsoleUserVO;
033: import com.bostechcorp.cbesb.console.common.ConsoleUserSettingInfo;
034: import com.bostechcorp.cbesb.console.common.Constants;
035: import com.bostechcorp.cbesb.console.common.SecurityLoginInfo;
036: import com.bostechcorp.cbesb.console.common.ServerSideException;
037: import com.bostechcorp.cbesb.console.help.FileHelper;
038: import com.bostechcorp.cbesb.console.jmxclient.JmxClient;
039: import com.bostechcorp.cbesb.console.rpc.SecurityLogin;
040:
041: /**
042: * @author LPS
043: *
044: */
045: public class SecurityLoginImplStartOnStartup01 extends
046: JmxServiceServlet implements SecurityLogin {
047: private static final long serialVersionUID = -407626456409562224L;
048:
049: public SecurityLoginInfo login(String port, String user,
050: String Password) {
051:
052: SecurityLoginInfo userInfo = new SecurityLoginInfo();
053: ConsoleUserVO dbUser = null;
054:
055: try {
056: dbUser = getConsoleUser(user);
057:
058: } catch (Exception e) {
059: userInfo
060: .setException(new ServerSideException(
061: Messages
062: .get(CoreMessageConstants.CANNOT_GET_USER_FROM_DATABASE),
063: e));
064:
065: }
066:
067: if (dbUser != null) {
068: if (user.equals(dbUser.getLogin())) {
069: if (Password.equals(dbUser.getPassword())) {
070: if (isValidUserType(dbUser.getType())) {
071: userInfo = new SecurityLoginInfo(dbUser
072: .getUserId(), dbUser.getLogin(), dbUser
073: .getName(), dbUser.getType(), dbUser
074: .getTimeout());
075: ConsoleUserSettingInfo info = ConsoleSettingUtil
076: .getConsoleUserSetting(String
077: .valueOf(dbUser.getUserId()));
078: userInfo.setSaInEndpointView(info
079: .getSaInEndpointView());
080: // connectiong to JMX also
081: //userInfo.setJmxConnectInfo(jmxConnect());
082:
083: // if (userInfo.getJmxConnectInfo() == null || userInfo.getJmxConnectInfo().isError()) {
084: // userInfo.setSuccess(true);
085: // userInfo
086: // .setError("User Logged in Succesfully but JMX Problem occured; some functionality may not work.");
087: // }
088:
089: if (!userInfo.isError()) {
090: HttpSession session = this
091: .getThreadLocalRequest()
092: .getSession();
093: session.setAttribute(
094: Constants.SECURITY_LOGIN_INFO,
095: userInfo);
096: session.setAttribute(
097: Constants.SECURITY_LOGIN_ID, String
098: .valueOf(userInfo
099: .getUserId()));
100: session.setAttribute(
101: Constants.LAST_CALL_TIMESTAMP,
102: System.currentTimeMillis());
103: }
104: }
105: } else {
106:
107: userInfo
108: .setException(new ServerSideException(
109: Messages
110: .get(CoreMessageConstants.WRONG_USERNAME_OR_PASSWORD)));
111:
112: }
113: } else {
114: userInfo
115: .setException(new ServerSideException(
116: Messages
117: .get(CoreMessageConstants.WRONG_USERNAME_OR_PASSWORD)));
118:
119: }
120: } else
121: userInfo
122: .setException(new ServerSideException(
123: Messages
124: .get(CoreMessageConstants.WRONG_USERNAME_OR_PASSWORD)));
125: return userInfo;
126: }
127:
128: private boolean isValidUserType(String type) {
129: if (type.equals(SecurityLoginInfo.administrator)
130: || type.equals(SecurityLoginInfo.operator)
131: || type.equals(SecurityLoginInfo.user))
132: return true;
133: return false;
134: }
135:
136: public boolean logout() {
137: jmxDisconnect();
138: //
139: ViewLogImpl.cbserverRAFFileHelper.init();
140: ViewLogImpl.tcwrapperRAFFileHelper.init();
141: ViewLogImpl.smwrapperRAFFileHelper.init();
142: return true;
143: }
144:
145: /*
146: * (non-Javadoc)
147: *
148: * @see com.bostechcorp.cbesb.console.rpc.SecurityLogin#jmsDisconnect()
149: */
150: public void jmxDisconnect() {
151: HttpSession session = this .getThreadLocalRequest().getSession();
152: JmxClient jmxClient = (JmxClient) session
153: .getAttribute(Constants.JMX_CLIENT);
154: if (jmxClient != null) {
155: session.setAttribute(Constants.JMX_CLIENT, null);
156: jmxClient.closeJmxConnection();
157: }
158:
159: }
160:
161: private ConsoleUserVO getConsoleUser(String loginNickname)
162: throws Exception {
163:
164: ConsoleUserVO userVO = ConsoleUserDB
165: .getUserByNickname(loginNickname);
166: return userVO;
167: }
168:
169: }
|