Search in sources :

Example 1 with AvpRepresentation

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;
}
Also used : ArrayList(java.util.ArrayList) AvpSet(org.jdiameter.api.AvpSet) VendorSpecificApplicationIdAvp(net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp) Avp(org.jdiameter.api.Avp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ExperimentalResultAvp(net.java.slee.resource.diameter.base.events.avp.ExperimentalResultAvp) ProxyInfoAvp(net.java.slee.resource.diameter.base.events.avp.ProxyInfoAvp) FailedAvp(net.java.slee.resource.diameter.base.events.avp.FailedAvp) AvpRepresentation(org.jdiameter.api.validation.AvpRepresentation) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with AvpRepresentation

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;
}
Also used : ArrayList(java.util.ArrayList) AvpSet(org.jdiameter.api.AvpSet) Avp(org.jdiameter.api.Avp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) AvpRepresentation(org.jdiameter.api.validation.AvpRepresentation) NoSuchAvpException(net.java.slee.resource.diameter.base.NoSuchAvpException)

Example 3 with AvpRepresentation

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());
            }
        }
    }
}
Also used : GroupedAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl) Dictionary(org.jdiameter.api.validation.Dictionary) AvpRepresentation(org.jdiameter.api.validation.AvpRepresentation) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)

Aggregations

AvpRepresentation (org.jdiameter.api.validation.AvpRepresentation)3 ArrayList (java.util.ArrayList)2 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)2 Avp (org.jdiameter.api.Avp)2 AvpSet (org.jdiameter.api.AvpSet)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NoSuchAvpException (net.java.slee.resource.diameter.base.NoSuchAvpException)1 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)1 ExperimentalResultAvp (net.java.slee.resource.diameter.base.events.avp.ExperimentalResultAvp)1 FailedAvp (net.java.slee.resource.diameter.base.events.avp.FailedAvp)1 ProxyInfoAvp (net.java.slee.resource.diameter.base.events.avp.ProxyInfoAvp)1 VendorSpecificApplicationIdAvp (net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp)1 Dictionary (org.jdiameter.api.validation.Dictionary)1 GroupedAvpImpl (org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl)1