Search in sources :

Example 11 with LdapInvalidDnException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.

the class Ava method compareTo.

/**
 * @see Comparable#compareTo(Object)
 */
@Override
public int compareTo(Ava that) {
    if (that == null) {
        return 1;
    }
    int comp;
    if (schemaManager == null) {
        // Compare the ATs
        comp = normType.compareTo(that.normType);
        if (comp != 0) {
            return comp;
        }
        // and compare the values
        if (value == null) {
            if (that.value == null) {
                return 0;
            } else {
                return -1;
            }
        } else {
            if (that.value == null) {
                return 1;
            } else {
                comp = value.compareTo((Value) that.value);
                return comp;
            }
        }
    } else {
        if (that.schemaManager == null) {
            // Problem : we will apply the current Ava SchemaManager to the given Ava
            try {
                that.apply(schemaManager);
            } catch (LdapInvalidDnException lide) {
                return 1;
            }
        }
        // First compare the AT OID
        comp = attributeType.getOid().compareTo(that.attributeType.getOid());
        if (comp != 0) {
            return comp;
        }
        // Now, compare the two values using the ordering matchingRule comparator, if any
        MatchingRule orderingMR = attributeType.getOrdering();
        if (orderingMR != null) {
            LdapComparator<Object> comparator = (LdapComparator<Object>) orderingMR.getLdapComparator();
            if (comparator != null) {
                comp = value.compareTo(that.value);
                return comp;
            } else {
                comp = compareValues(that);
                return comp;
            }
        } else {
            comp = compareValues(that);
            return comp;
        }
    }
}
Also used : LdapComparator(org.apache.directory.api.ldap.model.schema.LdapComparator) Value(org.apache.directory.api.ldap.model.entry.Value) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 12 with LdapInvalidDnException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.

the class Rdn method addAVA.

/**
 * Add an Ava to the current Rdn
 *
 * @param upType The user provided type of the added Rdn.
 * @param type The normalized provided type of the added Rdn.
 * @param upValue The user provided value of the added Rdn
 * @param value The normalized provided value of the added Rdn
 * @throws LdapInvalidDnException
 *             If the Rdn is invalid
 */
