Esempio n. 1
0
 public void receiveAuthRequest(
     final int id, final String mechName, final byte[] initialResponse) {
   log.tracef("Received authentication request for ID %08x, mech %s", id, mechName);
   if (id == 0 || id == 1) {
     // ignore
     return;
   }
   getExecutor()
       .execute(
           () -> {
             final SaslServer saslServer;
             final IntIndexHashMap<Auth> authMap = this.authMap;
             try {
               saslServer =
                   authenticationFactory.createMechanism(
                       mechName, f -> new ServerNameSaslServerFactory(f, endpoint.getName()));
             } catch (SaslException e) {
               log.trace("Authentication failed at mechanism creation", e);
               try {
                 Auth oldAuth = authMap.put(new Auth(id, new RejectingSaslServer()));
                 if (oldAuth != null) oldAuth.dispose();
                 connectionHandler.sendAuthReject(id);
               } catch (IOException e1) {
                 log.trace("Failed to send auth reject", e1);
               }
               return;
             }
             // clear out any old auth
             final Auth auth = new Auth(id, saslServer);
             Auth oldAuth = authMap.put(auth);
             if (oldAuth != null) oldAuth.dispose();
             final byte[] challenge;
             try {
               challenge = saslServer.evaluateResponse(initialResponse);
             } catch (SaslException e) {
               log.trace("Authentication failed at response evaluation", e);
               try {
                 connectionHandler.sendAuthReject(id);
               } catch (IOException e1) {
                 authMap.remove(auth);
                 auth.dispose();
                 log.trace("Failed to send auth reject", e1);
               }
               return;
             }
             if (saslServer.isComplete()) {
               try {
                 connectionHandler.sendAuthSuccess(id, challenge);
               } catch (IOException e) {
                 authMap.remove(auth);
                 auth.dispose();
                 log.trace("Failed to send auth success", e);
               }
               return;
             } else {
               try {
                 connectionHandler.sendAuthChallenge(id, challenge);
               } catch (IOException e) {
                 authMap.remove(auth);
                 auth.dispose();
                 log.trace("Failed to send auth challenge", e);
               }
               return;
             }
           });
 }
Esempio n. 2
0
  private static void handleCoordinateOperation() {
    final Resolver resolver = cloudname.getResolver();
    final Coordinate coordinate = Coordinate.parse(coordinateFlag);
    switch (operationFlag) {
      case CREATE:
        try {
          cloudname.createCoordinate(coordinate);
        } catch (CloudnameException e) {
          System.err.println("Got error: " + e.getMessage());
          break;
        } catch (CoordinateExistsException e) {
          e.printStackTrace();
          break;
        }
        System.err.println("Created coordinate.");
        break;
      case DELETE:
        try {
          cloudname.destroyCoordinate(coordinate);
        } catch (CoordinateDeletionException e) {
          System.err.println("Got error: " + e.getMessage());
          return;
        } catch (CoordinateMissingException e) {
          System.err.println("Got error: " + e.getMessage());
          break;
        } catch (CloudnameException e) {
          System.err.println("Got error: " + e.getMessage());
          break;
        }
        System.err.println("Deleted coordinate.");
        break;
      case STATUS:
        {
          ServiceStatus status;
          try {
            status = cloudname.getStatus(coordinate);
          } catch (CloudnameException e) {
            System.err.println(
                "Problems loading status, is service running? Error:\n" + e.getMessage());
            break;
          }
          System.err.println(
              "Status:\n" + status.getState().toString() + " " + status.getMessage());
          List<Endpoint> endpoints = null;
          try {
            endpoints =
                resolver.resolve(
                    "all."
                        + coordinate.getService()
                        + "."
                        + coordinate.getUser()
                        + "."
                        + coordinate.getCell());
          } catch (CloudnameException e) {
            System.err.println("Got error: " + e.getMessage());
            break;
          }
          System.err.println("Endpoints:");
          for (Endpoint endpoint : endpoints) {
            if (endpoint.getCoordinate().getInstance() == coordinate.getInstance()) {
              System.err.println(
                  endpoint.getName()
                      + "-->"
                      + endpoint.getHost()
                      + ":"
                      + endpoint.getPort()
                      + " protocol:"
                      + endpoint.getProtocol());
              System.err.println("Endpoint data:\n" + endpoint.getEndpointData());
            }
          }
          break;
        }
      case HOST:
        {
          List<Endpoint> endpoints = null;
          try {
            endpoints = resolver.resolve(coordinate.asString());
          } catch (CloudnameException e) {
            System.err.println(
                "Could not resolve " + coordinate.asString() + " Error:\n" + e.getMessage());
            break;
          }
          for (Endpoint endpoint : endpoints) {
            System.out.println("Host: " + endpoint.getHost());
          }
        }
        break;
      case SET_CONFIG:
        try {
          cloudname.setConfig(coordinate, configFlag, null);
        } catch (CloudnameException e) {
          System.err.println("Got error: " + e.getMessage());
          break;

        } catch (CoordinateMissingException e) {
          System.err.println("Non-existing coordinate.");
        }
        System.err.println("Config updated.");
        break;

      case READ_CONFIG:
        try {
          System.out.println("Config is:" + cloudname.getConfig(coordinate));
        } catch (CoordinateMissingException e) {
          System.err.println("Non-existing coordinate.");
        } catch (CloudnameException e) {
          System.err.println("Problem with cloudname: " + e.getMessage());
        }
        break;
      default:
        System.out.println("Unknown command " + operationFlag);
    }
  }