1 13 14 19 package org.ejbca.util.query; 20 21 32 public class UserMatch extends BasicMatch { 33 35 public static final int MATCH_WITH_USERNAME = 0; 36 public static final int MATCH_WITH_EMAIL = 1; 37 public static final int MATCH_WITH_STATUS = 2; public static final int MATCH_WITH_ENDENTITYPROFILE = 3; public static final int MATCH_WITH_CERTIFICATEPROFILE = 4; public static final int MATCH_WITH_CA = 5; public static final int MATCH_WITH_TOKEN = 6; 42 public static final int MATCH_WITH_DN = 7; 43 public static final int MATCH_WITH_UID = 100; 45 public static final int MATCH_WITH_COMMONNAME = 101; 46 public static final int MATCH_WITH_DNSERIALNUMBER = 102; 47 public static final int MATCH_WITH_GIVENNAME = 103; 48 public static final int MATCH_WITH_INITIALS = 104; 49 public static final int MATCH_WITH_SURNAME = 105; 50 public static final int MATCH_WITH_TITLE = 106; 51 public static final int MATCH_WITH_ORGANIZATIONUNIT = 107; 52 public static final int MATCH_WITH_ORGANIZATION = 108; 53 public static final int MATCH_WITH_LOCALE = 109; 54 public static final int MATCH_WITH_STATE = 110; 55 public static final int MATCH_WITH_DOMAINCOMPONENT = 111; 56 public static final int MATCH_WITH_COUNTRY = 112; 57 public static final int MATCH_WITH_RFC822NAME = 200; 59 public static final int MATCH_WITH_DNSNAME = 201; 60 public static final int MATCH_WITH_IPADDRESS = 202; 61 public static final int MATCH_WITH_X400ADDRESS = 203; 62 public static final int MATCH_WITH_DIRECTORYNAME = 204; 63 public static final int MATCH_WITH_EDIPARTNAME = 205; 64 public static final int MATCH_WITH_URI = 206; 65 public static final int MATCH_WITH_REGISTEREDID = 207; 66 public static final int MATCH_WITH_UPN = 208; 67 public static final int MATCH_WITH_GUID = 209; 68 69 70 71 static final String [] MATCH_WITH_SQLNAMES = {"username", "subjectEmail", "status" 73 , "endEntityProfileId", "certificateProfileId" 74 , "cAId", "tokenType"}; 75 76 77 private static final String MATCH_WITH_SUBJECTDN = "subjectDN"; 79 private static final String [] MATCH_WITH_SUBJECTDN_NAMES = { 80 "UID=", "CN=", "SN=", "GIVENNAME=", "INITIALS=", "SURNAME=", "T=", "OU=", "O=", "L=", "ST=", 81 "DC", "C=" 82 }; 83 84 private static final String MATCH_WITH_SUBJECTALTNAME = "subjectAltName"; 85 private static final String [] MATCH_WITH_SUBJECTALTNAME_NAMES = { 86 "RFC822NAME=", "DNSNAME=", "IPADDRESS=", "X400ADDRESS=", "DIRECTORYNAME=", 87 "EDIPARTNAME=", "UNIFORMRESOURCEIDENTIFIER=", "REGISTEREDID=", "UPN=", "GUID=" 88 }; 89 91 102 public UserMatch(int matchwith, int matchtype, String matchvalue) 103 throws NumberFormatException { 104 this.matchwith = matchwith; 105 this.matchtype = matchtype; 106 this.matchvalue = matchvalue; 107 108 if ((matchwith >= MATCH_WITH_STATUS) && (matchwith <= MATCH_WITH_CA)) { 109 new Integer (matchvalue); 110 } 111 } 112 113 118 public String getQueryString() { 119 String returnval = ""; 120 121 if (isSubjectDNMatch()) { 122 returnval = MATCH_WITH_SUBJECTDN + " LIKE '%" + 124 MATCH_WITH_SUBJECTDN_NAMES[matchwith - 100] + matchvalue + "%'"; 125 }else{ 126 if (isSubjectAltNameMatch()){ 127 returnval = MATCH_WITH_SUBJECTALTNAME + " LIKE '%" + 128 MATCH_WITH_SUBJECTALTNAME_NAMES[matchwith - 200] + matchvalue + "%'"; 129 }else { 130 if(matchwith == MATCH_WITH_DN){ 131 if (matchtype == BasicMatch.MATCH_TYPE_EQUALS) { 132 returnval = MATCH_WITH_SUBJECTDN + " = '" + matchvalue + "'"; 133 } 134 135 if (matchtype == BasicMatch.MATCH_TYPE_BEGINSWITH) { 136 returnval = MATCH_WITH_SUBJECTDN + " LIKE '" + matchvalue + "%'"; 137 } 138 139 if (matchtype == BasicMatch.MATCH_TYPE_CONTAINS) { 140 returnval = MATCH_WITH_SUBJECTDN + " LIKE '%" + matchvalue + "%'"; 141 } 142 143 }else{ 144 if (matchtype == BasicMatch.MATCH_TYPE_EQUALS) { 145 String stringChar = "'"; 148 if ((matchwith == MATCH_WITH_STATUS) || (matchwith == MATCH_WITH_CA) || (matchwith == MATCH_WITH_CERTIFICATEPROFILE) || (matchwith == MATCH_WITH_ENDENTITYPROFILE) || (matchwith == MATCH_WITH_TOKEN)) { 149 stringChar = ""; 150 } 151 returnval = MATCH_WITH_SQLNAMES[matchwith] + " = "+stringChar + matchvalue + stringChar; 152 } 153 154 if (matchtype == BasicMatch.MATCH_TYPE_BEGINSWITH) { 155 returnval = MATCH_WITH_SQLNAMES[matchwith] + " LIKE '" + matchvalue + "%'"; 156 } 157 } 158 } 159 } 160 return returnval; 161 } 162 163 165 170 public boolean isLegalQuery() { 171 if(matchvalue == null){ 172 return false; 173 } 174 return !(matchvalue.trim().equals("")); 175 } 176 177 private boolean isSubjectDNMatch() { 179 return this.matchwith >= 100 && this.matchwith < 200; 180 } 181 182 private boolean isSubjectAltNameMatch() { 184 return this.matchwith >= 200 && this.matchwith < 300; 185 } 186 187 private int matchwith; 189 private int matchtype; 190 private String matchvalue; 191 } 192 | Popular Tags |