private void addAVA(SchemaManager schemaManager, String type, Value value) throws LdapInvalidDnException {
    // First, let's normalize the type
    AttributeType attributeType;
    String normalizedType = Strings.lowerCaseAscii(type);
    this.schemaManager = schemaManager;
    if (schemaManager != null) {
        attributeType = schemaManager.getAttributeType(normalizedType);
        if (!value.isSchemaAware()) {
            if (attributeType != null) {
                try {
                    value = new Value(attributeType, value);
                } catch (LdapInvalidAttributeValueException liave) {
                    throw new LdapInvalidDnException(liave.getMessage(), liave);
                }
            }
        } else {
            if (attributeType != null) {
                normalizedType = attributeType.getOid();
            }
        }
    }
    Ava newAva = new Ava(schemaManager, type, normalizedType, value);
    switch(nbAvas) {
        case 0:
            // This is the first Ava. Just stores it.
            ava = newAva;
            nbAvas = 1;
            avaType = normalizedType;
            hashCode();
            return;
        case 1:
            // before adding a new one, if it's not already present
            if (ava.equals(newAva)) {
                return;
            }
            // First, create the List and the HashMap
            avas = new ArrayList<>();
            avaTypes = new HashMap<>();
            List<Ava> avaList = new ArrayList<>();
            // and store the existing Ava into it.
            avas.add(ava);
            avaList.add(ava);
            avaTypes.put(avaType, avaList);
            nbAvas++;
            ava = null;
        default:
            // add a new Ava, if it's not already present
            avaList = avaTypes.get(newAva.getNormType());
            if (avaList == null) {
                // Not present, we can add it
                avaList = new ArrayList<>();
                avaList.add(newAva);
                avaTypes.put(newAva.getNormType(), avaList);
                avas.add(newAva);
                nbAvas++;
            } else {
                // We have at least one Ava with the same type, check if it's the same value
                if (!avaList.contains(newAva)) {
                    // Ok, we can add it
                    avaList.add(newAva);
                    avas.add(newAva);
                    nbAvas++;
                }
            }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Value(org.apache.directory.api.ldap.model.entry.Value) ArrayList(java.util.ArrayList) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 13 with LdapInvalidDnException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.

the class AvaTest method testAttributeTypeAndValueValidType.

/**
 * Test a valid type for an AttributeTypeAndValue
 */
@Test
public void testAttributeTypeAndValueValidType() throws LdapException {
    Ava atav = new Ava(schemaManager, "DC", (String) null);
    assertEquals("DC=", atav.toString());
    assertEquals("DC=", atav.getName());
    atav = new Ava(schemaManager, "  DC  ", (String) null);
    assertEquals("  DC  =", atav.toString());
    assertEquals("  DC  =", atav.getName());
    try {
        atav = new Ava(schemaManager, null, (String) null);
        fail();
    } catch (LdapInvalidDnException lide) {
        assertTrue(true);
    }
}
Also used : Ava(org.apache.directory.api.ldap.model.name.Ava) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) Test(org.junit.Test)

Example 14 with LdapInvalidDnException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project wildfly by wildfly.

the class NoReplayKdcServer method start.

/**
 * @throws IOException if we cannot bind to the sockets
 */
public void start() throws IOException, LdapInvalidDnException {
    super.start();
    try {
        // override initialized replay cache with a dummy implementation
        Field replayCacheField = KdcServer.class.getDeclaredField("replayCache");
        replayCacheField.setAccessible(true);
        replayCacheField.set(this, new DummyReplayCache());
    } catch (Exception e) {
        LOGGER.warn("Unable to override replay cache.", e);
    }
}
Also used : Field(java.lang.reflect.Field) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 15 with LdapInvalidDnException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-fortress-core by apache.

the class AuditMgrConsole method printAuthZReport.

/**
 * @param list
 */
void printAuthZReport(List<AuthZ> list) {
    ReaderUtil.clearScreen();
    if (list != null && list.size() > 0) {
        int ctr = 0;
        for (AuthZ authZ : list) {
            /*
            public class AuthZ
            {
                private String createTimestamp;
                private String creatorsName;
                private String entryCSN;
                private String entryDN;
                private String entryUUID;
                private String hasSubordinates;
                private String modifiersName;
                private String modifyTimestamp;
                private String objectClass;
                private String reqAttr;
                private String reqAttrsOnly;
                private String reqAuthzID;
                private String reqControls;
                private String reqDN;
                private String reqDerefAliases;
                private String reqEnd;
                private String reqEntries;
                private String reqFilter;
                private String reqResult;
                private String reqScope;
                private String reqSession;
                private String reqSizeLimit;
                private String reqStart;
                private String reqTimeLimit;
                private String reqType;
                private String structuralObjectClass;
                private String subschemaSubentry;
                */
            // System.out.println("**********************************");
            System.out.println("AUTHORIZATION AUDIT RECORD " + ctr++);
            System.out.println("***************************************");
            Date aDate = null;
            try {
                aDate = TUtil.decodeGeneralizedTime(authZ.getReqEnd());
            } catch (ParseException pe) {
                System.out.println("    Access Time    " + "ParseException=" + pe.getMessage());
            }
            if (aDate != null) {
                SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                String formattedDate = formatter.format(aDate);
                System.out.println("    Access Time     " + formattedDate);
            }
            System.out.println("    userId          " + AuditUtil.getAuthZId(authZ.getReqAuthzID()));
            try {
                Permission pOp = getAuthZPerm(authZ);
                System.out.println("    Resource Name   " + pOp.getObjName());
                System.out.println("    Operation       " + pOp.getOpName());
                int rCtr = 0;
                if (pOp.getRoles() != null) {
                    // TODO: fix the NPE that happens here:
                    System.out.println("    Success?        " + authZ.getReqEntries().equals(GlobalIds.AUTHZ_COMPARE_FAILURE_FLAG));
                    for (String role : pOp.getRoles()) {
                        System.out.println("    Role[" + rCtr++ + "]         " + role);
                    }
                }
            } catch (LdapInvalidDnException e) {
                System.out.println("LdapInvalidDnException=" + e);
            }
            // System.out.println("    reqStart        [" + authZ.getReqStart() + "]");
            // System.out.println("    reqEnd          [" + authZ.getReqEnd() + "]");
            System.out.println();
            System.out.println();
        // System.out.println("**********************************");
        }
    } else {
        System.out.println("AuthZ list empty");
    }
}
Also used : AuthZ(org.apache.directory.fortress.core.model.AuthZ) Permission(org.apache.directory.fortress.core.model.Permission) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Aggregations

LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)25 Dn (org.apache.directory.api.ldap.model.name.Dn)18 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)10 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)8 DecoderException (org.apache.directory.api.asn1.DecoderException)6 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)5 Rdn (org.apache.directory.api.ldap.model.name.Rdn)4 Value (org.apache.directory.api.ldap.model.entry.Value)3 ModifyDnRequest (org.apache.directory.api.ldap.model.message.ModifyDnRequest)3 ModifyDnResponseImpl (org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl)3 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)2 Control (org.apache.directory.api.ldap.model.message.Control)2 Ava (org.apache.directory.api.ldap.model.name.Ava)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1