operation.setResultCode(ResultCode.PROTOCOL_ERROR);
return;
}
ByteString dnString;
ASN1Reader reader = ASN1.getReader(requestValue);
try
{
reader.readStartSequence();
dnString = reader.readOctetString();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message =
ERR_PWPSTATE_EXTOP_DECODE_FAILURE.get(getExceptionMessage(e));
operation.appendErrorMessage(message);
operation.setResultCode(ResultCode.PROTOCOL_ERROR);
return;
}
// Decode the DN and get the corresponding user entry.
DN targetDN;
try
{
targetDN = DN.decode(dnString);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
operation.setResponseData(de);
return;
}
DN rootDN = DirectoryServer.getActualRootBindDN(targetDN);
if (rootDN != null)
{
targetDN = rootDN;
}
Entry userEntry;
InternalClientConnection conn =
new InternalClientConnection(clientConnection.getAuthenticationInfo());
InternalSearchOperation internalSearch =
conn.processSearch(targetDN, SearchScope.BASE_OBJECT,
DereferencePolicy.NEVER_DEREF_ALIASES, 1, 0,
false, userFilter, requestAttributes, null);
if (internalSearch.getResultCode() != ResultCode.SUCCESS)
{
operation.setResultCode(internalSearch.getResultCode());
operation.setErrorMessage(internalSearch.getErrorMessage());
operation.setMatchedDN(internalSearch.getMatchedDN());
operation.setReferralURLs(internalSearch.getReferralURLs());
return;
}
List<SearchResultEntry> matchingEntries = internalSearch.getSearchEntries();
if (matchingEntries.isEmpty())
{
operation.setResultCode(ResultCode.INSUFFICIENT_ACCESS_RIGHTS);
return;
}
else if (matchingEntries.size() > 1)
{
Message message = ERR_PWPSTATE_EXTOP_MULTIPLE_ENTRIES.get(
String.valueOf(targetDN));
operation.appendErrorMessage(message);
operation.setResultCode(ResultCode.CONSTRAINT_VIOLATION);
return;
}
else
{
userEntry = matchingEntries.get(0);
}
// Get the password policy state for the user entry.
PasswordPolicyState pwpState;
PasswordPolicy policy;
try
{
pwpState = new PasswordPolicyState(userEntry, false);
policy = pwpState.getPolicy();
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
operation.setResponseData(de);
return;
}
// Create a hash set that will be used to hold the types of the return
// types that should be included in the response.
boolean returnAll;
LinkedHashSet<Integer> returnTypes = new LinkedHashSet<Integer>();
try
{
if (!reader.hasNextElement())
{
// There is no operations sequence.
returnAll = true;
}
else if(reader.peekLength() <= 0)
{
// There is an operations sequence but its empty.
returnAll = true;
reader.readStartSequence();
reader.readEndSequence();
}
else
{
returnAll = false;
reader.readStartSequence();
while(reader.hasNextElement())
{
int opType;
ArrayList<String> opValues;
reader.readStartSequence();
opType = (int)reader.readInteger();
if (!reader.hasNextElement())
{
// There is no values sequence
opValues = null;
}
else if(reader.peekLength() <= 0)
{
// There is a values sequence but its empty
opValues = null;
reader.readStartSequence();
reader.readEndSequence();
}
else
{
reader.readStartSequence();
opValues = new ArrayList<String>();
while (reader.hasNextElement())
{
opValues.add(reader.readOctetStringAsString());
}
reader.readEndSequence();
}
reader.readEndSequence();
if(!processOp(opType, opValues, operation,
returnTypes, pwpState, policy))
{
return;
}
}
reader.readEndSequence();
}
reader.readEndSequence();
// If there are any modifications that need to be made to the password
// policy state, then apply them now.
List<Modification> stateMods = pwpState.getModifications();