⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 endentityprofile.java

📁 一套JAVA的CA证书签发系统.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     // Check if ca id is among available ca ids.      String[] availablecaids;      try{        availablecaids = getValue(AVAILCAS,0).split(SPLITCHAR);      }catch(Exception e){          throw new UserDoesntFullfillEndEntityProfile("Error parsing end entity profile.");      }      if(availablecaids == null)           throw new UserDoesntFullfillEndEntityProfile("Error End Entity Profiles Available CAs is null.");      else{        boolean found=false;        for(int i=0; i < availablecaids.length;i++){          int tmp = Integer.parseInt(availablecaids[i]);          if( tmp == caid || tmp == SecConst.ALLCAS)            found=true;        }        if(!found)           throw new UserDoesntFullfillEndEntityProfile("Couldn't find CA among End Entity Profiles Available CAs.");      }          }        public void doesPasswordFulfillEndEntityProfile(String password, boolean clearpwd)      throws UserDoesntFullfillEndEntityProfile{    			boolean fullfillsprofile = true;		if(useAutoGeneratedPasswd()){		  if(password !=null)			throw new UserDoesntFullfillEndEntityProfile("Autogenerated password must have password==null");		}else{           		            		 if(!isModifyable(EndEntityProfile.PASSWORD,0)){		   if(!password.equals(getValue(EndEntityProfile.PASSWORD,0)));		   			 fullfillsprofile=false;		 } 		 else		   if(isRequired(EndEntityProfile.PASSWORD,0)){			 if((!clearpwd && password == null) || (password != null && password.trim().equals("")))						   fullfillsprofile=false;		   }		}           		 if(clearpwd && isRequired(EndEntityProfile.CLEARTEXTPASSWORD,0) && getValue(EndEntityProfile.CLEARTEXTPASSWORD,0).equals(EndEntityProfile.FALSE)){		 				 fullfillsprofile=false;		 }		 		 if(!fullfillsprofile)		   throw new UserDoesntFullfillEndEntityProfile("Password doesn't fullfill profile.");    }    public Object clone() throws CloneNotSupportedException {      EndEntityProfile clone = new EndEntityProfile();      HashMap clonedata = (HashMap) clone.saveData();      Iterator i = (data.keySet()).iterator();      while(i.hasNext()){        Object key = i.next();        clonedata.put(key,data.get(key));      }      clone.loadData(clonedata);      return clone;    }    /** Implemtation of UpgradableDataHashMap function getLatestVersion */    public float getLatestVersion(){       return LATEST_VERSION;    }    /** Implemtation of UpgradableDataHashMap function upgrade. */    public void upgrade() {        log.debug(">upgrade");        if(LATEST_VERSION != getVersion()){            log.info("upgrading entityprofile with version "+getVersion());            // New version of the class, upgrade            if(getVersion() < 1){                ArrayList numberarray = (ArrayList)   data.get(NUMBERARRAY);                while(numberarray.size() < 37){                   numberarray.add(new Integer(0));                }                data.put(NUMBERARRAY,numberarray);              }            if(getVersion() < 2){                ArrayList numberarray = (ArrayList)   data.get(NUMBERARRAY);                while(numberarray.size() < 39){                   numberarray.add(new Integer(0));                }                data.put(NUMBERARRAY,numberarray);                                addField(AVAILCAS);                addField(DEFAULTCA);                setRequired(AVAILCAS,0,true);                setRequired(DEFAULTCA,0,true);            }            if(getVersion() < 3){                setNotificationSubject("");                setNotificationSender("");                setNotificationMessage("");            }                        if(getVersion() < 4){                ArrayList numberoffields = (ArrayList)   data.get(NUMBERARRAY);                                for(int i =numberoffields.size(); i < NUMBEROFPARAMETERS; i++){                  numberoffields.add(new Integer(0));                }                               data.put(NUMBERARRAY,numberoffields);                            }                        data.put(VERSION, new Float(LATEST_VERSION));        }        log.debug("<upgrade");    }    // Private Methods    private void checkIfEmailFullfillProfile(int field, int number, String email, String text) throws UserDoesntFullfillEndEntityProfile {    	if(!email.trim().equals("") && email.indexOf('@') == -1)    		throw new UserDoesntFullfillEndEntityProfile("Invalid email address. There must have '@' in address.");    	    	String emaildomain = email.substring(email.indexOf('@') + 1);    	    	    	        if(!getUse(field,number) && !email.trim().equals(""))          throw new UserDoesntFullfillEndEntityProfile(text + " cannot be used in end entity profile.");              if(!isModifyable(field,number)){          String[] values;          try{            values = getValue(field, number).split(SPLITCHAR);          }catch(Exception e){            throw new UserDoesntFullfillEndEntityProfile("Error parsing end entity profile.");          }          boolean exists = false;          for(int i = 0; i < values.length ; i++){            if(emaildomain.equals(values[i].trim()))              exists = true;          }          if(!exists)            throw new UserDoesntFullfillEndEntityProfile("Field " + text + " data didn't match requirement of end entity profile.");        }    }            private void checkIfDataFullfillProfile(int field, int number, String data, String text, String email) throws UserDoesntFullfillEndEntityProfile {    	if(data == null && field != EMAIL)    		throw new UserDoesntFullfillEndEntityProfile("Field " +  text + " cannot be null.");    	if(data !=null)    		if(!getUse(field,number) && !data.trim().equals(""))    			throw new UserDoesntFullfillEndEntityProfile(text + " cannot be used in end entity profile.");    	if(field == OLDDNE || field == RFC822NAME){    		if(isRequired(field,number)){    			if(!data.trim().equals(email.trim()))    				throw new UserDoesntFullfillEndEntityProfile("Field " + text + " data didn't match Email field.");    		}    	}    	else{    		if(!isModifyable(field,number)){    			String[] values;    			try{    				values = getValue(field, number).split(SPLITCHAR);    			}catch(Exception e){    				throw new UserDoesntFullfillEndEntityProfile("Error parsing end entity profile.");    			}    			boolean exists = false;    			for(int i = 0; i < values.length ; i++){    				if(data.equals(values[i].trim()))    					exists = true;    			}    			if(!exists)    				throw new UserDoesntFullfillEndEntityProfile("Field " + text + " data didn't match requirement of end entity profile.");    		}    	}    }    private void checkIfAllRequiredFieldsExists(DNFieldExtractor subjectdnfields, DNFieldExtractor subjectaltnames, String username, String email)  throws UserDoesntFullfillEndEntityProfile{        int size;        // Check if Username exists.        if(isRequired(USERNAME,0)){          if(username == null || username.trim().equals(""))            throw new UserDoesntFullfillEndEntityProfile("Username cannot be empty or null.");        }        // Check if required Email fields exists.        if(isRequired(EMAIL,0)){          if(email == null || email.trim().equals(""))            throw new UserDoesntFullfillEndEntityProfile("Email address cannot be empty or null.");        }        // Check if all required subjectdn fields exists.        for(int i = 0; i < SUBJECTDNFIELDS.length; i++){          size = getNumberOfField(SUBJECTDNFIELDS[i]);          for(int j = 0; j < size; j++){            if(isRequired(SUBJECTDNFIELDS[i],j))              if(subjectdnfields.getField(SUBJECTDNFIELDEXTRACTORNAMES[i],j).trim().equals(""))                throw new UserDoesntFullfillEndEntityProfile("Subject DN field '" + SUBJECTDNFIELDNAMES[i] + "' must exist.");          }        }         // Check if all required subject alternate name fields exists.        for(int i = 0; i < SUBJECTALTNAMEFIELDS.length; i++){          size = getNumberOfField(SUBJECTALTNAMEFIELDS[i]);          for(int j = 0; j < size; j++){            if(isRequired(SUBJECTALTNAMEFIELDS[i],j))              if(subjectaltnames.getField(SUBJECTALTNAMEFIELDEXTRACTORNAMES[i],j).trim().equals(""))                throw new UserDoesntFullfillEndEntityProfile("Subject Alterntive Name field '" + SUBJECTALTNAMEFIELDNAMES[i] + "' must exist.");          }        }    }    private void  checkIfForIllegalNumberOfFields(DNFieldExtractor subjectdnfields, DNFieldExtractor subjectaltnames) throws UserDoesntFullfillEndEntityProfile{        // Check number of subjectdn fields.        for(int i = 0; i < SUBJECTDNFIELDS.length; i++){            if(getNumberOfField(SUBJECTDNFIELDS[i]) < subjectdnfields.getNumberOfFields(SUBJECTDNFIELDEXTRACTORNAMES[i]))              throw new UserDoesntFullfillEndEntityProfile("Wrong number of " + SUBJECTDNFIELDNAMES[i] + " fields in Subject DN.");        }         // Check number of subject alternate name fields.        for(int i = 0; i < SUBJECTALTNAMEFIELDS.length; i++){          if(getNumberOfField(SUBJECTALTNAMEFIELDS[i]) < subjectaltnames.getNumberOfFields(SUBJECTALTNAMEFIELDEXTRACTORNAMES[i]))           throw new UserDoesntFullfillEndEntityProfile("Wrong number of " + SUBJECTALTNAMEFIELDNAMES[i] + " fields in Subject Alternative Name.");        }    }    private void  incrementFieldnumber(int parameter){      ArrayList numberarray = (ArrayList) data.get(NUMBERARRAY);      numberarray.set(parameter, new Integer(((Integer) numberarray.get(parameter)).intValue() + 1));    }    private void  decrementFieldnumber(int parameter){      ArrayList numberarray = (ArrayList) data.get(NUMBERARRAY);      numberarray.set(parameter, new Integer(((Integer) numberarray.get(parameter)).intValue() - 1));    }            // Private Constants.    private static final int FIELDBOUNDRARY  = 10000;    private static final int NUMBERBOUNDRARY = 100;    private static final int[] SUBJECTDNFIELDS              = {OLDDNE, UID, COMMONNAME, SN, GIVENNAME, INITIALS, SURNAME, TITLE, ORGANIZATIONUNIT, ORGANIZATION, LOCALE, STATE, DOMAINCOMPONENT, COUNTRY, UNSTRUCTUREDADDRESS, UNSTRUCTUREDNAME};    private static final int[] SUBJECTDNFIELDEXTRACTORNAMES = { DNFieldExtractor.E,DNFieldExtractor.UID, DNFieldExtractor.CN, DNFieldExtractor.SN,                                                               DNFieldExtractor.GIVENNAME,DNFieldExtractor.INITIALS,DNFieldExtractor.SURNAME, DNFieldExtractor.T,                                                               DNFieldExtractor.OU, DNFieldExtractor.O, DNFieldExtractor.L,                                                               DNFieldExtractor.ST, DNFieldExtractor.DC, DNFieldExtractor.C,															   DNFieldExtractor.UNSTRUCTUREDADDRESS, DNFieldExtractor.UNSTRUCTUREDNAME};    private static final String[] SUBJECTDNFIELDNAMES       = {"Email Address (E)", "UID","CommonName (CN)", "SerialNumber (SN)", "GivenName (GivenName)",                                                               "Initials (Initials)", "SurName (SurName)", "Title (T)", "OrganizationUnit (OU)", "Organization (O)",                                                               "Location (L)", "State (ST)", "DomainComponent (DC)", "Country (C)", "Unstructured Address (IP)", "Unstructured Name (fqdn)"};    private static final int[] SUBJECTALTNAMEFIELDS              = {DNSNAME,IPADDRESS, OTHERNAME, UNIFORMRESOURCEID, X400ADDRESS, DIRECTORYNAME, EDIPARTNAME, REGISTEREDID, RFC822NAME, UPN , GUID};    private static final int[] SUBJECTALTNAMEFIELDEXTRACTORNAMES = {DNFieldExtractor.DNSNAME,DNFieldExtractor.IPADDRESS, DNFieldExtractor.OTHERNAME,                                                                    DNFieldExtractor.URI, DNFieldExtractor.X400ADDRESS, DNFieldExtractor.DIRECTORYNAME,                                                                    DNFieldExtractor.EDIPARTNAME, DNFieldExtractor.REGISTEREDID, DNFieldExtractor.RFC822NAME, DNFieldExtractor.UPN, DNFieldExtractor.GUID};    private static final String[] SUBJECTALTNAMEFIELDNAMES       = {"DNSName", "IPAddress", "OtherName", "UniformResourceId (uri)", "X400Address", "DirectoryName",                                                                    "EDIPartName","RegisteredId","RFC822Name", "UPN", "Globally Unique Id"};    // Used to map constants of DNFieldExtractor to end entity profile constants.    private static final int[] DNEXTRATORTOPROFILEMAPPER      = {OLDDNE, UID, COMMONNAME, SN, GIVENNAME, INITIALS, SURNAME,                                                                 TITLE, ORGANIZATIONUNIT, ORGANIZATION, LOCALE,                                                                 STATE, DOMAINCOMPONENT, COUNTRY, UNSTRUCTUREDADDRESS, UNSTRUCTUREDNAME, OTHERNAME, RFC822NAME, DNSNAME,                                                                 IPADDRESS, X400ADDRESS, DIRECTORYNAME, EDIPARTNAME, UNIFORMRESOURCEID, REGISTEREDID, UPN, GUID};    private static final String[] DNEXTRATORTOPROFILEMAPPERTEXTS = {"Email Address (E)", "UID", "CommonName (CN)", "SerialNumber (SN)",                                                                    "GivenName (GivenName)", "Initials (Initials)", "SurName (SurName)",                                                                    "Title (T)", "OrganizationUnit (OU)", "Organization (O)", "Location (L)",                                                                    "State (ST)", "DomainComponent (DC)", "Country (C)", "Unstructured Address (IP)", 																	"Unstructured Name (fqdn)","OtherName", "RFC822Name", "DNSName",                                                                    "IPAddress", "X400Address", "DirectoryName", "EDIPartName", "UniformResourceId (uri)", "RegisteredId", "UPN", 																	"Globally Unique Id"};    private static final int[] PROFILEIDTOUSERIDMAPPER        = {0,0,0, DNFieldExtractor.E, DNFieldExtractor.UID, DNFieldExtractor.CN, DNFieldExtractor.SN,                                                                        DNFieldExtractor.GIVENNAME,DNFieldExtractor.INITIALS, DNFieldExtractor.SURNAME,                                                                        DNFieldExtractor.T, DNFieldExtractor.OU, DNFieldExtractor.O,                                                                        DNFieldExtractor.L ,DNFieldExtractor.ST,DNFieldExtractor.DC,                                                                        DNFieldExtractor.C ,DNFieldExtractor.RFC822NAME ,DNFieldExtractor.DNSNAME,                                                                        DNFieldExtractor.IPADDRESS ,DNFieldExtractor.OTHERNAME ,DNFieldExtractor.URI, DNFieldExtractor.X400ADDRESS,                                                                        DNFieldExtractor.DIRECTORYNAME ,DNFieldExtractor.EDIPARTNAME ,DNFieldExtractor.REGISTEREDID,0,0,0,0,0,0,0,0,0,0,DNFieldExtractor.UPN,0,0,DNFieldExtractor.UNSTRUCTUREDADDRESS,DNFieldExtractor.UNSTRUCTUREDNAME, DNFieldExtractor.GUID};    private static final String NUMBERARRAY               = "NUMBERARRAY";    private static final String SUBJECTDNFIELDORDER       = "SUBJECTDNFIELDORDER";    private static final String SUBJECTALTNAMEFIELDORDER  = "SUBJECTALTNAMEFIELDORDER";        private static final String NOTIFICATIONSENDER     = "NOTIFICATIONSENDER";    private static final String NOTIFICATIONSUBJECT    = "NOTIFICATIONSSUBJECT";    private static final String NOTIFICATIONMESSAGE   = "NOTIFICATIONSMESSAGE";    // Private fields.}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -