Пример #1
0
 public static Subject createSubject(File certKeyFile) {
   try {
     X509CertificateChain certKey = readPemCertificateAndKey(certKeyFile);
     return AuthenticationUtil.getSubject(certKey);
   } catch (InvalidKeySpecException ex) {
     throw new RuntimeException("failed to read RSA private key from " + certKeyFile, ex);
   } catch (NoSuchAlgorithmException ex) {
     throw new RuntimeException("BUG: failed to create empty KeyStore", ex);
   } catch (IOException ex) {
     throw new RuntimeException("failed to read certificate file " + certKeyFile, ex);
   } catch (CertificateException ex) {
     throw new RuntimeException("failed to load certificate from file " + certKeyFile, ex);
   }
 }
 public UserData registerUser(String userName, String email, String password)
     throws UserRegistrationException {
   checkNotNull(userName);
   checkNotNull(email);
   checkNotNull(password);
   User existingUser = metaproject.getUser(userName);
   if (existingUser != null) {
     throw new UserNameAlreadyExistsException(userName);
   }
   for (User user : metaproject.getUsers()) {
     if (email.equals(user.getEmail())) {
       throw new UserEmailAlreadyExistsException(email);
     }
   }
   User newUser = metaproject.createUser(userName, password);
   return AuthenticationUtil.createUserData(UserId.getUserId(newUser.getName()));
 }
Пример #3
0
 public static Subject createSubject(File certFile, File keyFile) {
   try {
     PrivateKey pk = readPrivateKey(keyFile);
     X509Certificate[] chain = readCertificateChain(certFile);
     return AuthenticationUtil.getSubject(chain, pk);
   } catch (InvalidKeySpecException ex) {
     throw new RuntimeException("failed to read RSA private key from " + keyFile, ex);
   } catch (NoSuchAlgorithmException ex) {
     throw new RuntimeException("BUG: failed to create empty KeyStore", ex);
   } catch (FileNotFoundException ex) {
     throw new RuntimeException(
         "failed to find certificate and/or key file " + certFile + "," + keyFile, ex);
   } catch (IOException ex) {
     throw new RuntimeException("failed to read certificate file " + certFile, ex);
   } catch (CertificateException ex) {
     throw new RuntimeException("failed to load certificate from file " + certFile, ex);
   }
 }