Source Code Cross Referenced for LdapExtClient.java in  » Testing » jakarta-jmeter » org » apache » jmeter » protocol » ldap » sampler » 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 » Testing » jakarta jmeter » org.apache.jmeter.protocol.ldap.sampler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.protocol.ldap.sampler;
020:
021:        import java.util.Hashtable;
022:
023:        import javax.naming.Context;
024:        import javax.naming.NamingException;
025:        import javax.naming.NamingEnumeration;
026:        import javax.naming.directory.Attributes;
027:        import javax.naming.directory.DirContext;
028:        import javax.naming.directory.InitialDirContext;
029:        import javax.naming.directory.ModificationItem;
030:        import javax.naming.directory.SearchControls;
031:
032:        import org.apache.jorphan.logging.LoggingManager;
033:        import org.apache.log.Logger;
034:
035:        /*******************************************************************************
036:         * 
037:         * author Dolf Smits(Dolf.Smits@Siemens.com) created Aug 09 2003 11:00 AM
038:         * company Siemens Netherlands N.V..
039:         * 
040:         * Based on the work of: author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
041:         * created Apr 29 2003 11:00 AM company Sip Technologies and Exports Ltd.
042:         * 
043:         ******************************************************************************/
044:
045:        /*******************************************************************************
046:         * Ldap Client class is main class to create ,modify, search and delete all the
047:         * LDAP functionality available
048:         ******************************************************************************/
049:        public class LdapExtClient {
050:            private static final Logger log = LoggingManager
051:                    .getLoggerForClass();
052:
053:            private static final String CONTEXT_IS_NULL = "Context is null"; //TODO should perhaps be a resource
054:
055:            /**
056:             * Constructor for the LdapClient object
057:             */
058:            public LdapExtClient() {
059:            }
060:
061:            /**
062:             * connect to server
063:             * 
064:             * @param host
065:             *            Description of Parameter
066:             * @param username
067:             *            Description of Parameter
068:             * @param password
069:             *            Description of Parameter
070:             * @exception NamingException
071:             *                Description of Exception
072:             */
073:            public DirContext connect(String host, String port, String rootdn,
074:                    String username, String password, String connTimeOut,
075:                    boolean secure) throws NamingException {
076:                DirContext dirContext;
077:                Hashtable env = new Hashtable();
078:                env.put(Context.INITIAL_CONTEXT_FACTORY,
079:                        "com.sun.jndi.ldap.LdapCtxFactory"); // $NON-NLS-1$
080:                StringBuffer sb = new StringBuffer(80);
081:                if (secure) {
082:                    sb.append("ldaps://"); // $NON-NLS-1$
083:                } else {
084:                    sb.append("ldap://"); // $NON-NLS-1$
085:                }
086:                sb.append(host);
087:                if (port.length() > 0) {
088:                    sb.append(":"); // $NON-NLS-1$
089:                    sb.append(port);
090:                }
091:                sb.append("/"); // $NON-NLS-1$
092:                sb.append(rootdn);
093:                env.put(Context.PROVIDER_URL, sb.toString());
094:                log.info("prov_url= " + env.get(Context.PROVIDER_URL)); // $NON-NLS-1$
095:                if (connTimeOut.length() > 0) {
096:                    env.put("com.sun.jndi.ldap.connect.timeout", connTimeOut); // $NON-NLS-1$
097:                }
098:                env.put(Context.REFERRAL, "throw"); // $NON-NLS-1$
099:                env.put("java.naming.batchsize", "0"); // $NON-NLS-1$  // $NON-NLS-2$
100:                env.put(Context.SECURITY_CREDENTIALS, password);
101:                env.put(Context.SECURITY_PRINCIPAL, username);
102:                dirContext = new InitialDirContext(env);
103:                return dirContext;
104:            }
105:
106:            /**
107:             * disconnect from the server
108:             */
109:            public void disconnect(DirContext dirContext) {
110:                if (dirContext == null) {
111:                    log.info("Cannot disconnect null context");
112:                    return;
113:                }
114:
115:                try {
116:                    dirContext.close();
117:                } catch (NamingException e) {
118:                    log.warn("Ldap client disconnect - ", e);
119:                }
120:            }
121:
122:            /***************************************************************************
123:             * Filter the data in the ldap directory for the given search base
124:             * 
125:             * @param searchBase
126:             *            base where the search should start
127:             * @param searchFilter
128:             *            filter filter this value from the base
129:             **************************************************************************/
130:            public NamingEnumeration searchTest(DirContext dirContext,
131:                    String searchBase, String searchFilter, int scope,
132:                    long countlim, int timelim, String[] attrs, boolean retobj,
133:                    boolean deref) throws NamingException {
134:                if (dirContext == null) {
135:                    throw new NamingException(CONTEXT_IS_NULL);
136:                }
137:                SearchControls searchcontrols = null;
138:                searchcontrols = new SearchControls(scope, countlim, timelim,
139:                        attrs, retobj, deref);
140:                log.debug("scope, countlim, timelim, attrs, retobj, deref= "
141:                        + searchFilter + scope + countlim + timelim + attrs
142:                        + retobj + deref);
143:                return dirContext.search(searchBase, searchFilter,
144:                        searchcontrols);
145:            }
146:
147:            /***************************************************************************
148:             * Filter the data in the ldap directory
149:             * 
150:             * @param filter
151:             *            filter this value from the base
152:             **************************************************************************/
153:            public NamingEnumeration compare(DirContext dirContext,
154:                    String filter, String entrydn) throws NamingException {
155:                if (dirContext == null) {
156:                    throw new NamingException(CONTEXT_IS_NULL);
157:                }
158:                SearchControls searchcontrols = new SearchControls(0, 1, 0,
159:                        new String[0], false, false);
160:                return dirContext.search(entrydn, filter, searchcontrols);
161:            }
162:
163:            /***************************************************************************
164:             * ModDN the data in the ldap directory for the given search base
165:             * 
166:             **************************************************************************/
167:            public void moddnOp(DirContext dirContext, String ddn, String newdn)
168:                    throws NamingException {
169:                log.debug("ddn and newDn= " + ddn + "@@@@" + newdn);
170:                if (dirContext == null) {
171:                    throw new NamingException(CONTEXT_IS_NULL);
172:                }
173:                dirContext.rename(ddn, newdn);
174:            }
175:
176:            /***************************************************************************
177:             * Modify the attribute in the ldap directory for the given string
178:             * 
179:             * @param mods
180:             *            add all the entry in to the ModificationItem
181:             * @param string
182:             *            The string (dn) value
183:             **************************************************************************/
184:            public void modifyTest(DirContext dirContext,
185:                    ModificationItem[] mods, String string)
186:                    throws NamingException {
187:                if (dirContext == null) {
188:                    throw new NamingException(CONTEXT_IS_NULL);
189:                }
190:                dirContext.modifyAttributes(string, mods);
191:
192:            }
193:
194:            /***************************************************************************
195:             * Create the entry in the ldap directory for the given string
196:             * 
197:             * @param attributes
198:             *            add all the attributes and values from the attributes object
199:             * @param string
200:             *            The string (dn) value
201:             **************************************************************************/
202:            public DirContext createTest(DirContext dirContext,
203:                    Attributes attributes, String string)
204:                    throws NamingException {
205:                if (dirContext == null) {
206:                    throw new NamingException(CONTEXT_IS_NULL);
207:                }
208:                return dirContext.createSubcontext(string, attributes);
209:            }
210:
211:            /***************************************************************************
212:             * Delete the attribute from the ldap directory
213:             * 
214:             * @param string
215:             *            The string (dn) value
216:             **************************************************************************/
217:            public void deleteTest(DirContext dirContext, String string)
218:                    throws NamingException {
219:                if (dirContext == null) {
220:                    throw new NamingException(CONTEXT_IS_NULL);
221:                }
222:                dirContext.destroySubcontext(string);
223:            }
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.