Package org.nasutekds.server.protocols.ldap

Examples of org.nasutekds.server.protocols.ldap.LDAPControl


  public void testDecodeControlUsernameValue()
         throws Exception
  {
    ByteString authzID = ByteString.valueOf("u:test");

    LDAPControl c = new LDAPControl(OID_PROXIED_AUTH_V2, true, authzID);
    ProxiedAuthV2Control proxyControl = ProxiedAuthV2Control.DECODER.decode(c.isCritical(), c.getValue());
    assertEquals(proxyControl.getAuthorizationID(), authzID);
  }
View Full Code Here


  public void testDecodeControlInvalidValue()
         throws Exception
  {
    ByteString authzID = ByteString.valueOf("invalid");

    LDAPControl c = new LDAPControl(OID_PROXIED_AUTH_V2, true, authzID);
    ProxiedAuthV2Control proxyControl = ProxiedAuthV2Control.DECODER.decode(c.isCritical(), c.getValue());
    assertEquals(proxyControl.getAuthorizationID(), authzID);
  }
View Full Code Here

    ByteStringBuilder bsb = new ByteStringBuilder();
    ASN1Writer writer = ASN1.getWriter(bsb);
    writer.writeOctetString(innerValue);
    ByteString outerValue = bsb.toByteString();

    LDAPControl c = new LDAPControl(OID_PROXIED_AUTH_V2, true, outerValue);
    ProxiedAuthV2Control proxyControl = ProxiedAuthV2Control.DECODER.decode(c.isCritical(), c.getValue());
    assertEquals(proxyControl.getAuthorizationID(), innerValue);
  }
View Full Code Here

    ByteStringBuilder bsb = new ByteStringBuilder();
    ASN1Writer writer = ASN1.getWriter(bsb);
    writer.writeOctetString(innerValue);
    ByteString outerValue = bsb.toByteString();

    LDAPControl c = new LDAPControl(OID_PROXIED_AUTH_V2, true, outerValue);
    ProxiedAuthV2Control proxyControl = ProxiedAuthV2Control.DECODER.decode(c.isCritical(), c.getValue());
    assertEquals(proxyControl.getAuthorizationID(), innerValue);
  }
