Source Code Cross Referenced for UserMatch.java in  » Authentication-Authorization » ejbca » org » ejbca » util » query » 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 » Authentication Authorization » ejbca » org.ejbca.util.query 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*************************************************************************
002:         *                                                                       *
003:         *  EJBCA: The OpenSource Certificate Authority                          *
004:         *                                                                       *
005:         *  This software is free software; you can redistribute it and/or       *
006:         *  modify it under the terms of the GNU Lesser General Public           *
007:         *  License as published by the Free Software Foundation; either         *
008:         *  version 2.1 of the License, or any later version.                    *
009:         *                                                                       *
010:         *  See terms of license at gnu.org.                                     *
011:         *                                                                       *
012:         *************************************************************************/package org.ejbca.util.query;
013:
014:        /**
015:         * A class used by Query class to build a query for ejbca ra module. Inherits BasicMatch.  Main
016:         * function is getQueryString which returns a fragment of SQL statment.
017:         *
018:         * @author TomSelleck
019:         * @version $Id: UserMatch.java,v 1.5 2007/05/04 09:06:39 anatom Exp $
020:         *
021:         * @see org.ejbca.util.query.BasicMatch
022:         * @see org.ejbca.util.query.TimeMatch
023:         * @see org.ejbca.util.query.LogMatch
024:         */
025:        public class UserMatch extends BasicMatch {
026:            // Public Constants
027:
028:            public static final int MATCH_WITH_USERNAME = 0;
029:            public static final int MATCH_WITH_EMAIL = 1;
030:            public static final int MATCH_WITH_STATUS = 2; // Value must the number representation.
031:            public static final int MATCH_WITH_ENDENTITYPROFILE = 3; // Matches the profile id not profilename.
032:            public static final int MATCH_WITH_CERTIFICATEPROFILE = 4; // Matches the certificatetype id not name.
033:            public static final int MATCH_WITH_CA = 5; // Matches the CA id not CA name.
034:            public static final int MATCH_WITH_TOKEN = 6;
035:            public static final int MATCH_WITH_DN = 7;
036:            // Subject DN fields.
037:            public static final int MATCH_WITH_UID = 100;
038:            public static final int MATCH_WITH_COMMONNAME = 101;
039:            public static final int MATCH_WITH_DNSERIALNUMBER = 102;
040:            public static final int MATCH_WITH_GIVENNAME = 103;
041:            public static final int MATCH_WITH_INITIALS = 104;
042:            public static final int MATCH_WITH_SURNAME = 105;
043:            public static final int MATCH_WITH_TITLE = 106;
044:            public static final int MATCH_WITH_ORGANIZATIONUNIT = 107;
045:            public static final int MATCH_WITH_ORGANIZATION = 108;
046:            public static final int MATCH_WITH_LOCALE = 109;
047:            public static final int MATCH_WITH_STATE = 110;
048:            public static final int MATCH_WITH_DOMAINCOMPONENT = 111;
049:            public static final int MATCH_WITH_COUNTRY = 112;
050:            // Subject Altname Fields
051:            public static final int MATCH_WITH_RFC822NAME = 200;
052:            public static final int MATCH_WITH_DNSNAME = 201;
053:            public static final int MATCH_WITH_IPADDRESS = 202;
054:            public static final int MATCH_WITH_X400ADDRESS = 203;
055:            public static final int MATCH_WITH_DIRECTORYNAME = 204;
056:            public static final int MATCH_WITH_EDIPARTNAME = 205;
057:            public static final int MATCH_WITH_URI = 206;
058:            public static final int MATCH_WITH_REGISTEREDID = 207;
059:            public static final int MATCH_WITH_UPN = 208;
060:            public static final int MATCH_WITH_GUID = 209;
061:
062:            // Private Constants.
063:            static final String[] MATCH_WITH_SQLNAMES = { "username",
064:                    "subjectEmail", "status", "endEntityProfileId",
065:                    "certificateProfileId", "cAId", "tokenType" };
066:
067:            // Represents the column names in ra userdata table.
068:            private static final String MATCH_WITH_SUBJECTDN = "subjectDN";
069:            private static final String[] MATCH_WITH_SUBJECTDN_NAMES = {
070:                    "UID=", "CN=", "SN=", "GIVENNAME=", "INITIALS=",
071:                    "SURNAME=", "T=", "OU=", "O=", "L=", "ST=", "DC", "C=" };
072:
073:            private static final String MATCH_WITH_SUBJECTALTNAME = "subjectAltName";
074:            private static final String[] MATCH_WITH_SUBJECTALTNAME_NAMES = {
075:                    "RFC822NAME=", "DNSNAME=", "IPADDRESS=", "X400ADDRESS=",
076:                    "DIRECTORYNAME=", "EDIPARTNAME=",
077:                    "UNIFORMRESOURCEIDENTIFIER=", "REGISTEREDID=", "UPN=",
078:                    "GUID=" };
079:
080:            // Public methods.
081:
082:            /**
083:             * Creates a new instance of UserMatch.
084:             *
085:             * @param matchwith determines which field i userdata table to match with.
086:             * @param matchtype determines how to match the field. SubjectDN fields can only be matched
087:             *        with 'begins with'.
088:             * @param matchvalue the value to match with.
089:             *
090:             * @throws NumberFormatException if matchvalue constains illegal numbervalue when matching
091:             *         number field.
092:             */
093:            public UserMatch(int matchwith, int matchtype, String matchvalue)
094:                    throws NumberFormatException {
095:                this .matchwith = matchwith;
096:                this .matchtype = matchtype;
097:                this .matchvalue = matchvalue;
098:
099:                if ((matchwith >= MATCH_WITH_STATUS)
100:                        && (matchwith <= MATCH_WITH_CA)) {
101:                    new Integer(matchvalue);
102:                }
103:            }
104:
105:            /**
106:             * Returns a SQL statement fragment from the given data.
107:             *
108:             * @return sql string
109:             */
110:            public String getQueryString() {
111:                String returnval = "";
112:
113:                if (isSubjectDNMatch()) {
114:                    // Ignore MATCH_TYPE_EQUALS.
115:                    returnval = MATCH_WITH_SUBJECTDN + " LIKE '%"
116:                            + MATCH_WITH_SUBJECTDN_NAMES[matchwith - 100]
117:                            + matchvalue + "%'";
118:                } else {
119:                    if (isSubjectAltNameMatch()) {
120:                        returnval = MATCH_WITH_SUBJECTALTNAME
121:                                + " LIKE '%"
122:                                + MATCH_WITH_SUBJECTALTNAME_NAMES[matchwith - 200]
123:                                + matchvalue + "%'";
124:                    } else {
125:                        if (matchwith == MATCH_WITH_DN) {
126:                            if (matchtype == BasicMatch.MATCH_TYPE_EQUALS) {
127:                                returnval = MATCH_WITH_SUBJECTDN + " = '"
128:                                        + matchvalue + "'";
129:                            }
130:
131:                            if (matchtype == BasicMatch.MATCH_TYPE_BEGINSWITH) {
132:                                returnval = MATCH_WITH_SUBJECTDN + " LIKE '"
133:                                        + matchvalue + "%'";
134:                            }
135:
136:                            if (matchtype == BasicMatch.MATCH_TYPE_CONTAINS) {
137:                                returnval = MATCH_WITH_SUBJECTDN + " LIKE '%"
138:                                        + matchvalue + "%'";
139:                            }
140:
141:                        } else {
142:                            if (matchtype == BasicMatch.MATCH_TYPE_EQUALS) {
143:                                // Because some databases (read JavaDB/Derby) does not allow matching of integer with a string expression
144:                                // like "where status='10'" instead of "where status=10", we have to hav e some special handling here.
145:                                String stringChar = "'";
146:                                if ((matchwith == MATCH_WITH_STATUS)
147:                                        || (matchwith == MATCH_WITH_CA)
148:                                        || (matchwith == MATCH_WITH_CERTIFICATEPROFILE)
149:                                        || (matchwith == MATCH_WITH_ENDENTITYPROFILE)
150:                                        || (matchwith == MATCH_WITH_TOKEN)) {
151:                                    stringChar = "";
152:                                }
153:                                returnval = MATCH_WITH_SQLNAMES[matchwith]
154:                                        + " = " + stringChar + matchvalue
155:                                        + stringChar;
156:                            }
157:
158:                            if (matchtype == BasicMatch.MATCH_TYPE_BEGINSWITH) {
159:                                returnval = MATCH_WITH_SQLNAMES[matchwith]
160:                                        + " LIKE '" + matchvalue + "%'";
161:                            }
162:                        }
163:                    }
164:                }
165:                return returnval;
166:            }
167:
168:            // getQueryString
169:
170:            /**
171:             * Checks if query data is ok.
172:             *
173:             * @return true if query is legal, false otherwise
174:             */
175:            public boolean isLegalQuery() {
176:                if (matchvalue == null) {
177:                    return false;
178:                }
179:                return !(matchvalue.trim().equals(""));
180:            }
181:
182:            // Private Methods
183:            private boolean isSubjectDNMatch() {
184:                return this .matchwith >= 100 && this .matchwith < 200;
185:            }
186:
187:            // Private Methods
188:            private boolean isSubjectAltNameMatch() {
189:                return this .matchwith >= 200 && this .matchwith < 300;
190:            }
191:
192:            // Private Fields.
193:            private int matchwith;
194:            private int matchtype;
195:            private String matchvalue;
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.