Exemplo n.º 1
1
 private static TerminalFactory loadFactory(String pn, String type)
     throws NoSuchAlgorithmException {
   TerminalFactory tf = null;
   try {
     Class<?> cls = Class.forName(pn);
     Provider p = (Provider) cls.getConstructor().newInstance();
     tf = TerminalFactory.getInstance(type == null ? "PC/SC" : type, null, p);
   } catch (ClassNotFoundException
       | InstantiationException
       | IllegalAccessException
       | IllegalArgumentException
       | InvocationTargetException
       | NoSuchMethodException
       | SecurityException e) {
     throw new RuntimeException("Could not load " + pn, e);
   } catch (NoSuchAlgorithmException e) {
     if (e.getCause() != null) {
       Class<?> cause = e.getCause().getClass();
       if (cause.equals(java.lang.UnsupportedOperationException.class)) {
         throw new NoSuchAlgorithmException(e.getCause().getMessage());
       }
       if (cause.equals(java.lang.UnsatisfiedLinkError.class)) {
         throw new NoSuchAlgorithmException(e.getCause().getMessage());
       }
     }
     throw e;
   }
   return tf;
 }
Exemplo n.º 2
0
  private boolean basicAuth(HttpServerRequest request, String encodedAuth) {
    byte[] authBytes = Base64.decodeBase64(encodedAuth);
    String decodedString = new String(authBytes);
    String[] splitAuth = StringUtils.split(StringUtils.trim(decodedString), ":"); // $NON-NLS-1$

    if (splitAuth.length != 2) return false;

    if (fileBasicAuthData.containsKey(splitAuth[0])) {
      String storedHash = new String(Base64.decodeBase64(fileBasicAuthData.get(splitAuth[0])));

      MessageDigest digest;
      try {
        digest = MessageDigest.getInstance("SHA-256"); // $NON-NLS-1$
        digest.update(splitAuth[1].getBytes());

        String receivedHash = new String(digest.digest());

        if (storedHash.equals(receivedHash)) {
          return true;
        }
      } catch (NoSuchAlgorithmException e) {
        logger.error(e.getMessage(), e.getCause());
      }
    }

    request
        .response()
        .headers()
        .add(
            "WWW-Authenticate",
            "Basic realm=\"" + config.getRealm() + "\""); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    return false;
  }