View Full Code Here

      bsb.clear();
      returnTypes = PersistentSearchChangeType.intToTypes(i);
      PersistentSearchControl psc = new PersistentSearchControl(
          isCritical, returnTypes, changesOnly, returnECs);
      psc.write(writer);
      LDAPControl control = LDAPReader.readControl(ASN1.getReader(bsb));
      psc = PersistentSearchControl.DECODER.decode(control.isCritical(), control.getValue());
      assertNotNull(psc);
      assertEquals(isCritical, psc.isCritical());
      assertEquals(OID_PERSISTENT_SEARCH, psc.getOID());
      assertEquals(changesOnly, psc.getChangesOnly());
      assertEquals(returnECs, psc.getReturnECs());
      assertEquals(returnTypes.size(), psc.getChangeTypes().size());

      // Check the toString
      String toString = "PersistentSearchControl(changeTypes=\"" +
      PersistentSearchChangeType.changeTypesToString(psc.getChangeTypes()) +
      "\",changesOnly=" + psc.getChangesOnly() +
      ",returnECs=" +psc.getReturnECs() +")" ;
      assertEquals(psc.toString(), toString);


      // check null value for the control
      try
      {
        control = new LDAPControl(OID_PERSISTENT_SEARCH, isCritical);
        psc = PersistentSearchControl.DECODER.decode(control.isCritical(), control.getValue());
        assertTrue(false,"the control should have a value");
      }
      catch (DirectoryException e)
      {
        // normal case
        assertTrue(true,"the control should have a value");
      }

      // check invalid value for the control
      try
      {
        control = new LDAPControl(OID_PERSISTENT_SEARCH, isCritical,
            ByteString.valueOf("invalid value"));
        psc = PersistentSearchControl.DECODER.decode(control.isCritical(), control.getValue());
        assertTrue(false, "the control should have a value");
      }
      catch (DirectoryException e)
      {
        // normal case
View Full Code Here

      // also check encode/decode
      try
      {
        bsb.clear();
        ecnc.write(writer);
        LDAPControl control = LDAPReader.readControl(ASN1.getReader(bsb));
        newEcnc = EntryChangeNotificationControl.DECODER.decode(control.isCritical(), control.getValue());
        assertNotNull(newEcnc);
        assertEquals(ecnc.getOID(), newEcnc.getOID());
        assertEquals(ecnc.getChangeNumber(), newEcnc.getChangeNumber());
        assertEquals(ecnc.getChangeType(), newEcnc.getChangeType());
        assertNull(newEcnc.getPreviousDN());
        assertEquals(ecnc.isCritical(), newEcnc.isCritical());
      }
      catch (DirectoryException e)
      {
        if (type.compareTo(PersistentSearchChangeType.MODIFY_DN) == 0)
        {
          assertTrue(true,"could decode a control with previousDN=null " +
              "and type=modDN");
        }
        else
        {
          assertTrue(false,"could decode a control with previousDN=null " +
          "and type=modDN");
        }
      }
    }

    // Test contructor EntryChangeNotificationControl
    // (PersistentSearchChangeType changeType, DN previousDN, long
    // changeNumber)
    DN dn = DN.decode(dnString);
    for (PersistentSearchChangeType type : types)
    {
      ecnc = new EntryChangeNotificationControl(type, dn, changeNumber);
      assertNotNull(ecnc);
      assertEquals(OID_ENTRY_CHANGE_NOTIFICATION, ecnc.getOID());
      assertEquals(changeNumber, ecnc.getChangeNumber());
      assertEquals(type, ecnc.getChangeType());
      assertEquals(dn, ecnc.getPreviousDN());
      assertEquals(false, ecnc.isCritical()) ;
      checkEntryChangeNotificationControlToString(ecnc);

      // also check encode/decode
      try
      {
        bsb.clear();
        ecnc.write(writer);
        LDAPControl control = LDAPReader.readControl(ASN1.getReader(bsb));
        newEcnc = EntryChangeNotificationControl.DECODER.decode(control.isCritical(), control.getValue());
        assertNotNull(newEcnc);
        assertEquals(ecnc.getOID(),newEcnc.getOID());
        assertEquals(ecnc.getChangeNumber(),newEcnc.getChangeNumber());
        assertEquals(ecnc.getChangeType(),newEcnc.getChangeType());
        assertEquals(ecnc.getPreviousDN(),newEcnc.getPreviousDN());
        assertEquals(ecnc.isCritical(),newEcnc.isCritical()) ;
      }
      catch (DirectoryException e)
      {
        if (type.compareTo(PersistentSearchChangeType.MODIFY_DN) == 0)
        {
          assertTrue(false,"couldn't decode a control with previousDN " +
              "not null and type=modDN");
        }
        else
        {
          assertTrue(true,"couldn't decode a control with previousDN " +
          "not null and type=modDN");
        }
      }
    }


    // Test contructor EntryChangeNotificationControl(boolean
    // isCritical, PersistentSearchChangeType changeType,
    // DN previousDN, long changeNumber)
    for (PersistentSearchChangeType type : types)
    {
      ecnc = new EntryChangeNotificationControl(isCritical, type, dn,
          changeNumber);
      assertNotNull(ecnc);
      assertEquals(OID_ENTRY_CHANGE_NOTIFICATION, ecnc.getOID());
      assertEquals(changeNumber, ecnc.getChangeNumber());
      assertEquals(type, ecnc.getChangeType());
      assertEquals(dn, ecnc.getPreviousDN());
      assertEquals(isCritical, ecnc.isCritical()) ;
      checkEntryChangeNotificationControlToString(ecnc);

      // also check encode/decode
      try
      {
        bsb.clear();
        ecnc.write(writer);
        LDAPControl control = LDAPReader.readControl(ASN1.getReader(bsb));
        newEcnc = EntryChangeNotificationControl.DECODER.decode(control.isCritical(), control.getValue());
        assertNotNull(newEcnc);
        assertEquals(ecnc.getOID(),newEcnc.getOID());
        assertEquals(ecnc.getChangeNumber(),newEcnc.getChangeNumber());
        assertEquals(ecnc.getChangeType(),newEcnc.getChangeType());
        assertEquals(ecnc.getPreviousDN(),newEcnc.getPreviousDN());
        assertEquals(ecnc.isCritical(),newEcnc.isCritical()) ;
      }
      catch (DirectoryException e)
      {
        if (type.compareTo(PersistentSearchChangeType.MODIFY_DN) == 0)
        {
          assertTrue(false,"couldn't decode a control with previousDN " +
              "not null and type=modDN");
        }
        else
        {
          assertTrue(true,"couldn't decode a control with previousDN " +
          "not null and type=modDN");
        }
      }
    }

    // Check error on decode
    try
    {
      LDAPControl control =
          new LDAPControl(OID_ENTRY_CHANGE_NOTIFICATION, isCritical);
      newEcnc = EntryChangeNotificationControl.DECODER.decode(control.isCritical(), control.getValue());
      assertTrue(false,"couldn't decode a control with null");
    }
    catch (DirectoryException e)
    {
      assertTrue(true,"couldn't decode a control with null");
View Full Code Here

    assertNotNull(pec);
    assertEquals(pec.isCritical(),isCritical);
    assertEquals(pec.getOID(),OID_NS_PASSWORD_EXPIRED);

    // Check the decode
    LDAPControl control = new LDAPControl(OID_NS_PASSWORD_EXPIRED,isCritical);
    pec = PasswordExpiredControl.DECODER.decode(control.isCritical(), control.getValue());
    assertNotNull(pec);
    assertEquals(pec.isCritical(),isCritical);
    assertEquals(pec.getOID(),OID_NS_PASSWORD_EXPIRED);

    control = new LDAPControl(OID_NS_PASSWORD_EXPIRED, isCritical,
        ByteString.valueOf("value"));
    try
    {
      pec = PasswordExpiredControl.DECODER.decode(control.isCritical(), control.getValue());
      assertTrue(false,
          "should be allow to create a passwordExpiredControl with value");
    }
    catch (DirectoryException e)
    {
      // Normal case
      assertTrue(true,
          "should be allow to create a passwordExpiredControl with value");
    }

    // Check toString
    assertEquals("PasswordExpiredControl()", pec.toString());

    // Check encode
    ByteStringBuilder bsb = new ByteStringBuilder();
    ASN1Writer writer = ASN1.getWriter(bsb);
    pec = new PasswordExpiredControl(isCritical);
    pec.write(writer);
    control = LDAPReader.readControl(ASN1.getReader(bsb));
    PasswordExpiredControl newPec =
        PasswordExpiredControl.DECODER.decode(control.isCritical(), control.getValue());
    assertNotNull(newPec);
    assertEquals(newPec.isCritical(), isCritical);
    assertEquals(pec.getOID(),OID_NS_PASSWORD_EXPIRED);
  }
