/**
   * @param authentication
   * @param msg
   * @return
   * @throws IOException
   */
  public int authenticate(AuthenticationProtocolServer authentication, SshMsgUserAuthRequest msg)
      throws IOException {
    NativeAuthenticationProvider authImpl = NativeAuthenticationProvider.getInstance();

    if (authImpl == null) {
      log.error("Cannot perfrom authentication witout native authentication provider");

      return AuthenticationProtocolState.FAILED;
    }

    ByteArrayReader bar = new ByteArrayReader(msg.getRequestData());
    boolean changepwd = ((bar.read() == 0) ? false : true);
    String password = bar.readString();
    String newpassword = null;

    if (changepwd) {
      newpassword = bar.readString();

      try {
        if (!authImpl.changePassword(msg.getUsername(), password, newpassword)) {
          return AuthenticationProtocolState.FAILED;
        }

        if (authImpl.logonUser(msg.getUsername(), newpassword)) {
          return AuthenticationProtocolState.COMPLETE;
        } else {
          return AuthenticationProtocolState.FAILED;
        }
      } catch (PasswordChangeException ex1) {
        return AuthenticationProtocolState.FAILED;
      }
    } else {
      try {
        if (authImpl.logonUser(msg.getUsername(), password)) {
          log.info(msg.getUsername() + " has passed password authentication");

          return AuthenticationProtocolState.COMPLETE;
        } else {
          log.info(msg.getUsername() + " has failed password authentication");

          return AuthenticationProtocolState.FAILED;
        }
      } catch (PasswordChangeException ex) {
        SshMsgUserAuthPwdChangeReq reply =
            new SshMsgUserAuthPwdChangeReq(
                msg.getUsername() + " is required to change password", "");
        authentication.sendMessage(reply);

        return AuthenticationProtocolState.READY;
      }
    }
  }
Beispiel #2
0
 /**
  * @param bar
  * @throws InvalidMessageException
  */
 protected void constructMessage(ByteArrayReader bar) throws InvalidMessageException {
   try {
     cookie = new byte[16];
     bar.read(cookie);
     supportedKex = loadListFromString(bar.readString());
     supportedPK = loadListFromString(bar.readString());
     supportedEncryptCS = loadListFromString(bar.readString());
     supportedEncryptSC = loadListFromString(bar.readString());
     supportedMacCS = loadListFromString(bar.readString());
     supportedMacSC = loadListFromString(bar.readString());
     supportedCompCS = loadListFromString(bar.readString());
     supportedCompSC = loadListFromString(bar.readString());
     supportedLangCS = loadListFromString(bar.readString());
     supportedLangSC = loadListFromString(bar.readString());
     firstKexFollows = (bar.read() == 0) ? false : true;
   } catch (IOException ioe) {
     throw new InvalidMessageException("Error reading message data: " + ioe.getMessage());
   }
 }
Beispiel #3
0
 /**
  * @param bar
  * @throws java.io.IOException
  * @throws com.sshtools.j2ssh.transport.InvalidMessageException DOCUMENT ME!
  */
 public void constructMessage(ByteArrayReader bar)
     throws java.io.IOException, com.sshtools.j2ssh.transport.InvalidMessageException {
   id = bar.readUINT32();
   path = bar.readString();
   attrs = new FileAttributes(bar);
 }