Source Code Cross Referenced for LoginBean.java in  » Portal » Open-Portal » com » sun » portal » admin » console » common » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.admin.console.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: LoginBean.java,v 1.7 2006/06/15 22:34:45 cathywu Exp $
003:         * Copyright 2005 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.admin.console.common;
014:
015:        import java.util.logging.Level;
016:        import java.util.Properties;
017:        import java.io.InputStream;
018:
019:        import javax.servlet.http.HttpSession;
020:
021:        import javax.management.remote.JMXConnector;
022:
023:        import javax.faces.context.FacesContext;
024:        import javax.faces.application.FacesMessage;
025:        import javax.faces.el.VariableResolver;
026:        import javax.faces.validator.ValidatorException;
027:        import javax.faces.component.UIComponent;
028:        import javax.faces.component.UIInput;
029:
030:        import com.sun.portal.admin.common.util.AdminClientUtil;
031:        import com.sun.portal.admin.console.common.LoginAlertBean;
032:        import com.sun.portal.admin.console.util.JMXHelpers;
033:
034:        public class LoginBean {
035:
036:            // Holds value of property userName. 
037:            private String userName = null;
038:
039:            // Holds value of property password. 
040:            private String password = null;
041:
042:            // Holds value of property usernameField . 
043:            private UIInput usernameField;
044:
045:            // Holds value of property passwordField. 
046:            private UIInput passwordField;
047:
048:            // Name of the connection property file
049:            public static final String PAS_SETTINGS_FILE = "pasconnect.properties";
050:
051:            // The host name where the mbean server is running
052:            private static String pasHost = null;
053:
054:            // The portal domain for which the console is connecting
055:            private static String pasDomain = null;
056:
057:            static {
058:
059:                try {
060:                    ClassLoader lbsCloader = LoginBean.class.getClassLoader();
061:                    InputStream is = lbsCloader
062:                            .getResourceAsStream(PAS_SETTINGS_FILE);
063:                    Properties pasSettings = new Properties();
064:                    if (is != null) {
065:                        pasSettings.load(is);
066:                        pasHost = pasSettings.getProperty("pas.host", "")
067:                                .trim();
068:                        pasDomain = pasSettings.getProperty("pas.domain", "")
069:                                .trim();
070:                    }
071:                } catch (Exception e) {
072:                    // Cannot load the connection settings file
073:                    // Ignore and proceed. console will connect to local mbean server
074:                }
075:            }
076:
077:            public LoginBean() {
078:            }
079:
080:            public String getUserName() {
081:                return userName;
082:            }
083:
084:            public void setUserName(String name) {
085:                userName = name;
086:            }
087:
088:            public String getPassword() {
089:                return password;
090:            }
091:
092:            public void setPassword(String pwd) {
093:                password = pwd;
094:            }
095:
096:            /**
097:             * Getter for property usernameField.
098:             *
099:             * @return Value of property usernameField.
100:             */
101:            public UIInput getUsernameField() {
102:                return this .usernameField;
103:            }
104:
105:            /**
106:             * Getter for pasHost.
107:             */
108:            public String getPasHost() {
109:                return pasHost;
110:            }
111:
112:            /**
113:             * Getter for pasDomain.
114:             */
115:            public String getPasDomain() {
116:                return pasDomain;
117:            }
118:
119:            /**
120:             * Setter for property usernameField.
121:             *
122:             * @param usernameField Value of property usernameField.
123:             */
124:            public void setUsernameField(UIInput usernameField) {
125:                this .usernameField = usernameField;
126:            }
127:
128:            /**
129:             * Getter for property passwordField.
130:             *
131:             * @return Value of property passwordField.
132:             */
133:            public UIInput getPasswordField() {
134:                return this .passwordField;
135:            }
136:
137:            /**
138:             * Setter for property passwordField.
139:             *
140:             * @param passwordField Value of property passwordFiled.
141:             */
142:            public void setPasswordField(UIInput passwordField) {
143:                this .passwordField = passwordField;
144:            }
145:
146:            private void setupLoginAlert(FacesContext context, String summary,
147:                    String detail, String type) {
148:                VariableResolver vr = context.getApplication()
149:                        .getVariableResolver();
150:                Object obj = vr.resolveVariable(context, "LoginAlert");
151:                if ((obj != null) && (obj instanceof  LoginAlertBean)) {
152:                    LoginAlertBean lab = (LoginAlertBean) obj;
153:                    lab.setDisplayError(Boolean.TRUE);
154:                    lab.setDisplaySpacer(Boolean.TRUE);
155:                    lab.setAlertSummary(summary);
156:                    lab.setAlertDetail(detail);
157:                    lab.setAlertType(type);
158:                }
159:            }
160:
161:            /** 
162:             * Validator method to be called durng the Process Validation phase.
163:             * It validates that the username and password fields contain non-null
164:             * values. 
165:             *	 
166:             * @param context The faces context for this request.
167:             * @param component The component to be validated.
168:             * @param value The value to be validated.
169:             */
170:            public void validateData(FacesContext context,
171:                    UIComponent component, Object value) {
172:                boolean pswdInvalid = false;
173:                boolean unameInvalid = false;
174:
175:                String username = "";
176:                String password = "";
177:                Object obj = usernameField.getLocalValue();
178:                if (obj != null) {
179:                    username = obj.toString();
180:                }
181:
182:                obj = passwordField.getLocalValue();
183:                if (obj != null) {
184:                    password = obj.toString();
185:                }
186:
187:                FacesMessage message = new FacesMessage();
188:
189:                // validate the local value of the password field component.
190:                if (!isValidData(password)) {
191:                    pswdInvalid = true;
192:                }
193:
194:                // validate the local value of the username field component.
195:                if (!isValidData(username)) {
196:                    unameInvalid = true;
197:                }
198:
199:                // Set appropriate error messages in LoginError object.
200:                String[] args = { "" };
201:                if ((pswdInvalid) && (unameInvalid)) {
202:                    setupLoginAlert(context, "login.validation.aleret.summary",
203:                            "login.uidpwd.validation.alert.detail", "error");
204:                } else if (pswdInvalid) {
205:                    setupLoginAlert(context, "login.validation.aleret.summary",
206:                            "login.password.validation.alert.detail", "error");
207:                } else if (unameInvalid) {
208:                    setupLoginAlert(context, "login.validation.aleret.summary",
209:                            "login.username.validation.alert.detail", "error");
210:                }
211:
212:                // If at least one field is invalid, throw the validator exception
213:                // to cause the same page to be re-rendered.
214:                if ((pswdInvalid) || (unameInvalid)) {
215:                    throw new ValidatorException(message);
216:                }
217:            }
218:
219:            // Helper method to validate data.	
220:            private boolean isValidData(String data) {
221:                if ((data == null) || (data.trim().length() == 0)) {
222:                    return false;
223:                }
224:                return true;
225:            }
226:
227:            public String login() {
228:                try {
229:                    authenticate(userName, password);
230:                } catch (SecurityException se) {
231:                    FacesContext context = FacesContext.getCurrentInstance();
232:                    setupLoginAlert(context,
233:                            "login.authentication.alert.summary",
234:                            "login.authentication.alert.detail", "error");
235:                    PSBaseBean
236:                            .log(
237:                                    Level.SEVERE,
238:                                    "Failed to authenticate with JMX Server: LoginBean.login()",
239:                                    se);
240:                    return "failure";
241:                } catch (Exception e) {
242:                    FacesContext context = FacesContext.getCurrentInstance();
243:                    setupLoginAlert(context,
244:                            "login.authentication.alert.summary",
245:                            "login.authentication.alert.detail", "error");
246:                    PSBaseBean
247:                            .log(
248:                                    Level.SEVERE,
249:                                    "Failed to authenticate with JMX Server: LoginBean.login()",
250:                                    e);
251:                    return "failure";
252:                }
253:                return "success";
254:            }
255:
256:            public String getAppContext() {
257:                return FacesContext.getCurrentInstance().getExternalContext()
258:                        .getRequestContextPath();
259:            }
260:
261:            private void authenticate(String uid, String pwd)
262:                    throws SecurityException, Exception {
263:                JMXConnector connector = JMXConnect(uid, pwd);
264:                if (connector != null) {
265:                    AuthCredentialBean abean = AuthCredentialBean
266:                            .getCurrentInstance();
267:                    if (abean != null) {
268:                        abean.setAuthCredential(connector, uid);
269:                        FacesContext context = FacesContext
270:                                .getCurrentInstance();
271:                        context.getApplication().createValueBinding(
272:                                "#{AuthCredentialBean}").setValue(context,
273:                                abean);
274:                    }
275:                }
276:            }
277:
278:            private JMXConnector JMXConnect(String uid, String pwd)
279:                    throws SecurityException, Exception {
280:
281:                JMXConnector jmxconn = null;
282:
283:                try {
284:
285:                    if (pasHost != null && pasHost.length() > 0) {
286:                        if (pasDomain != null && pasDomain.length() > 0) {
287:                            // Connect to the mbean server and domain defined in the 
288:                            // connection property file
289:                            jmxconn = AdminClientUtil.getJMXConnector(pasHost,
290:                                    pasDomain, uid, pwd);
291:                        } else {
292:                            // Connect to defaultdomain
293:                            jmxconn = AdminClientUtil.getJMXConnector(pasHost,
294:                                    AdminClientUtil.DEFAULT_DOMAIN, uid, pwd);
295:                        }
296:                    } else {
297:                        // Connect to the mbean server on local host
298:                        jmxconn = AdminClientUtil.getJMXConnector(uid, pwd);
299:                    }
300:
301:                } catch (SecurityException se) {
302:                    // must clean up so that we don't fool ourselves to believe there's
303:                    // a valid session
304:                    AuthCredentialBean abean = AuthCredentialBean
305:                            .getCurrentInstance();
306:                    if (abean != null) {
307:                        abean.resetAuthCredential();
308:                    }
309:                    throw se;
310:                } catch (Exception e) {
311:                    // must clean up so that we don't fool ourselves to believe there's
312:                    // a valid session
313:                    AuthCredentialBean abean = AuthCredentialBean
314:                            .getCurrentInstance();
315:                    if (abean != null) {
316:                        abean.resetAuthCredential();
317:                    }
318:                    throw e;
319:                }
320:
321:                return jmxconn;
322:            }
323:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.