View Full Code Here

    assertEquals(pec.isCritical(),isCritical);
    assertEquals(pec.getOID(),OID_NS_PASSWORD_EXPIRING);
    assertEquals(pec.getSecondsUntilExpiration(), sec);

    // Check the decode
    LDAPControl control = new LDAPControl(OID_NS_PASSWORD_EXPIRING,isCritical);
    try
    {
      pec = PasswordExpiringControl.DECODER.decode(control.isCritical(), control.getValue());
      assertTrue(false,
          "shouldn't be allow to create PasswordExpiringControl without value");
    }
    catch (DirectoryException e)
    {
      // Normal case
      assertTrue(true,
          "shouldn't be allow to create PasswordExpiringControl without value");
    }

    control = new LDAPControl(OID_NS_PASSWORD_EXPIRING, isCritical,
        ByteString.valueOf("Wrong value"));
    try
    {
      pec = PasswordExpiringControl.DECODER.decode(control.isCritical(), control.getValue());
      assertTrue(false,
      "shouldn't be allow to create PasswordExpiringControl with a wrong value");
    }
    catch (DirectoryException e)
    {
      // Normal case
      assertTrue(true,
      "shouldn't be allow to create PasswordExpiringControl with a wrong value");
    }

    // Check encode/decode
    ByteStringBuilder bsb = new ByteStringBuilder();
    ASN1Writer writer = ASN1.getWriter(bsb);
    pec = new PasswordExpiringControl(isCritical, sec);
    pec.write(writer);
    control = LDAPReader.readControl(ASN1.getReader(bsb));
    pec = PasswordExpiringControl.DECODER.decode(control.isCritical(), control.getValue());
    assertNotNull(pec);
    assertEquals(pec.isCritical(), isCritical);
    assertEquals(pec.getOID(),OID_NS_PASSWORD_EXPIRING);
    assertEquals(pec.getSecondsUntilExpiration(), sec);
  }
