crmfmessagehandler.java

来自「一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考」· Java 代码 · 共 402 行 · 第 1/2 页

JAVA
402
字号
							String pbeMacAlg = verifyer.getMacOid();							int pbeIterationCount = verifyer.getIterationCount();							if (ret) {								// If authentication was correct, we will now create a username and password and register the new user in EJBCA								UsernameGenerator gen = UsernameGenerator.getInstance(usernameGeneratorParams);								String dn = crmfreq.getSubjectDN();								log.debug("Creating username from base dn: "+dn);								String username = gen.generateUsername(dn);								IPasswordGenerator pwdgen = PasswordGeneratorFactory.getInstance(PasswordGeneratorFactory.PASSWORDTYPE_ALLPRINTABLE);								String pwd = pwdgen.getNewPassword(12, 12);								// AltNames may be in the request template								String altNames = crmfreq.getRequestAltNames();								boolean addedUser = false; // flag indicating if adding was succesful								String failText = null;								FailInfo failInfo = null;								try {									UserDataVO user = null;									try {										user = usersession.findUser(admin, username);									} catch (FinderException e) {										// User can not be found, leave user as null									}									if (user == null) {										try {											log.debug("Creating new user.");											usersession.addUser(admin, username, pwd, dn, altNames, null, false, eeProfileId, certProfileId, SecConst.USER_ENDUSER, SecConst.TOKEN_SOFT_BROWSERGEN, 0, caId);																															} catch (DuplicateKeyException e) {											// This was veery strange, we didn't find it before, but now it exists?											String errMsg = intres.getLocalizedMessage("cmp.erroradduserupdate", username);											log.error(errMsg);											// If the user already exists, we will change him instead and go for that											usersession.changeUser(admin, username, pwd, dn, altNames, null, false, eeProfileId, certProfileId, SecConst.USER_ENDUSER, SecConst.TOKEN_SOFT_BROWSERGEN, 0, UserDataConstants.STATUS_NEW, caId);																				}									} else {										// If the user already exists, we will change him instead and go for that										log.debug("User already exists, so we will update instead.");										usersession.changeUser(admin, username, pwd, dn, altNames, null, false, eeProfileId, certProfileId, SecConst.USER_ENDUSER, SecConst.TOKEN_SOFT_BROWSERGEN, 0, UserDataConstants.STATUS_NEW, caId);																			}									addedUser = true;								} catch (UserDoesntFullfillEndEntityProfile e) {									String errMsg = intres.getLocalizedMessage("cmp.erroradduser", username);									log.error(errMsg, e);									failText = e.getMessage();								} catch (ApprovalException e) {									String errMsg = intres.getLocalizedMessage("cmp.erroradduser", username);									log.error(errMsg, e);									failText = e.getMessage();									failInfo = FailInfo.NOT_AUTHORIZED;								} catch (WaitingForApprovalException e) {									String errMsg = intres.getLocalizedMessage("cmp.erroradduser", username);									log.error(errMsg, e);									failText = e.getMessage();									failInfo = FailInfo.NOT_AUTHORIZED;								}								if (!addedUser) {									CmpErrorResponseMessage cresp = new CmpErrorResponseMessage();									cresp.setRecipientNonce(msg.getSenderNonce());									cresp.setSenderNonce(new String(Base64.encode(CmpMessageHelper.createSenderNonce())));									cresp.setSender(msg.getRecipient());									cresp.setRecipient(msg.getSender());									cresp.setTransactionId(msg.getTransactionId());									cresp.setFailText(failText);									cresp.setFailInfo(failInfo);									cresp.setRequestId(requestId);									cresp.setRequestType(requestType);																		// Set all protection parameters									log.debug(responseProtection+", "+pbeDigestAlg+", "+pbeMacAlg+", "+keyId+", "+raAuthenticationSecret);									if (StringUtils.equals(responseProtection, "pbe") && (pbeDigestAlg != null) && (pbeMacAlg != null) && (keyId != null) && (raAuthenticationSecret != null) ) {										cresp.setPbeParameters(keyId, raAuthenticationSecret, pbeDigestAlg, pbeMacAlg, pbeIterationCount);									}									resp = cresp;									try {										resp.create();									} catch (InvalidKeyException e1) {										String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");										log.error(errMsg, e1);									} catch (NoSuchAlgorithmException e1) {										String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");										log.error(errMsg, e1);									} catch (NoSuchProviderException e1) {										String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");										log.error(errMsg, e1);									} catch (SignRequestException e1) {										String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");										log.error(errMsg, e1);									} catch (NotFoundException e1) {										String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");										log.error(errMsg, e1);									} catch (IOException e1) {										String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");										log.error(errMsg, e1);									}																								}								crmfreq.setUsername(username);								crmfreq.setPassword(pwd);								// Set all protection parameters								if (StringUtils.equals(responseProtection, "pbe")) {									crmfreq.setPbeParameters(keyId, raAuthenticationSecret, pbeDigestAlg, pbeMacAlg, pbeIterationCount);								}								// Now we are all set to go ahead and generate a certificate for the poor bastard							} else {								String errMsg = intres.getLocalizedMessage("cmp.errorauthmessage");								log.error(errMsg);								if (verifyer.getErrMsg() != null) {									errMsg = verifyer.getErrMsg();								}								resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, errMsg);					        								}						} catch (NoSuchAlgorithmException e) {							String errMsg = intres.getLocalizedMessage("cmp.errorcalcprotection");							log.error(errMsg, e);							resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, e.getMessage());						} catch (NoSuchProviderException e) {							String errMsg = intres.getLocalizedMessage("cmp.errorcalcprotection");							log.error(errMsg, e);							resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, e.getMessage());						} catch (InvalidKeyException e) {							String errMsg = intres.getLocalizedMessage("cmp.errorcalcprotection");							log.error(errMsg, e);							resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, e.getMessage());						}					} else {						String errMsg = intres.getLocalizedMessage("cmp.errorunauthmessagera");						log.error(errMsg);						resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, errMsg);					}				} else {					// Try to find the user that is the subject for the request					// if extractUsernameComponent is null, we have to find the user from the DN					// if not empty the message will find the username itself, in the getUsername method					if (StringUtils.isEmpty(extractUsernameComponent)) {						String dn = crmfreq.getSubjectDN();						log.debug("looking for user with dn: "+dn);						UserDataVO data = usersession.findUserBySubjectDN(admin, dn);						if (data != null) {							log.debug("Found username: "+data.getUsername());							crmfreq.setUsername(data.getUsername());						} else {							String errMsg = intres.getLocalizedMessage("cmp.infonouserfordn");							log.info(errMsg);						}					}				}			} else {				String errMsg = intres.getLocalizedMessage("cmp.errornocmrfreq");				log.error(errMsg);			}			// This is a request message, so we want to enroll for a certificate, if we have not created an error already			if (resp == null) {				// Get the certificate				resp = signsession.createCertificate(admin, crmfreq, -1,						Class.forName("org.ejbca.core.protocol.cmp.CmpResponseMessage"));							}			if (resp == null) {				String errMsg = intres.getLocalizedMessage("cmp.errornullresp");				log.error(errMsg);			}		} catch (AuthorizationDeniedException e) {			String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");			log.error(errMsg, e);					} catch (NotFoundException e) {			String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");			log.error(errMsg, e);						resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_REQUEST, e.getMessage());		} catch (AuthStatusException e) {			String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");			log.error(errMsg, e);						resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_REQUEST, e.getMessage());		} catch (AuthLoginException e) {			String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");			log.error(errMsg, e);						resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_REQUEST, e.getMessage());		} catch (IllegalKeyException e) {			String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");			log.error(errMsg, e);					} catch (CADoesntExistsException e) {			String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");			log.error(errMsg, e);						resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.WRONG_AUTHORITY, e.getMessage());		} catch (SignRequestException e) {			String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");			log.error(errMsg, e);					} catch (SignRequestSignatureException e) {			String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");			log.error(errMsg, e);						resp = CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_POP, e.getMessage());		} catch (ClassNotFoundException e) {			String errMsg = intres.getLocalizedMessage("cmp.errorgeneral");			log.error(errMsg, e);					} catch (RemoteException e) {			// Fatal error			String errMsg = intres.getLocalizedMessage("cmp.erroradduser");			log.error(errMsg, e);						resp = null;		}									return resp;	}	}

⌨️ 快捷键说明

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