001: /**
002: * $Id: AuthCredentialBean.java,v 1.5 2006/01/26 22:20:48 hc109819 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.io.IOException;
016: import java.util.logging.Level;
017:
018: import javax.faces.context.FacesContext;
019: import javax.faces.el.VariableResolver;
020:
021: import javax.management.remote.JMXConnector;
022: import javax.management.MBeanServerConnection;
023:
024: import com.sun.portal.admin.console.util.MBeanServerConnectionWrapperFactory;
025: import com.sun.portal.admin.console.sra.utils.Util;
026:
027: /**
028: *
029: */
030: public class AuthCredentialBean {
031:
032: private transient JMXConnector connector = null;
033: private transient MBeanServerConnection mbsc = null;
034: private transient String uid = null;
035:
036: /** Creates a new instance of AuthCredentialBean */
037: public AuthCredentialBean() {
038: }
039:
040: public void setAuthCredential(JMXConnector connector, String uid) {
041: if ((connector != null) && (uid != null)) {
042: this .connector = connector;
043: this .uid = uid;
044: try {
045: // gets the MBeanServerConnection from the wrapper factory
046: mbsc = MBeanServerConnectionWrapperFactory
047: .getInstance(this .connector
048: .getMBeanServerConnection());
049: } catch (IOException ioe) {
050: resetAuthCredential();
051: PSBaseBean
052: .log(
053: Level.SEVERE,
054: "Failed to init MBean Server Connection : AuthCredentialBean.setAuthCredential()",
055: ioe);
056: }
057: } else {
058: resetAuthCredential();
059: }
060: }
061:
062: public void resetAuthCredential() {
063: connector = null;
064: uid = null;
065: mbsc = null;
066: }
067:
068: public void closeConnection() throws IOException {
069: if (connector != null) {
070: connector.close();
071: }
072: }
073:
074: private JMXConnector getJMXConnector() {
075: return connector;
076: }
077:
078: public MBeanServerConnection getMBeanServerConnection() {
079: return mbsc;
080: }
081:
082: public String getUID() {
083: return uid;
084: }
085:
086: public static AuthCredentialBean getCurrentInstance() {
087: VariableResolver vr = FacesContext.getCurrentInstance()
088: .getApplication().getVariableResolver();
089: Object obj = vr.resolveVariable(FacesContext
090: .getCurrentInstance(), "AuthCredentialBean");
091: if ((obj != null) && (obj instanceof AuthCredentialBean)) {
092: return (AuthCredentialBean) obj;
093: }
094: return null;
095: }
096:
097: public boolean isUserAuthenticated() {
098: return ((connector != null) && (uid != null) && (mbsc != null)) ? true
099: : false;
100: }
101: }
|