Package org.nasutekds.server.types

Examples of org.nasutekds.server.types.ByteString


    LDAPMessage message =
        org.nasutekds.server.protocols.ldap.LDAPReader.readMessage(asn1Reader);

    if(debugInputStream.isRecordingEnabled())
    {
      ByteString bytesRead = debugInputStream.getRecordedBytes();
      debugInputStream.clearRecordedBytes();

      StringBuilder builder = new StringBuilder();
      builder.append("bytes read from wire(len=");
      builder.append(bytesRead.length());
      builder.append("):");
      builder.append(ServerConstants.EOL);
      bytesRead.toHexPlusAscii(builder, 4);

      TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, builder.toString());
      TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, message.toString());
    }
View Full Code Here


        int beforeCount = (int)reader.readInteger();
        int afterCount  = (int)reader.readInteger();

        int offset = 0;
        int contentCount = 0;
        ByteString greaterThanOrEqual = null;
        byte targetType = reader.peekType();
        switch (targetType)
        {
          case TYPE_TARGET_BYOFFSET:
            reader.readStartSequence();
            offset = (int)reader.readInteger();
            contentCount = (int)reader.readInteger();
            reader.readEndSequence();
            break;

          case TYPE_TARGET_GREATERTHANOREQUAL:
            greaterThanOrEqual = reader.readOctetString();
            break;

          default:
            Message message = INFO_VLVREQ_CONTROL_INVALID_TARGET_TYPE.get(
                byteToHex(targetType));
            throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message);
        }

        ByteString contextID = null;
        if (reader.hasNextElement())
        {
          contextID = reader.readOctetString();
        }
