Source Code Cross Referenced for Server.java in  » J2EE » enhydra » mx4j » examples » remote » interception » 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 » J2EE » enhydra » mx4j.examples.remote.interception 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The MX4J Contributors.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the MX4J License version 1.0.
006:         * See the terms of the MX4J License in the documentation provided with this software.
007:         */
008:
009:        package mx4j.examples.remote.interception;
010:
011:        import java.io.File;
012:        import java.io.FileOutputStream;
013:        import java.io.IOException;
014:        import java.util.HashMap;
015:        import java.util.Map;
016:        import java.util.Properties;
017:        import javax.management.MBeanServer;
018:        import javax.management.MBeanServerFactory;
019:        import javax.management.ObjectName;
020:        import javax.management.remote.JMXAuthenticator;
021:        import javax.management.remote.JMXConnectorServer;
022:        import javax.management.remote.JMXConnectorServerFactory;
023:        import javax.management.remote.JMXServiceURL;
024:
025:        import mx4j.tools.naming.NamingService;
026:        import mx4j.tools.remote.PasswordAuthenticator;
027:
028:        /**
029:         * This example shows how to setup a JSR 160 connector server that intercepts calls to its target MBeanServer.
030:         * It will be shown how to intercept and print on the console the Subject of the current call.
031:         * It is very similar to the {@link mx4j.examples.remote.security.Server security example}, because it needs
032:         * an authenticated Subject to be present in order to log the Subject of the current invocation.
033:         *
034:         * @version $Revision: 1.1 $
035:         * @see Client
036:         */
037:        public class Server {
038:            private static final String PASSWORD_FILE = "users.properties";
039:
040:            public static void main(String[] args) throws Exception {
041:                prepareUsersFile();
042:
043:                // The address of the connector server
044:                JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0,
045:                        "/jndi/jmx");
046:
047:                // Specify the authenticator in the environment Map, using the
048:                // standard property JMXConnector.AUTHENTICATOR
049:                Map environment = new HashMap();
050:                JMXAuthenticator authenticator = new PasswordAuthenticator(
051:                        new File(PASSWORD_FILE));
052:                environment
053:                        .put(JMXConnectorServer.AUTHENTICATOR, authenticator);
054:
055:                // Create and register the connector server
056:                JMXConnectorServer cntorServer = JMXConnectorServerFactory
057:                        .newJMXConnectorServer(url, environment, null);
058:                ObjectName cntorServerName = ObjectName.getInstance(":service="
059:                        + JMXConnectorServer.class.getName() + ",protocol="
060:                        + url.getProtocol());
061:                MBeanServer server = MBeanServerFactory
062:                        .createMBeanServer("remote.security.example");
063:                server.registerMBean(cntorServer, cntorServerName);
064:
065:                // Setup the rmiregistry to bind in JNDI the RMIConnectorServer stub.
066:                NamingService naming = new NamingService();
067:                ObjectName namingName = ObjectName.getInstance(":service="
068:                        + NamingService.class.getName());
069:                server.registerMBean(naming, namingName);
070:                naming.start();
071:
072:                // Setup the interception
073:                SubjectTrackingMBeanServer interceptor = new SubjectTrackingMBeanServer();
074:                cntorServer.setMBeanServerForwarder(interceptor);
075:
076:                // Start the connector server
077:                cntorServer.start();
078:
079:                System.out.println("Server up and running");
080:            }
081:
082:            /**
083:             * Writes a user/password file in the filesystem, with two hardcoded users:
084:             * 'admin' and 'guest'.
085:             * Normally this file is provided externally, not created by a program.
086:             * Purpose of this method is to show how to obfuscate passwords using
087:             * {@link PasswordAuthenticator}.
088:             */
089:            private static void prepareUsersFile() throws IOException {
090:                Properties properties = new Properties();
091:
092:                String user = "admin";
093:                String password = PasswordAuthenticator
094:                        .obfuscatePassword("admin");
095:                properties.setProperty(user, password);
096:
097:                user = "guest";
098:                password = PasswordAuthenticator.obfuscatePassword("guest");
099:                properties.setProperty(user, password);
100:
101:                FileOutputStream fos = new FileOutputStream(new File(
102:                        PASSWORD_FILE));
103:                properties.store(fos, null);
104:            }
105:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.