Source Code Cross Referenced for AdminServerUtil.java in  » Portal » Open-Portal » com » sun » portal » admin » server » 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.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: AdminServerUtil.java,v 1.7 2005/11/23 21:39:22 yue Exp $
003:         * Copyright 2004 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.server;
014:
015:        import java.io.IOException;
016:        import java.security.AccessControlContext;
017:        import java.security.AccessController;
018:        import java.util.LinkedList;
019:        import java.util.Set;
020:
021:        import javax.management.remote.JMXConnector;
022:        import javax.security.auth.Subject;
023:
024:        import com.iplanet.am.util.AMPasswordUtil;
025:        import com.iplanet.sso.SSOToken;
026:        import com.sun.cacao.agent.auth.CacaoCallbackHandler;
027:        import com.sun.cacao.agent.auth.Credential;
028:        import com.sun.portal.admin.common.context.PortalDomainContext;
029:        import com.sun.portal.admin.common.context.PortalDomainContextException;
030:        import com.sun.portal.admin.common.context.PortalDomainContextFactory;
031:        import com.sun.portal.admin.common.util.AdminUtil;
032:
033:        /**
034:         * This class provides misc. utility methods for portal MBeans.
035:         */
036:        public class AdminServerUtil extends AdminUtil {
037:            /**
038:             * Returns a connected JMXConnector to the connector server
039:             * running on the given host.  The connection is authenticated
040:             * using the JASS credentials from the current context.  This
041:             * method is typically used by a portal MBean to make a connection
042:             * to the Portal Admin Server running on another host.
043:             * <p>
044:             * The caller is responsible for obtaining the
045:             * MBeanServerConnection and closing the returned JMXConnector.
046:             *
047:             * @param  host  the host where the JMX connector server is running on.
048:             * @return a connected JMXConnector.
049:             * @exception NullPointerException if host is null.
050:             * @exception SecurityException if an authentication error occurs.
051:             * @exception IOException if a connection error occurs.
052:             */
053:            public static JMXConnector getJMXConnector(String host)
054:                    throws SecurityException, IOException {
055:
056:                if (host == null) {
057:                    throw new NullPointerException("host is null.");
058:                }
059:
060:                // recover the credentials we need to open this connection...
061:                AccessControlContext acc = AccessController.getContext();
062:                Subject subject = Subject.getSubject(acc);
063:                Set publicCreds = subject
064:                        .getPublicCredentials(Credential.class);
065:                Set privateCreds = subject
066:                        .getPrivateCredentials(Credential.class);
067:
068:                // we expect only one match to this query
069:                if ((publicCreds.size() != 1) || (privateCreds.size() != 1)) {
070:                    throw new SecurityException("Cannot get unique credentials");
071:                }
072:
073:                String authID = ((Credential) publicCreds.iterator().next())
074:                        .getValue();
075:                String passwd = ((Credential) privateCreds.iterator().next())
076:                        .getValue();
077:                String[] authPieces = authID
078:                        .split(CacaoCallbackHandler.SEPARATOR);
079:
080:                if (CacaoCallbackHandler.getMechanisms().get(authPieces[0]) == null) {
081:                    throw new IllegalArgumentException(
082:                            "Invalid JAAS credentials");
083:                }
084:
085:                return getConnector(host, authID, passwd);
086:            }
087:
088:            /**
089:             * Returns the password of the currently authenticated user.  If
090:             * the user has not been authenticated, <code>null</code> is returned.
091:             *
092:             * @return the password of the currently authenticated user;
093:             *         <code>null</code> if the user has not been authenticated.
094:             */
095:            public static String getPassword() {
096:                AccessControlContext acc = AccessController.getContext();
097:                Subject subject = Subject.getSubject(acc);
098:
099:                if (subject == null) {
100:                    return null;
101:                }
102:
103:                Set credentials = subject
104:                        .getPrivateCredentials(Credential.class);
105:
106:                if ((credentials == null) || credentials.isEmpty()) {
107:                    return null;
108:                }
109:
110:                return ((Credential) credentials.iterator().next()).getValue();
111:            }
112:
113:            /**
114:             * Returns the SSO token of the currently authenticated user.  If
115:             * the user has not been authenticated (i.e. no SSO token),
116:             * <code>null</code> is returned.
117:             *
118:             * @return the SSOToken of the currently authenticated user;
119:             *         <code>null</code> if the user has not been authenticated.
120:             */
121:            public static SSOToken getSSOToken() {
122:                AccessControlContext acc = AccessController.getContext();
123:                Subject subject = Subject.getSubject(acc);
124:
125:                if (subject == null) {
126:                    return null;
127:                }
128:
129:                Set principals = subject.getPrincipals(PASPrincipal.class);
130:
131:                if ((principals == null) || principals.isEmpty()) {
132:                    return null;
133:                }
134:
135:                return ((PASPrincipal) principals.iterator().next())
136:                        .getSSOToken();
137:            }
138:
139:            /**
140:             * Encrypts the given clear text.
141:             *
142:             * @param  clearText  the clear text to be encrypted.
143:             * @return the encrypted text.
144:             */
145:            public static String encrypt(String clearText) {
146:                return AMPasswordUtil.encrypt(clearText);
147:            }
148:
149:            /**
150:             * Decrypts the given encrypted text.
151:             *
152:             * @param  encryptedText  the encrypted text to be decrypted.
153:             * @return the decrypted clear text.
154:             */
155:            public static String decrypt(String encryptedText) {
156:                return AMPasswordUtil.decrypt(encryptedText);
157:            }
158:
159:            /**
160:             * Returns the portal server instances in the portal with the
161:             * given portal ID and in the portal domain with the given domain ID.
162:             *
163:             * @param  domainID  domain ID of the portal domain.
164:             * @param  portalID  portal ID of the portal.
165:             * @return the IDs of the portal server instances.
166:             * @exception NullPointerException if domainID or portalID is
167:             *                                 <code>null</code>.
168:             * @exception NoSuchElementException if there is no portal domain
169:             *                                   with the given domain ID or no
170:             *                                   portal with the given portal ID.
171:             * @exception PortalDomainContextException if an error occurs when
172:             *                                         reading the instance IDs.
173:             */
174:            public static Set getPortalServerInstances(String domainID,
175:                    String portalID) throws PortalDomainContextException {
176:
177:                PortalDomainContext pdc = PortalDomainContextFactory
178:                        .getPortalDomainContext(domainID);
179:
180:                LinkedList path = new LinkedList();
181:                path.addFirst(domainID);
182:                path.addFirst(portalID);
183:                return pdc.getResourceIDs(PORTAL_SERVER_INSTANCE_MBEAN_TYPE,
184:                        path);
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.