Esempio n. 1
0
 void receiveAuthResponse(final int id, final byte[] response) {
   log.tracef("Received authentication response for ID %08x", id);
   if (id == 0 || id == 1) {
     // ignore
     return;
   }
   getExecutor()
       .execute(
           () -> {
             Auth auth = authMap.get(id);
             if (auth == null) {
               auth = authMap.putIfAbsent(new Auth(id, new RejectingSaslServer()));
               if (auth == null) {
                 // reject
                 try {
                   connectionHandler.sendAuthReject(id);
                 } catch (IOException e1) {
                   log.trace("Failed to send auth reject", e1);
                 }
                 return;
               }
             }
             final SaslServer saslServer = auth.getSaslServer();
             final byte[] challenge;
             try {
               challenge = saslServer.evaluateResponse(response);
             } catch (SaslException 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
 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;
             }
           });
 }