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

📄 endentityprofile.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *      */    private void checkIfGenderFullfillProfile(String field, int number, String gender, String text) throws UserDoesntFullfillEndEntityProfile {    	    	    	if(!gender.trim().equals("") && !(gender.equalsIgnoreCase("m") || gender.equalsIgnoreCase("f")))    		throw new UserDoesntFullfillEndEntityProfile("Invalid " + text + ". Must be M or F.");    	        if(!getUse(field,number) && !gender.trim().equals(""))          throw new UserDoesntFullfillEndEntityProfile(text + " cannot be used in end entity profile.");              if(!isModifyable(field,number) && !gender.trim().equals("")){          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(gender.equals(values[i].trim()))              exists = true;          }          if(!exists)            throw new UserDoesntFullfillEndEntityProfile("Field " + text + " data didn't match requirement of end entity profile.");        }    }    /**     * Used for date strings, should be YYYYMMDD     *      */    private void checkIfDateFullfillProfile(String field, int number, String date, String text) throws UserDoesntFullfillEndEntityProfile {    	    	    	if(!date.trim().equals("") && date.trim().length() != 8)    		throw new UserDoesntFullfillEndEntityProfile("Invalid " + text + ". Must be of length eight.");    	if(!date.trim().equals("") && !StringUtils.isNumeric(date.trim()))    		throw new UserDoesntFullfillEndEntityProfile("Invalid " + text + ". Must be only numbers.");    	        if(!getUse(field,number) && !date.trim().equals(""))          throw new UserDoesntFullfillEndEntityProfile(text + " cannot be used in end entity profile.");              if(!isModifyable(field,number) && !date.trim().equals("")){          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(date.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(String field, int number, String data, String text, String email) throws UserDoesntFullfillEndEntityProfile {    	if(data == null && !field.equals(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.equals(DnComponents.DNEMAIL) || field.equals(DnComponents.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, DNFieldExtractor subjectdirattrs, 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.        String[] dnfields = getSubjectDNProfileFields();        Integer[] dnFieldExtractorIds = (Integer[])DnComponents.getDnDnIds().toArray(new Integer[0]);        for(int i = 0; i < dnfields.length; i++){        	if(getReverseFieldChecks()){        		int nof = subjectdnfields.getNumberOfFields(dnFieldExtractorIds[i].intValue());        	    int numRequiredFields = getNumberOfRequiredFields(dnfields[i]);        	    if(nof < numRequiredFields){        	      throw new UserDoesntFullfillEndEntityProfile("Subject DN field '" + dnfields[i] + "' must exist.");        	    }        	}else{               size = getNumberOfField(dnfields[i]);               for(int j = 0; j < size; j++){               if(isRequired(dnfields[i],j))                 if(subjectdnfields.getField(dnFieldExtractorIds[i].intValue(),j).trim().equals(""))                  throw new UserDoesntFullfillEndEntityProfile("Subject DN field '" + dnfields[i] + "' must exist.");               }            }        }                         // Check if all required subject alternate name fields exists.        String[] altnamefields = getSubjectAltnameProfileFields();        Integer[] altNameFieldExtractorIds = (Integer[])DnComponents.getAltNameDnIds().toArray(new Integer[0]);        for(int i = 0; i < altnamefields.length; i++){        	if(getReverseFieldChecks()){        		int nof = subjectaltnames.getNumberOfFields(altNameFieldExtractorIds[i].intValue());        		int numRequiredFields = getNumberOfRequiredFields(altnamefields[i]);        		if(nof < numRequiredFields){        			throw new UserDoesntFullfillEndEntityProfile("Subject Alternative Name field '" + altnamefields[i] + "' must exist.");        		}        	}else{        		size = getNumberOfField(altnamefields[i]);        		for(int j = 0; j < size; j++){        			if(isRequired(altnamefields[i],j))        				if(subjectaltnames.getField(altNameFieldExtractorIds[i].intValue(),j).trim().equals(""))        					throw new UserDoesntFullfillEndEntityProfile("Subject Alterntive Name field '" + altnamefields[i] + "' must exist.");        		}        	}        }        // Check if all required subject directory attribute fields exists.        String[] dirattrfields = getSubjectDirAttrProfileFields();        Integer[] dirAttrFieldExtractorIds = (Integer[])DnComponents.getDirAttrDnIds().toArray(new Integer[0]);        for(int i = 0; i < dirattrfields.length; i++){        	        	size = getNumberOfField(dirattrfields[i]);        	for(int j = 0; j < size; j++){        		if(isRequired(dirattrfields[i],j))        			if(subjectdirattrs.getField(dirAttrFieldExtractorIds[i].intValue(),j).trim().equals(""))        				throw new UserDoesntFullfillEndEntityProfile("Subject Directory Attribute field '" + dirattrfields[i] + "' must exist.");        	}        }    }  /**   * Method calculating the number of required fields of on kind that is configured for this profile.   * @param field, one of the field constants   * @return The number of required fields of that kind.   */    private int getNumberOfRequiredFields(String field) {    	int retval = 0;    	int size = getNumberOfField(field);    	for(int j = 0; j < size; j++){    		if(isRequired(field,j)){    			retval++;    		}    	}   	    	    	return retval;    }	private void  checkIfForIllegalNumberOfFields(DNFieldExtractor subjectdnfields, DNFieldExtractor subjectaltnames, DNFieldExtractor subjectdirattrs) throws UserDoesntFullfillEndEntityProfile{        // Check number of subjectdn fields.        String[] dnfields = getSubjectDNProfileFields();        Integer[] dnFieldExtractorIds = (Integer[])DnComponents.getDnDnIds().toArray(new Integer[0]);        for(int i = 0; i < dnfields.length; i++){            if(getNumberOfField(dnfields[i]) < subjectdnfields.getNumberOfFields(dnFieldExtractorIds[i].intValue()))              throw new UserDoesntFullfillEndEntityProfile("Wrong number of " + dnfields[i] + " fields in Subject DN.");        }         // Check number of subject alternate name fields.        String[] altnamefields = getSubjectAltnameProfileFields();        Integer[] altNameFieldExtractorIds = (Integer[])DnComponents.getAltNameDnIds().toArray(new Integer[0]);        for(int i = 0; i < altnamefields.length; i++){          if(getNumberOfField(altnamefields[i]) < subjectaltnames.getNumberOfFields(altNameFieldExtractorIds[i].intValue()))           throw new UserDoesntFullfillEndEntityProfile("Wrong number of " + altnamefields[i] + " fields in Subject Alternative Name.");        }        // Check number of subject directory attribute fields.        String[] dirattrfields = getSubjectDirAttrProfileFields();        Integer[] dirAttrFieldExtractorIds = (Integer[])DnComponents.getDirAttrDnIds().toArray(new Integer[0]);        for(int i = 0; i < dirattrfields.length; i++){          if(getNumberOfField(dirattrfields[i]) < subjectdirattrs.getNumberOfFields(dirAttrFieldExtractorIds[i].intValue()))           throw new UserDoesntFullfillEndEntityProfile("Wrong number of " + dirattrfields[i] + " fields in Subject Directory Attributes.");        }    }	/** methods for mapping the DN, AltName, DirAttr constants from string->number	 * 	 */	private static int getParameterNumber(String parameter) {		Integer number = (Integer)dataConstants.get(parameter);		if (number != null) {			return number.intValue();					}		log.error("No parameter number for "+parameter);		return -1;	}	/** methods for mapping the DN, AltName, DirAttr constants from number->string	 * 	 */	private static String getParameter(int parameterNumber) {		Set set = dataConstants.entrySet();		Iterator iter = set.iterator();		String ret = null;		while (iter.hasNext() && ret == null) {			Map.Entry entry = (Map.Entry)iter.next();			Integer val = (Integer)entry.getValue();			if (val.intValue() == parameterNumber) {				ret = (String)entry.getKey();			}		}		if (ret == null) {			log.error("No parameter for "+parameterNumber);					}		return ret;	}	    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;        public static String[] getSubjectDNProfileFields() {    	return (String[])DnComponents.getDnProfileFields().toArray(new String[0]);    }    public static String[] getSubjectAltnameProfileFields() {    	return (String[])DnComponents.getAltNameFields().toArray(new String[0]);    }    public static String[] getSubjectDirAttrProfileFields() {    	return (String[])DnComponents.getDirAttrFields().toArray(new String[0]);    }    private static final String NUMBERARRAY               = "NUMBERARRAY";    private static final String SUBJECTDNFIELDORDER       = "SUBJECTDNFIELDORDER";    private static final String SUBJECTALTNAMEFIELDORDER  = "SUBJECTALTNAMEFIELDORDER";    private static final String SUBJECTDIRATTRFIELDORDER  = "SUBJECTDIRATTRFIELDORDER";        private static final String NOTIFICATIONSENDER     = "NOTIFICATIONSENDER";    private static final String NOTIFICATIONSUBJECT    = "NOTIFICATIONSSUBJECT";    private static final String NOTIFICATIONMESSAGE   = "NOTIFICATIONSMESSAGE";    private static final String REUSECERTIFICATE = "REUSECERTIFICATE";    private static final String REVERSEFFIELDCHECKS = "REVERSEFFIELDCHECKS";         private static final String PRINTINGUSE            = "PRINTINGUSE";    private static final String PRINTINGDEFAULT        = "PRINTINGDEFAULT";    private static final String PRINTINGREQUIRED       = "PRINTINGREQUIRED";    private static final String PRINTINGCOPIES         = "PRINTINGCOPIES";    private static final String PRINTINGPRINTERNAME    = "PRINTINGPRINTERNAME";    private static final String PRINTINGSVGFILENAME    = "PRINTINGSVGFILENAME";    private static final String PRINTINGSVGDATA        = "PRINTINGSVGDATA";    // Private fields.}

⌨️ 快捷键说明

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