Source Code Cross Referenced for ClientApplication.java in  » Security » acegi-security » sample » contact » 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 » Security » acegi security » sample.contact 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002:         *
003:         * Licensed under the Apache License, Version 2.0 (the "License");
004:         * you may not use this file except in compliance with the License.
005:         * You may obtain a copy of the License at
006:         *
007:         *     http://www.apache.org/licenses/LICENSE-2.0
008:         *
009:         * Unless required by applicable law or agreed to in writing, software
010:         * distributed under the License is distributed on an "AS IS" BASIS,
011:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:         * See the License for the specific language governing permissions and
013:         * limitations under the License.
014:         */
015:
016:        package sample.contact;
017:
018:        import org.acegisecurity.Authentication;
019:
020:        import org.acegisecurity.context.SecurityContextHolder;
021:
022:        import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
023:
024:        import org.springframework.beans.factory.ListableBeanFactory;
025:
026:        import org.springframework.context.support.FileSystemXmlApplicationContext;
027:
028:        import org.springframework.util.StopWatch;
029:
030:        import java.lang.reflect.InvocationTargetException;
031:        import java.lang.reflect.Method;
032:
033:        import java.util.Iterator;
034:        import java.util.List;
035:        import java.util.Map;
036:
037:        /**
038:         * Demonstrates accessing the {@link ContactManager} via remoting protocols.<P>Based on Spring's JPetStore sample,
039:         * written by Juergen Hoeller.</p>
040:         *
041:         * @author Ben Alex
042:         */
043:        public class ClientApplication {
044:            //~ Instance fields ================================================================================================
045:
046:            private final ListableBeanFactory beanFactory;
047:
048:            //~ Constructors ===================================================================================================
049:
050:            public ClientApplication(ListableBeanFactory beanFactory) {
051:                this .beanFactory = beanFactory;
052:            }
053:
054:            //~ Methods ========================================================================================================
055:
056:            public void invokeContactManager(Authentication authentication,
057:                    int nrOfCalls) {
058:                StopWatch stopWatch = new StopWatch(nrOfCalls
059:                        + " ContactManager call(s)");
060:                Map contactServices = this .beanFactory.getBeansOfType(
061:                        ContactManager.class, true, true);
062:
063:                SecurityContextHolder.getContext().setAuthentication(
064:                        authentication);
065:
066:                for (Iterator it = contactServices.keySet().iterator(); it
067:                        .hasNext();) {
068:                    String beanName = (String) it.next();
069:
070:                    Object object = this .beanFactory.getBean("&" + beanName);
071:
072:                    try {
073:                        System.out
074:                                .println("Trying to find setUsername(String) method on: "
075:                                        + object.getClass().getName());
076:
077:                        Method method = object.getClass().getMethod(
078:                                "setUsername", new Class[] { String.class });
079:                        System.out
080:                                .println("Found; Trying to setUsername(String) to "
081:                                        + authentication.getPrincipal());
082:                        method.invoke(object, new Object[] { authentication
083:                                .getPrincipal() });
084:                    } catch (NoSuchMethodException ignored) {
085:                        System.out
086:                                .println("This client proxy factory does not have a setUsername(String) method");
087:                    } catch (IllegalAccessException ignored) {
088:                        ignored.printStackTrace();
089:                    } catch (InvocationTargetException ignored) {
090:                        ignored.printStackTrace();
091:                    }
092:
093:                    try {
094:                        System.out
095:                                .println("Trying to find setPassword(String) method on: "
096:                                        + object.getClass().getName());
097:
098:                        Method method = object.getClass().getMethod(
099:                                "setPassword", new Class[] { String.class });
100:                        method.invoke(object, new Object[] { authentication
101:                                .getCredentials() });
102:                        System.out
103:                                .println("Found; Trying to setPassword(String) to "
104:                                        + authentication.getCredentials());
105:                    } catch (NoSuchMethodException ignored) {
106:                        System.out
107:                                .println("This client proxy factory does not have a setPassword(String) method");
108:                    } catch (IllegalAccessException ignored) {
109:                    } catch (InvocationTargetException ignored) {
110:                    }
111:
112:                    ContactManager remoteContactManager = (ContactManager) contactServices
113:                            .get(beanName);
114:                    System.out.println("Calling ContactManager '" + beanName
115:                            + "'");
116:
117:                    stopWatch.start(beanName);
118:
119:                    List contacts = null;
120:
121:                    for (int i = 0; i < nrOfCalls; i++) {
122:                        contacts = remoteContactManager.getAll();
123:                    }
124:
125:                    stopWatch.stop();
126:
127:                    if (contacts.size() != 0) {
128:                        Iterator listIterator = contacts.iterator();
129:
130:                        while (listIterator.hasNext()) {
131:                            Contact contact = (Contact) listIterator.next();
132:                            System.out
133:                                    .println("Contact: " + contact.toString());
134:                        }
135:                    } else {
136:                        System.out
137:                                .println("No contacts found which this user has permission to");
138:                    }
139:
140:                    System.out.println();
141:                    System.out.println(stopWatch.prettyPrint());
142:                }
143:
144:                SecurityContextHolder.clearContext();
145:            }
146:
147:            public static void main(String[] args) {
148:                String username = System.getProperty("username", "");
149:                String password = System.getProperty("password", "");
150:                String nrOfCallsString = System.getProperty("nrOfCalls", "");
151:
152:                if ("".equals(username) || "".equals(password)) {
153:                    System.out
154:                            .println("You need to specify the user ID to use, the password to use, and optionally a number of calls "
155:                                    + "using the username, password, and nrOfCalls system properties respectively. eg for user marissa, "
156:                                    + "use: -Dusername=marissa -Dpassword=koala' for a single call per service and "
157:                                    + "use: -Dusername=marissa -Dpassword=koala -DnrOfCalls=10 for ten calls per service.");
158:                    System.exit(-1);
159:                } else {
160:                    int nrOfCalls = 1;
161:
162:                    if (!"".equals(nrOfCallsString)) {
163:                        nrOfCalls = Integer.parseInt(nrOfCallsString);
164:                    }
165:
166:                    ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext(
167:                            "clientContext.xml");
168:                    ClientApplication client = new ClientApplication(
169:                            beanFactory);
170:
171:                    client.invokeContactManager(
172:                            new UsernamePasswordAuthenticationToken(username,
173:                                    password), nrOfCalls);
174:                    System.exit(0);
175:                }
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.