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;
}
}
}
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++;
}
}
}
}
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);
}
}
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);
}
}
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");
}
}
Aggregations