use of org.jdiameter.api.validation.AvpRepresentation in project jain-slee.diameter by RestComm.
the class AvpAssistant method checkAvpFlags.
/**
* @param set
* the set to check
* @return an array of offending AVPs
*/
protected static ArrayList<String> checkAvpFlags(AvpSet set) {
ArrayList<String> failedAvps = new ArrayList<String>();
for (Avp avp : set) {
// System.out.println(avp.getVendorId() + ":" + avp.getCode() + " V[" + avp.isVendorId() + "] M[" +
// avp.isMandatory() + "] P[" + avp.isEncrypted() + "]");
AvpRepresentation avpRep = DictionaryImpl.INSTANCE.getAvp(avp.getCode(), avp.getVendorId());
// Mandatory must not be set if rule is MUST NOT or SHOULD NOT
if (avp.isMandatory() && (avpRep.getRuleMandatory().equals("mustnot") || avpRep.getRuleMandatory().equals("shouldnot"))) {
failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[M / '" + avp.isMandatory() + "' vs '" + avpRep.getRuleMandatory() + "']");
}
// Protected must not be set if rule is MUST or MAY
if (avp.isEncrypted() && !(avpRep.getRuleProtected().equals("must") || avpRep.getRuleProtected().equals("may"))) {
failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[P / '" + avp.isEncrypted() + "' vs '" + avpRep.getRuleProtected() + "']");
}
// Vendor must be set if rule is MUST or MAY
if (avp.isEncrypted() && !(avpRep.getRuleProtected().equals("must") || avpRep.getRuleProtected().equals("may"))) {
failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[P / '" + avp.isEncrypted() + "' vs '" + avpRep.getRuleProtected() + "']");
}
AvpSet subAvps = null;
try {
subAvps = avp.getGrouped();
} catch (Exception e) {
}
if (subAvps != null) {
failedAvps.addAll(checkAvpFlags(subAvps));
}
}
return failedAvps;
}
use of org.jdiameter.api.validation.AvpRepresentation in project jain-slee.diameter by RestComm.
the class AvpFlagsTest method checkAvpFlags.
/**
* @param set
* the set to check
* @return an array of offending AVPs
*/
protected ArrayList<String> checkAvpFlags(AvpSet set) {
ArrayList<String> failedAvps = new ArrayList<String>();
for (Avp avp : set) {
// System.out.println(avp.getVendorId() + ":" + avp.getCode() + " V[" + avp.isVendorId() + "] M[" +
// avp.isMandatory() + "] P[" + avp.isEncrypted() + "]");
AvpRepresentation avpRep = validator.getAvp(avp.getCode(), avp.getVendorId());
// Mandatory must not be set if rule is MUST NOT or SHOULD NOT
if (avp.isMandatory() && (avpRep.getRuleMandatory().equals("mustnot") || avpRep.getRuleMandatory().equals("shouldnot"))) {
failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[M / '" + avp.isMandatory() + "' vs '" + avpRep.getRuleMandatory() + "']");
}
// Protected must not be set if rule is MUST or MAY
if (avp.isEncrypted() && !(avpRep.getRuleProtected().equals("must") || avpRep.getRuleProtected().equals("may"))) {
failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[P / '" + avp.isEncrypted() + "' vs '" + avpRep.getRuleProtected() + "']");
}
// Vendor must be set if rule is MUST or MAY
if (avp.isEncrypted() && !(avpRep.getRuleProtected().equals("must") || avpRep.getRuleProtected().equals("may"))) {
failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[P / '" + avp.isEncrypted() + "' vs '" + avpRep.getRuleProtected() + "']");
}
AvpSet subAvps = null;
try {
subAvps = avp.getGrouped();
} catch (Exception e) {
}
if (subAvps != null) {
failedAvps.addAll(checkAvpFlags(subAvps));
}
}
return failedAvps;
}
use of org.jdiameter.api.validation.AvpRepresentation in project jain-slee.diameter by RestComm.
the class ValidatorImpl method validate.
/*
* (non-Javadoc)
*
* @see net.java.slee.resource.diameter.Validator#
* validate(net.java.slee.resource.diameter.base.events.avp.DiameterAvp)
*/
@Override
public void validate(DiameterAvp avp) throws AvpNotAllowedException {
Dictionary dictionary = DictionarySingleton.getDictionary();
if (dictionary.isConfigured() && dictionary.isEnabled()) {
AvpRepresentation rep = dictionary.getAvp(avp.getCode(), avp.getVendorId());
// check for grouped?
if (rep != null && rep.isGrouped()) {
try {
GroupedAvpImpl impl = (GroupedAvpImpl) avp;
rep.validate(impl.getGenericData());
} catch (ClassCastException cce) {
throw new AvpNotAllowedException("Failed to validate avp, its not grouped!", cce, avp.getCode(), avp.getVendorId());
}
}
}
}
Aggregations