List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:ca.uhn.hl7v2.testpanel.model.conn.AbstractConnection.java
/** * TODO: rename//from www . j a va2s . com */ public KeyStore getHohSignatureKeystore_() throws KeyStoreException { if (isBlank(getHohSignatureKeystore())) { return null; } if (myHohSignatureKeystore_ != null) { return myHohSignatureKeystore_; } File jksFile = new File(getHohSignatureKeystore()); if (!jksFile.exists() || !jksFile.canRead()) { throw new KeyStoreException("File does not exist or can not be read: " + jksFile.getAbsolutePath()); } char[] password = null; if (isNotBlank(myHohSignatureKeystorePassword)) { password = myHohSignatureKeystorePassword.toCharArray(); } KeyStore keystore; try { keystore = KeystoreUtils.loadKeystore(jksFile, password); } catch (NoSuchAlgorithmException e) { ourLog.error("Failed to load keystore!", e); throw new KeyStoreException("Failed to load keystore: " + e.getMessage()); } catch (CertificateException e) { ourLog.error("Failed to load keystore!", e); throw new KeyStoreException("Failed to load keystore: " + e.getMessage()); } catch (IOException e) { ourLog.error("Failed to load keystore!", e); if (e.getCause() instanceof UnrecoverableKeyException) { throw new KeyStoreException("Keystore password appears to be incorrect"); } throw new KeyStoreException("Failed to load keystore: " + e.getMessage()); } if (this instanceof InboundConnection) { if (!KeystoreUtils.validateKeystoreForSignatureVerifying(keystore)) { throw new KeyStoreException("Keystore contains no keys appropriate for receiving data"); } } else if (this instanceof OutboundConnection) { if (!KeystoreUtils.validateKeystoreForSignatureSigning(keystore)) { throw new KeyStoreException("Keystore contains no keys appropriate for receiving data"); } } myHohSignatureKeystore_ = keystore; return myHohSignatureKeystore_; }
From source file:de.rrze.idmone.utils.jpwgen.PwGenerator.java
/** * This method parses the command line options, initializes the needed * objects and generates the required number of passwords by calling * <em>generatePassword()</em>. When not used as a stand-alone program this * method is to be preferred instead of the main(String[]). * // w w w . ja v a 2s. c o m * @param args * the arguments used to initialize the generation process * @return a list of passwords or <em>null</em> if no suitable passwords * could be generated. */ public static synchronized List<String> process(String[] args) { int passwordFlags = initDefaultFlags(); // The length of the password to be generated int passwordLength = DEFAULT_PASSWORD_LENGTH; int numberOfPasswords = DEFAULT_NUMBER_OF_PASSWORDS; int maxAttempts = DEFAULT_MAX_ATTEMPTS; log(Messages.getString("PwGenerator.PASSWORD_GENERATOR"), //$NON-NLS-1$ false); ArrayList<String> passwords = new ArrayList<String>(); BasicParser parser = new BasicParser(); try { CommandLine commandLine = parser.parse(options, args); parser.parse(options, args); if (commandLine.hasOption(CL_HELP)) { printUsage(); log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$ false); return passwords; } parser.parse(options, args); if (commandLine.hasOption(CL_SR_PROVIDERS)) { Set<String> serviceProviders = RandomFactory.getInstance() .getServiceProviderFor(IRandomFactory.TYPE_SECURE_RANDOM); log(Messages.getString("PwGenerator.SERVICES_PROVIDERS_FOR") //$NON-NLS-1$ + IRandomFactory.TYPE_SECURE_RANDOM + Messages.getString("PwGenerator.NEW_LINE"), false); //$NON-NLS-1$ for (Iterator<String> iter = serviceProviders.iterator(); iter.hasNext();) { String element = (String) iter.next(); log(Messages.getString("PwGenerator.SERVICE_PROVIDERS") + element //$NON-NLS-1$ + Messages.getString("PwGenerator.NEW_LINE"), false); //$NON-NLS-1$ log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$ false); return passwords; } } parser.parse(options, args); if (commandLine.hasOption(CL_PROVIDERS)) { log(Messages.getString("PwGenerator.ALL_SEC_PROVIDERS") //$NON-NLS-1$ + IRandomFactory.TYPE_SECURE_RANDOM + Messages.getString("PwGenerator.NEW_LINE"), false); //$NON-NLS-1$ Provider[] serviceProviders = RandomFactory.getInstance().getProviders(); for (int i = 0; i < serviceProviders.length; i++) { log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$ false); log(Messages.getString("PwGenerator.PROVIDER") + serviceProviders[i].getName() //$NON-NLS-1$ + Messages.getString("PwGenerator.NEW_LINE"), //$NON-NLS-1$ false); Set<Provider.Service> services = serviceProviders[i].getServices(); log(Messages.getString("PwGenerator.SERVICES") + Messages.getString("PwGenerator.NEW_LINE"), //$NON-NLS-1$//$NON-NLS-2$ false); log(services.toString(), false); log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$ false); } log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$ false); return passwords; } if (commandLine.hasOption(CL_NUMBER_PASSWORD)) { String sNumberOfPasswords = commandLine.getOptionValue(CL_NUMBER_PASSWORD); if (sNumberOfPasswords != null) numberOfPasswords = Integer.parseInt(sNumberOfPasswords); log(Messages.getString("PwGenerator.NUM_PASSWORDS") + numberOfPasswords, false); //$NON-NLS-1$ } commandLine = parser.parse(options, args); if (commandLine.hasOption(CL_PASSWORD_LENGTH)) { String sPasswordLength = commandLine.getOptionValue(CL_PASSWORD_LENGTH); if (sPasswordLength != null) passwordLength = Integer.parseInt(sPasswordLength); log(Messages.getString("PwGenerator.PASSWORD_LENGTH") + passwordLength, false); //$NON-NLS-1$ } parser.parse(options, args); if (commandLine.hasOption(CL_COLUMN)) { doColumns = true; log(Messages.getString("PwGenerator.COLUMNS_ENABLED"), false); //$NON-NLS-1$ } parser.parse(options, args); if (commandLine.hasOption(CL_TERM_WIDTH)) { String sTermWidth = commandLine.getOptionValue(CL_TERM_WIDTH); if (sTermWidth != null) termWidth = Integer.parseInt(sTermWidth); log(Messages.getString("PwGenerator.TERMINAL_LENGTH") + termWidth, false); //$NON-NLS-1$ } Random random = null; parser.parse(options, args); if (commandLine.hasOption(CL_RANDOM)) { random = RandomFactory.getInstance().getRandom(); log(Messages.getString("PwGenerator.NORMAL_RANDOM"), false); //$NON-NLS-1$ } else { try { random = RandomFactory.getInstance().getSecureRandom(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); random = RandomFactory.getInstance().getRandom(); } catch (NoSuchProviderException e) { e.printStackTrace(); random = RandomFactory.getInstance().getRandom(); } } parser.parse(options, args); if (commandLine.hasOption(CL_SR_ALGORITHM)) { String[] data = commandLine.getOptionValues(CL_SR_ALGORITHM); if (data.length == 2) { try { random = RandomFactory.getInstance().getSecureRandom(data[0], data[1]); log(Messages.getString("PwGenerator.SEC_ALG") + data[0] //$NON-NLS-1$ + Messages.getString("PwGenerator.PROV") + data[1] //$NON-NLS-1$ + Messages.getString("PwGenerator.DOR"), false); //$NON-NLS-1$ } catch (NoSuchAlgorithmException e) { log(Messages.getString("PwGenerator.ERROR") + e.getMessage() //$NON-NLS-1$ + Messages.getString("PwGenerator.NEW_LINE"), true); //$NON-NLS-1$ log(Messages.getString("PwGenerator.DEFAUL_RANDOM"), true); //$NON-NLS-1$ } catch (NoSuchProviderException e) { log(Messages.getString("PwGenerator.ERROR") + e.getMessage() //$NON-NLS-1$ + Messages.getString("PwGenerator.NEW_LINE"), true); //$NON-NLS-1$ log(Messages.getString("PwGenerator.DEFAUL_RANDOM"), true); //$NON-NLS-1$ } } } if (commandLine.hasOption(CL_NUMERALS)) { passwordFlags |= PW_DIGITS; log(Messages.getString("PwGenerator.DIGITS_ON"), false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_NO_NUMERALS)) { passwordFlags &= ~PW_DIGITS; log(Messages.getString("PwGenerator.DIGITS_OFF"), false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_CAPITALIZE)) { passwordFlags |= PW_UPPERS; log(Messages.getString("PwGenerator.UPPERCASE_ON"), false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_NO_CAPITALIZE)) { passwordFlags &= ~PW_UPPERS; log(Messages.getString("PwGenerator.UPPERCASE_OFF"), false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_AMBIGOUS)) { passwordFlags |= PW_AMBIGUOUS; log(Messages.getString("PwGenerator.AMBIGOUS_ON"), false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_NO_AMBIGOUS)) { passwordFlags &= ~PW_AMBIGUOUS; log(Messages.getString("PwGenerator.AMBIGOUS_OFF"), false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_SYMBOLS)) { passwordFlags |= PW_SYMBOLS; log(Messages.getString("PwGenerator.SYMBOLS_ON"), false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_SYMBOLS_REDUCED)) { passwordFlags |= PW_SYMBOLS_REDUCED; log(Messages.getString("PwGenerator.SYMBOLS_REDUCED_ON"), false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_NO_SYMBOLS)) { passwordFlags &= ~PW_SYMBOLS; passwordFlags &= ~PW_SYMBOLS_REDUCED; log(Messages.getString("PwGenerator.SYMBOLS_OFF"), false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_MAX_ATTEMPTS)) { String sMaxAttempts = commandLine.getOptionValue(CL_MAX_ATTEMPTS); if (sMaxAttempts != null) maxAttempts = Integer.parseInt(sMaxAttempts); log(Messages.getString("PwGenerator.MAX_ATTEMPTS") + maxAttempts, false); //$NON-NLS-1$ } if (commandLine.hasOption(CL_REGEX_STARTS_NO_SMALL_LETTER)) passwordFlags |= REGEX_STARTS_NO_SMALL_LETTER_FLAG; if (commandLine.hasOption(CL_REGEX_ENDS_NO_SMALL_LETTER)) passwordFlags |= REGEX_STARTS_NO_SMALL_LETTER_FLAG; if (commandLine.hasOption(CL_REGEX_STARTS_NO_UPPER_LETTER)) passwordFlags |= REGEX_STARTS_NO_UPPER_LETTER_FLAG; if (commandLine.hasOption(CL_REGEX_ENDS_NO_UPPER_LETTER)) passwordFlags |= REGEX_ENDS_NO_UPPER_LETTER_FLAG; if (commandLine.hasOption(CL_REGEX_ENDS_NO_DIGIT)) passwordFlags |= REGEX_ENDS_NO_DIGIT_FLAG; if (commandLine.hasOption(CL_REGEX_STARTS_NO_DIGIT)) passwordFlags |= REGEX_STARTS_NO_DIGIT_FLAG; if (commandLine.hasOption(CL_REGEX_STARTS_NO_SYMBOL)) passwordFlags |= REGEX_STARTS_NO_SYMBOL_FLAG; if (commandLine.hasOption(CL_REGEX_ENDS_NO_SYMBOL)) passwordFlags |= REGEX_ENDS_NO_SYMBOL_FLAG; if (commandLine.hasOption(CL_REGEX_ONLY_1_CAPITAL)) passwordFlags |= REGEX_ONLY_1_CAPITAL_FLAG; if (commandLine.hasOption(CL_REGEX_ONLY_1_SYMBOL)) passwordFlags |= REGEX_ONLY_1_SYMBOL_FLAG; if (commandLine.hasOption(CL_REGEX_AT_LEAST_2_SYMBOLS)) passwordFlags |= REGEX_AT_LEAST_2_SYMBOLS_FLAG; if (commandLine.hasOption(CL_REGEX_ONLY_1_DIGIT)) passwordFlags |= REGEX_ONLY_1_DIGIT_FLAG; if (commandLine.hasOption(CL_REGEX_AT_LEAST_2_DIGITS)) passwordFlags |= REGEX_AT_LEAST_2_DIGITS_FLAG; // ------------------------------------------------------------------- log(Messages.getString("PwGenerator.GENRIC_FLAGS"), //$NON-NLS-1$ false); int res = passwordFlags & PW_DIGITS; log(Messages.getString("PwGenerator.DIGITS") + (res != 0), false); //$NON-NLS-1$ res = passwordFlags & PW_AMBIGUOUS; log(Messages.getString("PwGenerator.AMBIGOUS") + (res != 0), false); //$NON-NLS-1$ res = passwordFlags & PW_SYMBOLS; log(Messages.getString("PwGenerator.SYMBOLS") + (res != 0), false); //$NON-NLS-1$ res = passwordFlags & PW_SYMBOLS_REDUCED; log(Messages.getString("PwGenerator.SYMBOLS_REDUCED") + (res != 0), false); //$NON-NLS-1$ res = passwordFlags & PW_UPPERS; log(Messages.getString("PwGenerator.UPPERS") + (res != 0), false); //$NON-NLS-1$ log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$ false); log(Messages.getString("PwGenerator.GENERATING") + numberOfPasswords //$NON-NLS-1$ + Messages.getString("PwGenerator.PW_LENGTH") //$NON-NLS-1$ + passwordLength, false); log(Messages.getString("PwGenerator.PW"), //$NON-NLS-1$ false); int i; for (i = 0; i < numberOfPasswords; i++) { String password = generatePassword(passwordLength, passwordFlags, maxAttempts, random); if (password != null) passwords.add(password); } } catch (ParseException e) { log(Messages.getString("PwGenerator.PARAM_ERROR") + e.getLocalizedMessage(), true); //$NON-NLS-1$ printUsage(); } catch (NumberFormatException e) { log(Messages.getString("PwGenerator.NUM_FORM_ERROR") + e.getLocalizedMessage(), true); //$NON-NLS-1$ printUsage(); } return passwords; }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.ClinicalDateObscurer.java
/** * For the given file parameter, removes all elements with names dayOfPrefix/monthOfPrefix/yearOfPrefix[ELEMENT] * where ELEMENT is from the list datesToObscure. Adds an element with name elapsedElementBase[ELEMENT] with * value equal to the number of days from the basis date until the given date. (So, if the date is before the basis * date, the value will be negative.) If the given date has no day then 1 is used. If the given date has no month * then 1 is used. If the given date has no year, then the elapsed days element will have no value, because the * calculation cannot be done./*from w ww. j av a 2s . co m*/ * * @param file the clinical XML file to operate on * @param context the context for this QC call * @return the original archive (pulled from the context) * @throws ProcessorException if an error occurs during the process */ @Override protected Archive processFile(final File file, final QcContext context) throws ProcessorException { // only process files that are newly submitted, otherwise are already obscured if (!context.getFilesCopiedFromPreviousArchive().contains(file.getName())) { try { if (getBcrUtils().isClinicalFile(file)) { processClinicalFile(file, context); } else if (getBcrUtils().isBiospecimenFile(file)) { processBiospecimenFile(file, context); } else if (getBcrUtils().isAuxiliaryFile(file)) { // Do nothing } else if (getBcrUtils().isControlFile(file)) { // Do nothing } else {//Unsupported XML file throw new ProcessorException("Unsupported XML file '" + file.getName() + "'"); } } catch (ParserConfigurationException x) { throw new ProcessorException( "Parser Configuration error, parsing file " + file.getName() + ": " + x.getMessage()); } catch (SAXException x) { throw new ProcessorException("SAX error, parsing file " + file.getName() + ": " + x.getMessage()); } catch (IOException x) { throw new ProcessorException("I/O error, parsing file " + file.getName() + ": " + x.getMessage()); } catch (TransformerException x) { throw new ProcessorException( "Error while dumping content of DOM Document in file '" + file.getAbsolutePath() + "'", x); } catch (NoSuchAlgorithmException e) { throw new ProcessorException(e.getMessage()); } } return context.getArchive(); }
From source file:org.globus.workspace.cloud.client.CloudClient.java
void action_hashPrint() throws ExecutionProblem { if (this.args.getActions().contains(AllArgs.ACTION_HASH_PRINT)) { //this.print.infoln(" DN: " + this.hashPrintDN); try {/*from w w w.j av a 2 s . c o m*/ //this.print.infoln("HASH: " + // SecurityUtil.hashDN(this.hashPrintDN)); this.print.infoln(SecurityUtil.hashDN(this.args.getHashPrintDN())); } catch (NoSuchAlgorithmException e) { throw new ExecutionProblem(e.getMessage(), e); } } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstXMsgClient.CFAstXMsgClientSchema.java
public boolean connect(String loginId, String password, String clusterName, String tenantName) { final String S_ProcName = "connect-full"; CFTipClientHandler clientHandler = getCFTipClientHandler(); String deviceName = clientHandler.getDeviceName(); String rqst = null;/*from www.j a v a 2s . c o m*/ try { MessageDigest msgDigest = MessageDigest.getInstance("SHA-512"); msgDigest.update(password.getBytes("UTF-8")); byte[] hash = msgDigest.digest(); byte[] encodedHash = Base64.encodeBase64(hash); byte[] devEncPWHash = clientHandler.encryptWithDevicePrivateKey(encodedHash); clientHandler.initSessionKey(); rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgSchemaMessageFormatter.formatRqstLogIn("\n\t\t\t", loginId, deviceName, devEncPWHash, clusterName, tenantName) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); } catch (NoSuchAlgorithmException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught NoSuchAlgorithmException - " + e.getMessage(), e); } catch (UnsupportedEncodingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught UnsupportedEncodingException - " + e.getMessage(), e); } catch (InvalidKeyException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught InvalidKeyException - " + e.getMessage(), e); } catch (NoSuchPaddingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught NoSuchPaddingException - " + e.getMessage(), e); } catch (IllegalBlockSizeException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught IllegalBlockSizeException - " + e.getMessage(), e); } catch (BadPaddingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught BadPaddingException - " + e.getMessage(), e); } try { cftipClientHandler.issueLoginRequest(rqst); } catch (InvalidAlgorithmParameterException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught InvalidAlgorithmParameterException - " + e.getMessage(), e); } catch (BadPaddingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught BadPaddingException - " + e.getMessage(), e); } catch (IllegalBlockSizeException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught IllegalBlockSizeException - " + e.getMessage(), e); } catch (InvalidKeyException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught InvalidKeyException - " + e.getMessage(), e); } catch (NoSuchAlgorithmException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught NoSuchAlgorithmException - " + e.getMessage(), e); } catch (NoSuchPaddingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught NoSuchPaddingException - " + e.getMessage(), e); } // The response handler sets up the authorization ICFTipResponseHandler responseHandler = cftipClientHandler.getResponseHandler(); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } // If we got a response instead of an exception, we succeeded at logging in. return (true); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgClient.CFAsteriskXMsgClientSchema.java
public boolean connect(String loginId, String password, String clusterName, String tenantName) { final String S_ProcName = "connect-full"; CFTipClientHandler clientHandler = getCFTipClientHandler(); String deviceName = clientHandler.getDeviceName(); String rqst = null;/* w w w . jav a 2 s.c om*/ try { MessageDigest msgDigest = MessageDigest.getInstance("SHA-512"); msgDigest.update(password.getBytes("UTF-8")); byte[] hash = msgDigest.digest(); byte[] encodedHash = Base64.encodeBase64(hash); byte[] devEncPWHash = clientHandler.encryptWithDevicePrivateKey(encodedHash); clientHandler.initSessionKey(); rqst = CFAsteriskXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAsteriskXMsgSchemaMessageFormatter.formatRqstLogIn("\n\t\t\t", loginId, deviceName, devEncPWHash, clusterName, tenantName) + "\n" + CFAsteriskXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); } catch (NoSuchAlgorithmException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught NoSuchAlgorithmException - " + e.getMessage(), e); } catch (UnsupportedEncodingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught UnsupportedEncodingException - " + e.getMessage(), e); } catch (InvalidKeyException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught InvalidKeyException - " + e.getMessage(), e); } catch (NoSuchPaddingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught NoSuchPaddingException - " + e.getMessage(), e); } catch (IllegalBlockSizeException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught IllegalBlockSizeException - " + e.getMessage(), e); } catch (BadPaddingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught BadPaddingException - " + e.getMessage(), e); } try { cftipClientHandler.issueLoginRequest(rqst); } catch (InvalidAlgorithmParameterException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught InvalidAlgorithmParameterException - " + e.getMessage(), e); } catch (BadPaddingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught BadPaddingException - " + e.getMessage(), e); } catch (IllegalBlockSizeException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught IllegalBlockSizeException - " + e.getMessage(), e); } catch (InvalidKeyException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught InvalidKeyException - " + e.getMessage(), e); } catch (NoSuchAlgorithmException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught NoSuchAlgorithmException - " + e.getMessage(), e); } catch (NoSuchPaddingException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught NoSuchPaddingException - " + e.getMessage(), e); } // The response handler sets up the authorization ICFTipResponseHandler responseHandler = cftipClientHandler.getResponseHandler(); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } // If we got a response instead of an exception, we succeeded at logging in. return (true); }
From source file:uk.ac.cam.cl.dtg.segue.api.managers.UserAccountManager.java
/** * Method to create a user object in our database. * /*from w w w .ja v a 2 s.c om*/ * @param request * to enable access to anonymous user information. * @param response * to store the session in our own segue cookie. * @param user * - the user DO to use for updates - must not contain a user id. * @throws InvalidPasswordException * - the password provided does not meet our requirements. * @throws MissingRequiredFieldException * - A required field is missing for the user object so cannot be saved. * @return the user object as was saved. * @throws SegueDatabaseException * - If there is an internal database error. * @throws AuthenticationProviderMappingException * - if there is a problem locating the authentication provider. This only applies for changing a * password. * @throws EmailMustBeVerifiedException * - if a user attempts to sign up with an email that must be verified before it can be used * (i.e. an @isaacphysics.org or @isaacchemistry.org address). */ public RegisteredUserDTO createUserObjectAndSession(final HttpServletRequest request, final HttpServletResponse response, final RegisteredUser user) throws InvalidPasswordException, MissingRequiredFieldException, SegueDatabaseException, AuthenticationProviderMappingException, EmailMustBeVerifiedException { Validate.isTrue(user.getId() == null, "When creating a new user the user id must not be set."); if (this.findUserByEmail(user.getEmail()) != null) { throw new DuplicateAccountException("An account with that e-mail address already exists."); } // Ensure nobody registers with Isaac email addresses. Users can change emails by verifying them however. if (user.getEmail().matches(".*@isaac(physics|chemistry|biology|science)\\.org")) { log.warn("User attempted to register with Isaac email address '" + user.getEmail() + "'!"); throw new EmailMustBeVerifiedException("You cannot register with an Isaac email address."); } RegisteredUser userToSave = null; MapperFacade mapper = this.dtoMapper; // We want to map to DTO first to make sure that the user cannot // change fields that aren't exposed to them RegisteredUserDTO userDtoForNewUser = mapper.map(user, RegisteredUserDTO.class); // This is a new registration userToSave = mapper.map(userDtoForNewUser, RegisteredUser.class); // Set defaults userToSave.setRole(Role.STUDENT); userToSave.setEmailVerificationStatus(EmailVerificationStatus.NOT_VERIFIED); userToSave.setRegistrationDate(new Date()); userToSave.setLastUpdated(new Date()); this.userAuthenticationManager.checkForSeguePasswordChange(user, userToSave); // Before save we should validate the user for mandatory fields. if (!this.isUserValid(userToSave)) { throw new MissingRequiredFieldException("The user provided is missing a mandatory field"); } else if (!this.database.hasALinkedAccount(userToSave) && userToSave.getPassword() == null) { // a user must have a way of logging on. throw new MissingRequiredFieldException("This modification would mean that the user" + " no longer has a way of authenticating. Reverting change."); } IPasswordAuthenticator authenticator = (IPasswordAuthenticator) this.registeredAuthProviders .get(AuthenticationProvider.SEGUE); try { authenticator.createEmailVerificationTokenForUser(userToSave, userToSave.getEmail()); } catch (NoSuchAlgorithmException e1) { log.error("Creation of email verification token failed: " + e1.getMessage()); } catch (InvalidKeySpecException e1) { log.error("Creation of email verification token failed: " + e1.getMessage()); } // save the user to get the userId RegisteredUser userToReturn = this.database.createOrUpdateUser(userToSave); // send an email confirmation and set up verification try { RegisteredUserDTO userToReturnDTO = this.getUserDTOById(userToReturn.getId()); ImmutableMap<String, Object> emailTokens = ImmutableMap.of("verificationURL", generateEmailVerificationURL(userToReturnDTO, userToReturn.getEmailVerificationToken())); emailManager.sendTemplatedEmailToUser(userToReturnDTO, emailManager.getEmailTemplateDTO("email-template-registration-confirmation"), emailTokens, EmailType.SYSTEM); } catch (ContentManagerException e) { log.error("Registration email could not be sent due to content issue: " + e.getMessage()); } catch (NoUserException e) { log.error("Registration email could not be sent due to content issue: " + e.getMessage()); } // save the user again with updated token userToReturn = this.database.createOrUpdateUser(userToReturn); logManager.logInternalEvent(this.convertUserDOToUserDTO(userToReturn), Constants.USER_REGISTRATION, ImmutableMap.builder().put("provider", AuthenticationProvider.SEGUE.name()).build()); // return it to the caller. return this.logUserIn(request, response, userToReturn); }
From source file:org.pwsafe.passwordsafeswt.PasswordSafeJFace.java
/** * Prompts the user to save the current file, if it has been modified. * //from w w w.j a v a 2s.c o m * @return <code>true</code> if the user cancels the action which triggered * the call to this method, <code>false</code> if the save was * successful or ignored. */ public boolean saveAppIfDirty() { boolean cancelled = false; if (isDirty()) { final int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO | SWT.CANCEL; final MessageBox messageBox = new MessageBox(getShell(), style); messageBox.setText(Messages.getString("PasswordSafeJFace.SaveChanges.Title")); //$NON-NLS-1$ messageBox.setMessage(Messages.getString("PasswordSafeJFace.SaveChanges.Message")); //$NON-NLS-1$ final int result = messageBox.open(); if (result == SWT.YES) { try { saveFile(); } catch (final IOException e1) { displayErrorDialog(Messages.getString("PasswordSafeJFace.SaveSafeError.Title"), e1.getMessage(), //$NON-NLS-1$ e1); cancelled = true; } catch (final NoSuchAlgorithmException e) { displayErrorDialog(Messages.getString("PasswordSafeJFace.SaveSafeError.Title"), e.getMessage(), //$NON-NLS-1$ e); cancelled = true; } } else if (result == SWT.CANCEL) { cancelled = true; } } return cancelled; }
From source file:xtremweb.dispatcher.HTTPHandler.java
private UserInterface getUser() throws IOException { UserInterface user = null;//from w ww .j a v a 2 s .c om user = userFromBasicAuth(request); if (user != null) { return user; } try { user = userFromJWTEthereumAuth(request); if (user != null) { return user; } user = userFromOAuth(request); if (user != null) { return user; } user = userFromOpenId(request); if (user != null) { return user; } user = userFromPostParams(request); if (user != null) { return user; } user = userFromCertificate(request); if (user != null) { return user; } return null; } catch (NoSuchAlgorithmException e) { throw new IOException(e.getMessage()); } }
From source file:swp.bibjsf.persistence.Data.java
@Override public int addReader(Reader reader) throws DataSourceException, BusinessElementAlreadyExistsException { logger.debug("add reader " + reader); try {//from w ww. j a v a 2 s .c o m if (getReader(reader.getId()) != null) { // ID must be unique throw new BusinessElementAlreadyExistsException( Messages.get("readerexists") + " " + Messages.get("id") + " = " + reader.getId()); } else if (!reader.getUsername().isEmpty() && getReaderByUsername(reader.getUsername()) != null) { // user name must be unique if defined throw new BusinessElementAlreadyExistsException( Messages.get("readerexists") + Messages.get("username") + " = " + reader.getUsername()); } else { logger.debug("reader " + reader + " does not yet exist; has ID: " + reader.hasId()); try { final String password = hashPassword(reader); Set<String> toIgnore = new HashSet<String>(); HashMap<String, Object> replace = new HashMap<String, Object>(); replace.put("password", password); int result = insertByID(reader, readerTableName, readerMinID, toIgnore, replace); insertUser(reader.getUsername()); return result; } catch (NoSuchAlgorithmException e) { logger.error("MD5 problem"); throw new DataSourceException(e.getMessage()); } } } catch (SQLException e) { logger.error("add reader failure"); throw new DataSourceException(e.getMessage()); } }