View Full Code Here

  public void modify(ChangeRecordEntry cre)
          throws IOException, LDIFException, ApplicationException
  {
    InternalClientConnection cc =
            InternalClientConnection.getRootConnection();
    ByteString dnByteString =
        ByteString.valueOf(
                    cre.getDN().toString());
    ResultCode rc;
    switch (cre.getChangeOperationType()) {
      case MODIFY:
        LOG.log(Level.INFO, "proparing to modify " + dnByteString);
        ModifyChangeRecordEntry mcre =
                (ModifyChangeRecordEntry) cre;
        ModifyOperation op =
                cc.processModify(dnByteString, mcre.getModifications());
        rc = op.getResultCode();
        if (rc.equals(ResultCode.
                SUCCESS)) {
          LOG.log(Level.INFO, "processed server modification " +
                  modListToString(op.getModifications()));
        } else if (rc.equals(
                ResultCode.
                        ATTRIBUTE_OR_VALUE_EXISTS)) {
          // ignore this error
          LOG.log(Level.INFO, "ignoring attribute that already exists: " +
                  modListToString(op.getModifications()));
        } else if (rc.equals(ResultCode.NO_SUCH_ATTRIBUTE)) {
          // This can happen if for instance the old configuration was
          // changed so that the value of an attribute matches the default
          // value of the attribute in the new configuration.
          // Just log it and move on.
          LOG.log(Level.INFO, "Ignoring attribute not found: " +
                  modListToString(op.getModifications()));
        } else {
          // report the error to the user
          MessageBuilder error = op.getErrorMessage();
          throw new ApplicationException(
              ReturnCode.IMPORT_ERROR,
                  INFO_ERROR_APPLY_LDIF_MODIFY.get(dnByteString.toString(),
                          error != null ? error.toString() : ""),
                  null);
        }
        break;
      case ADD:
        LOG.log(Level.INFO, "preparing to add " + dnByteString);
        AddChangeRecordEntry acre = (AddChangeRecordEntry) cre;
        List<Attribute> attrs = acre.getAttributes();
        ArrayList<RawAttribute> rawAttrs =
                new ArrayList<RawAttribute>(attrs.size());
        for (Attribute a : attrs) {
          rawAttrs.add(new LDAPAttribute(a));
        }
        AddOperation addOp = cc.processAdd(dnByteString, rawAttrs);
        rc = addOp.getResultCode();
        if (rc.equals(ResultCode.SUCCESS)) {
          LOG.log(Level.INFO, "processed server add " + addOp.getEntryDN());
        } else if (rc.equals(ResultCode.ENTRY_ALREADY_EXISTS)) {
          // Compare the attributes with the existing entry to see if we
          // can ignore this add.
          boolean ignore = true;
          for (RawAttribute attr : rawAttrs) {
            ArrayList<ByteString> values = attr.getValues();
            for (ByteString value : values) {
              CompareOperation compOp =
                cc.processCompare(dnByteString, attr.getAttributeType(), value);
              if (ResultCode.ASSERTION_FAILED.equals(compOp.getResultCode())) {
                ignore = false;
                break;
              }
            }
          }
          if (!ignore) {
            MessageBuilder error = addOp.getErrorMessage();
            throw new ApplicationException(
                ReturnCode.IMPORT_ERROR,
                    INFO_ERROR_APPLY_LDIF_ADD.get(dnByteString.toString(),
                            error != null ? error.toString() : ""),
                    null);
          }
        } else {
          boolean ignore = false;

          if (rc.equals(ResultCode.ENTRY_ALREADY_EXISTS)) {

            // The entry already exists.  Compare the attributes with the
            // existing entry to see if we can ignore this add.
            try {
              InternalSearchOperation searchOp =
                      cc.processSearch(
                              cre.getDN(),
                              SearchScope.BASE_OBJECT,
                              SearchFilter.createFilterFromString(
                                      "objectclass=*"));
              LinkedList<SearchResultEntry> se = searchOp.getSearchEntries();
              if (se.size() > 0) {
                SearchResultEntry e = se.get(0);
                List<Attribute> eAttrs = new ArrayList<Attribute>();
                eAttrs.addAll(e.getAttributes());
                eAttrs.add(e.getObjectClassAttribute());
                if (compareUserAttrs(attrs, eAttrs)) {
                  LOG.log(Level.INFO, "Ignoring failure to add " +
                          dnByteString + " since the existing entry's " +
                          "attributes are identical");
                  ignore = true;
                }
              }
            } catch (Exception  e) {
              LOG.log(Level.INFO, "Error attempting to compare rejected add " +
                      "entry with existing entry", e);
            }
          }

          if (!ignore) {
            MessageBuilder error = addOp.getErrorMessage();
            throw new ApplicationException(
                    ReturnCode.IMPORT_ERROR,
                    INFO_ERROR_APPLY_LDIF_ADD.get(dnByteString.toString(),
                            error != null ? error.toString() : ""),
                    null);
          }
        }
        break;
      case DELETE:
        LOG.log(Level.INFO, "preparing to delete " + dnByteString);
        DeleteOperation delOp = cc.processDelete(dnByteString);
        rc = delOp.getResultCode();
        if (rc.equals(ResultCode.SUCCESS)) {
          LOG.log(Level.INFO, "processed server delete " +
                  delOp.getEntryDN());
        } else {
          // report the error to the user
          MessageBuilder error = delOp.getErrorMessage();
          throw new ApplicationException(
              ReturnCode.IMPORT_ERROR,
                  INFO_ERROR_APPLY_LDIF_DELETE.get(dnByteString.toString(),
                          error != null ? error.toString() : ""),
                  null);
        }
        break;
      default:
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public final void getKeys(AttributeValue value, Set<byte[]> keys)
    {
      ByteString key;
      try
      {
        key = matchingRule.normalizeValue(value.getValue());
        keys.add(key.toByteArray());
      }
      catch (DirectoryException de)
      {
      }
    }
View Full Code Here

  public void processSASLBind(BindOperation bindOperation)
  {
    // The CRAM-MD5 bind process uses two stages.  See if the client provided
    // any credentials.  If not, then we're in the first stage so we'll send the
    // challenge to the client.
    ByteString       clientCredentials = bindOperation.getSASLCredentials();
    ClientConnection clientConnection  = bindOperation.getClientConnection();
    if (clientCredentials == null)
    {
      // The client didn't provide any credentials, so this is the initial
      // request.  Generate some random data to send to the client as the
      // challenge and store it in the client connection so we can verify the
      // credentials provided by the client later.
      byte[] challengeBytes = new byte[16];
      randomGenerator.nextBytes(challengeBytes);
      StringBuilder challengeString = new StringBuilder(18);
      challengeString.append('<');
      for (byte b : challengeBytes)
      {
        challengeString.append(byteToLowerHex(b));
      }
      challengeString.append('>');

      ByteString challenge =
          ByteString.valueOf(challengeString.toString());
      clientConnection.setSASLAuthStateInfo(challenge);
      bindOperation.setServerSASLCredentials(challenge);
      bindOperation.setResultCode(ResultCode.SASL_BIND_IN_PROGRESS);
      return;
    }


    // If we've gotten here, then the client did provide credentials.  First,
    // make sure that we have a stored version of the credentials associated
    // with the client connection.  If not, then it likely means that the client
    // is trying to pull a fast one on us.
    Object saslStateInfo = clientConnection.getSASLAuthStateInfo();
    if (saslStateInfo == null)
    {
      bindOperation.setResultCode(ResultCode.INVALID_CREDENTIALS);

      Message message = ERR_SASLCRAMMD5_NO_STORED_CHALLENGE.get();
      bindOperation.setAuthFailureReason(message);
      return;
    }

    if (! (saslStateInfo instanceof  ByteString))
    {
      bindOperation.setResultCode(ResultCode.INVALID_CREDENTIALS);

      Message message = ERR_SASLCRAMMD5_INVALID_STORED_CHALLENGE.get();
      bindOperation.setAuthFailureReason(message);
      return;
    }

    ByteString  challenge = (ByteString) saslStateInfo;

    // Wipe out the stored challenge so it can't be used again.
    clientConnection.setSASLAuthStateInfo(null);

View Full Code Here

    buffer.append("\" newRDN=\"");
    buffer.append(modifyDNOperation.getRawNewRDN().toString());
    buffer.append("\" deleteOldRDN=");
    buffer.append(modifyDNOperation.deleteOldRDN());

    ByteString newSuperior = modifyDNOperation.getRawNewSuperior();
    if (newSuperior != null)
    {
      buffer.append(" newSuperior=\"");
      buffer.append(newSuperior.toString());
    }
    if (modifyDNOperation.isSynchronizationOperation())
      buffer.append(" type=synchronization");

    writer.writeRecord(buffer.toString());
View Full Code Here

    compareResponse.setRequestID(compareRequest.getRequestID());

    // Read the attribute name and value for the compare request.
    AttributeValueAssertion attrValAssertion = compareRequest.getAssertion();
    String attrName = attrValAssertion.getName();
    ByteString attrValue = ByteString.valueOf(attrValAssertion.getValue());
    ByteString dnStr = ByteString.valueOf(compareRequest.getDn());

    // Create and send the LDAP compare request to the server.
    ProtocolOp op = new CompareRequestProtocolOp(dnStr, attrName, attrValue);
    LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op);
    connection.getLDAPWriter().writeMessage(msg);
View Full Code Here

        ModifyDNRequest modifyDNRequest)
    throws IOException, LDAPException, ASN1Exception
  {
    LDAPResult modDNResponse = objFactory.createLDAPResult();
    modDNResponse.setRequestID(modifyDNRequest.getRequestID());
    ByteString dnStr = ByteString.valueOf(modifyDNRequest.getDn());
    ProtocolOp op = null;

    if (modifyDNRequest.getNewSuperior() != null)
    {
      op = new ModifyDNRequestProtocolOp(dnStr, ByteString
View Full Code Here

      LDAPModification ldapMod = new LDAPModification(type, ldapAttr);
      modifications.add(ldapMod);

    }

    ByteString dnStr = ByteString.valueOf(modifyRequest.getDn());

    // Create and send the LDAP request to the server.
    ProtocolOp op = new ModifyRequestProtocolOp(dnStr, modifications);
    LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op);
    connection.getLDAPWriter().writeMessage(msg);
View Full Code Here

    throws IOException, LDAPException, ASN1Exception
  {
    LDAPResult addResponse = objFactory.createLDAPResult();
    addResponse.setRequestID(addRequest.getRequestID());

    ByteString dnStr = ByteString.valueOf(addRequest.getDn());
    ArrayList<RawAttribute> attributes = new ArrayList<RawAttribute>();

    List<DsmlAttr> addList = addRequest.getAttr();
    for(DsmlAttr attr : addList)
    {
View Full Code Here

TOP

Related Classes of org.nasutekds.server.types.ByteString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.