View Full Code Here

    // Check the encode/decode
    ByteStringBuilder bsb = new ByteStringBuilder();
    ASN1Writer writer = ASN1.getWriter(bsb);
    pec = new PasswordPolicyRequestControl(isCritical);
    pec.write(writer);
    LDAPControl control = LDAPReader
        .readControl(ASN1.getReader(bsb));
    pec = PasswordPolicyRequestControl.DECODER.decode(control.isCritical(), control.getValue());
    assertNotNull(pec);
    assertEquals(pec.isCritical(),isCritical);
    assertEquals(pec.getOID(),OID_PASSWORD_POLICY_CONTROL);

    control = new LDAPControl(OID_PASSWORD_POLICY_CONTROL,
        isCritical, ByteString.valueOf("value"));
    try
    {
      pec = PasswordPolicyRequestControl.DECODER.decode(control.isCritical(), control.getValue());
      assertTrue(false,
          "should be allow to create a PasswordPolicyRequestControl with value");
    }
    catch (DirectoryException e)
    {
View Full Code Here

      {
        bsb.clear();
        control = new PasswordPolicyResponseControl(isCritical,
            warningType, warningValue, errorType);
        control.write(writer);
        LDAPControl c = LDAPReader.readControl(ASN1.getReader(bsb));
        pprc = PasswordPolicyResponseControl.DECODER.decode(c.isCritical(), c.getValue());
        assertNotNull(pprc);
        assertEquals(warningType, pprc.getWarningType());
        assertEquals(errorType, pprc.getErrorType());
        assertEquals(pprc.getWarningValue(), warningValue);
        assertEquals(pprc.getOID(), OID_PASSWORD_POLICY_CONTROL);

        // check to String
        String toString =
          "PasswordPolicyResponseControl(" +
          warningType.toString() +
          "=" +
          warningValue +
          ", " +
          errorType.toString() +
          ")" ;
        assertEquals(toString, pprc.toString()) ;


        // check null value for the control
        try
        {
          c = new LDAPControl(OID_PASSWORD_POLICY_CONTROL, isCritical);
          pprc = PasswordPolicyResponseControl.DECODER.decode(c.isCritical(), c.getValue());
          assertTrue(false,"the control should have a value");
        }
        catch (DirectoryException e)
        {
          // normal case
          assertTrue(true,"the control should have a value");
        }


        // check null warning type
        bsb.clear();
        control = new PasswordPolicyResponseControl(isCritical,
            null, warningValue, errorType);
        control.write(writer);
        c = LDAPReader.readControl(ASN1.getReader(bsb));
        try
        {
          pprc = PasswordPolicyResponseControl.DECODER.decode(c.isCritical(), c.getValue());
          assertNull(pprc.getWarningType());
        }
        catch (DirectoryException e)
        {
          assertTrue(false,"We should be able to decode the control");
        }

        // check null error type
        bsb.clear();
        control = new PasswordPolicyResponseControl(isCritical,
            warningType, warningValue, null);
        control.write(writer);
        c = LDAPReader.readControl(ASN1.getReader(bsb));
        try
        {
          pprc = PasswordPolicyResponseControl.DECODER.decode(c.isCritical(), c.getValue());
          assertNull(pprc.getErrorType());
        }
        catch (DirectoryException e)
        {
          assertTrue(false,"We should be able to decode the control");
View Full Code Here

TOP

Related Classes of org.nasutekds.server.protocols.ldap.LDAPControl

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.