Projet

Général

Profil

« Précédent | Suivant » 

Révision 96454bcd

Ajouté par Sylvain Sauvage il y a plus de 11 ans

Version 1.9-mock

This is version 1.9-mock. 1.9 because the API still have changes pending
(principally relative to the Discovery Services). “mock” because TLS
configuration is not yet available and the signatures (SigMa) are not fully
implemented.

  • All:
    - code cleaned and refactored
    - lots of bugs fixed
    - dependencies checked and trimmed
    - documentation added
    - Identity handling added
  • New library modules (Mu, Nu)
  • New signature modules (SigMa)
  • Access Layer and User interfaces (ALfA and OMeGa):
    - code refactored
    - new, better APIs
    - Identity handling added
    - use EPCglobal and DS events (no proxy types anymore)
  • New tempororay DSeTa web service (pending new DS)
  • ETa corrected and added to the IoTa-Installer
    - ETa-Callback modules are now available as web applications
    - filtering rules: if a part of an event is not allowed, now the whole
    event is deleted from the result (before only the rejectd part was)
  • CaPPa: overall refactoring of XACML handling
    - new temporary User web service
    - new Xi module: XACML Interrogation web service (was two modules: TCP and
    servlet)
  • PSi now signs its events
  • Installer, now also installs or configures:
    - ETa and its Callback modules
    - ActiveMQ
    - SigMa
    - certificate/signing key
  • Greyc letters figures:
    - new simplified figures (sans IoTa and simplified IoTa)
    - new figure for ETa modules
    - show 3rd party clients
    - data flows specified
    - TLS and link security added
    - IDs and trusted IDs added
    - color adjusted for printing
    - GREYC logo added

Voir les différences:

ETa/ETa-Callback/ETa-Callback-Filter/src/main/java/fr/unicaen/iota/eta/callback/filter/CallbackCheck.java
/*
* This program is a part of the IoTa Project.
*
* Copyright © 2008-2012 Université de Caen Basse-Normandie, GREYC
* Copyright © 2011-2012 Université de Caen Basse-Normandie, GREYC
* Copyright © 2011 Orange Labs
*
* This program is free software: you can redistribute it and/or modify
......
*/
package fr.unicaen.iota.eta.callback.filter;
import com.sun.xacml.ctx.Result;
import fr.unicaen.iota.eta.callback.filter.xacml.EPCISPEP;
import fr.unicaen.iota.xacml.XACMLConstantsEventType;
import fr.unicaen.iota.xacml.pep.ExtensionEvent;
import fr.unicaen.iota.xacml.pep.XACMLEPCISEvent;
import fr.unicaen.iota.xi.client.EPCISPEP;
import fr.unicaen.iota.xi.utils.Utils;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.fosstrak.epcis.repository.model.*;
import org.fosstrak.epcis.model.AggregationEventType;
import org.fosstrak.epcis.model.BusinessTransactionType;
import org.fosstrak.epcis.model.EPC;
import org.fosstrak.epcis.model.EPCISEventType;
import org.fosstrak.epcis.model.ObjectEventType;
import org.fosstrak.epcis.model.QuantityEventType;
import org.fosstrak.epcis.model.TransactionEventType;
import org.fosstrak.epcis.utils.TimeParser;
import org.w3c.dom.Element;
/**
* This CallbackCheck class initializes the EPCIS PEP to send XACML request to
......
private EPCISPEP epcisPEP;
public CallbackCheck() {
epcisPEP = new EPCISPEP();
epcisPEP = new EPCISPEP(Constants.XACML_URL);
}
public boolean xacmlCheck(XACMLEPCISEvent xacmlEvent, String user) {
int baseEventResponse = epcisPEP.queryEvent(user, xacmlEvent, "Query");
if (baseEventResponse == Result.DECISION_PERMIT) {
return true;
}
return false;
int xacmlResponse = epcisPEP.queryEvent(user, xacmlEvent);
return Utils.responseIsPermit(xacmlResponse);
}
/**
* Checks the callback events by XACML requests to the XACML module.
*
* @param baseEventList The callback events.
* @return
* <code>true</code> if the callback is permitted.
* @param epcisEventList The callback events.
* @param user The user name.
* @return <code>true</code> if the callback is permitted.
*/
public boolean xacmlCheck(List<BaseEvent> baseEventList, String user) {
Iterator<BaseEvent> iterBaseEvent = baseEventList.iterator();
boolean decisionPermit = true;
while (iterBaseEvent.hasNext() && decisionPermit) {
BaseEvent baseEvent = iterBaseEvent.next();
// TODO: owner + user
String owner = null;
if (baseEvent instanceof AggregationEvent) {
decisionPermit = aggregationCallbackCheck((AggregationEvent) baseEvent, user, owner);
} else if (baseEvent instanceof ObjectEvent) {
decisionPermit = objectCallbackCheck((ObjectEvent) baseEvent, user, owner);
} else if (baseEvent instanceof QuantityEvent) {
decisionPermit = quantityCallbackCheck((QuantityEvent) baseEvent, user, owner);
} else if (baseEvent instanceof TransactionEvent) {
decisionPermit = transactionCallbackCheck((TransactionEvent) baseEvent, user, owner);
public boolean xacmlCheck(List<EPCISEventType> epcisEventList, String user) {
for (EPCISEventType epcisEvent : epcisEventList) {
String owner = "anonymous";
if (epcisEvent instanceof ObjectEventType) {
if (!checkObjectEvent((ObjectEventType) epcisEvent, user, owner)) {
return false;
}
} else if (epcisEvent instanceof AggregationEventType) {
if (!checkAggregationEvent((AggregationEventType) epcisEvent, user, owner)) {
return false;
}
} else if (epcisEvent instanceof QuantityEventType) {
if (!checkQuantityEvent((QuantityEventType) epcisEvent, user, owner)) {
return false;
}
} else if (epcisEvent instanceof TransactionEventType) {
if (!checkTransactionEvent((TransactionEventType) epcisEvent, user, owner)) {
return false;
}
}
}
return decisionPermit;
return true;
}
/**
* Checks an aggregation callback event.
*
* @param baseEvent The aggregation callback event to check.
* @return
* <code>true</code> if the aggregation callback event is permitted.
* @param user The user name.
* @return <code>true</code> if the aggregation callback event is permitted.
*/
private boolean aggregationCallbackCheck(AggregationEvent aggregationEvent, String user, String owner) {
Date eventTime = aggregationEvent.getEventTime();
Date recordTime = aggregationEvent.getRecordTime();
private boolean checkAggregationEvent(AggregationEventType aggregationEvent, String user, String owner) {
Date eventTime = (aggregationEvent.getEventTime() != null) ? aggregationEvent.getEventTime().toGregorianCalendar().getTime() : null;
Date recordTime = (aggregationEvent.getRecordTime() != null) ? aggregationEvent.getRecordTime().toGregorianCalendar().getTime() : null;
String eventType = XACMLConstantsEventType.AGGREGATION;
String readPoint = (aggregationEvent.getReadPoint() != null) ? aggregationEvent.getReadPoint().getUri() : null;
String bizLoc = (aggregationEvent.getBizLocation() != null) ? aggregationEvent.getBizLocation().getUri() : null;
String bizStep = (aggregationEvent.getBizStep() != null) ? aggregationEvent.getBizStep().getUri() : null;
String operation = (aggregationEvent.getAction() != null) ? aggregationEvent.getAction().name() : null;
String disposition = (aggregationEvent.getDisposition() != null) ? aggregationEvent.getDisposition().getUri() : null;
String parentId = aggregationEvent.getParentId();
String operation = (aggregationEvent.getAction() != null) ? aggregationEvent.getAction().value() : null;
String readPoint = (aggregationEvent.getReadPoint() != null) ? aggregationEvent.getReadPoint().getId() : null;
String bizLoc = (aggregationEvent.getBizLocation() != null) ? aggregationEvent.getBizLocation().getId() : null;
String bizStep = aggregationEvent.getBizStep();
String disposition = aggregationEvent.getDisposition();
String parentId = aggregationEvent.getParentID();
Long quantity = null;
String epc = null;
String childEpc = null;
String bizTrans = null;
ExtensionEvent extension = null;
boolean onePermit = false;
if (aggregationEvent.getChildEpcs() == null || aggregationEvent.getChildEpcs().isEmpty()) {
if (aggregationEvent.getBizTransList() == null || aggregationEvent.getBizTransList().isEmpty()) {
if (aggregationEvent.getChildEPCs() == null || aggregationEvent.getChildEPCs().getEpc() == null || aggregationEvent.getChildEPCs().getEpc().isEmpty()) {
if (aggregationEvent.getBizTransactionList() == null || aggregationEvent.getBizTransactionList().getBizTransaction() == null
|| aggregationEvent.getBizTransactionList().getBizTransaction().isEmpty()) {
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
} else {
Iterator<BusinessTransaction> iterBizTrans = aggregationEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getBizTransaction().getUri();
for (BusinessTransactionType bizTransType : aggregationEvent.getBizTransactionList().getBizTransaction()) {
bizTrans = bizTransType.getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
} else {
iterBizTrans.remove();
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
}
} else {
if (aggregationEvent.getBizTransList() == null || aggregationEvent.getBizTransList().isEmpty()) {
Iterator<String> iterChildEpc = aggregationEvent.getChildEpcs().iterator();
while (iterChildEpc.hasNext()) {
childEpc = iterChildEpc.next();
if (aggregationEvent.getBizTransactionList() == null || aggregationEvent.getBizTransactionList().getBizTransaction() == null
|| aggregationEvent.getBizTransactionList().getBizTransaction().isEmpty()) {
for (EPC epcType : aggregationEvent.getChildEPCs().getEpc()) {
childEpc = epcType.getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
} else {
iterChildEpc.remove();
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
} else {
String allowedChildEpc = null;
String allowedBizTrans = null;
Iterator<String> iterChildEpc = aggregationEvent.getChildEpcs().iterator();
while (iterChildEpc.hasNext()) {
childEpc = iterChildEpc.next();
Iterator<BusinessTransaction> iterBizTrans = aggregationEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getBizTransaction().getUri();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
allowedChildEpc = childEpc;
allowedBizTrans = bizTrans;
onePermit = true;
break;
}
Iterator<BusinessTransactionType> iterBizTransType = aggregationEvent.getBizTransactionList().getBizTransaction().iterator();
for (EPC epcType : aggregationEvent.getChildEPCs().getEpc()) {
childEpc = epcType.getValue();
if (iterBizTransType.hasNext()) {
bizTrans = iterBizTransType.next().getValue();
}
if (allowedChildEpc == null) {
iterChildEpc.remove();
} else {
break;
}
}
if (allowedChildEpc != null) {
Iterator<BusinessTransaction> iterBizTrans = aggregationEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getBizTransaction().getUri();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
iterBizTrans.remove();
}
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
if (allowedBizTrans != null) {
iterChildEpc = aggregationEvent.getChildEpcs().iterator();
while (iterChildEpc.hasNext()) {
childEpc = iterChildEpc.next();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
iterChildEpc.remove();
}
while (iterBizTransType.hasNext()) {
bizTrans = iterBizTransType.next().getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
}
}
if (onePermit) {
bizTrans = null;
childEpc = null;
Iterator<EventFieldExtension> iter = aggregationEvent.getExtensions().iterator();
while (iter.hasNext()) {
EventFieldExtension extensionField = iter.next();
String extensionId = extensionField.getFieldname();
String extensionValueType = extensionField.getValueColumnName();
Object extensionValue = null;
childEpc = null;
bizTrans = null;
for (Object obj: aggregationEvent.getAny()) {
Element element = (Element) obj;
String namespace = element.getNamespaceURI();
String extensionName = element.getLocalName();
String value = element.getTextContent();
// Gets the extension value
Object extensionValue = null;
try {
extensionValue = new Integer(Integer.parseInt(value));
} catch (Exception ex) {
// Extension value is not an integer
try {
if ("intValue".equals(extensionValueType)) {
extensionValue = new Integer(extensionField.getIntValue());
} else if ("floatValue".equals(extensionValueType)) {
extensionValue = new Float(extensionField.getFloatValue());
} else if ("dateValue".equals(extensionValueType)) {
extensionValue = new Date(extensionField.getDateValue().getTime());
} else if ("strValue".equals(extensionValueType)) {
extensionValue = extensionField.getStrValue();
} else {
iter.remove();
continue;
extensionValue = new Float(Float.parseFloat(value));
} catch (Exception exF) {
// Extension value is not a float
try {
extensionValue = new Double(Double.parseDouble(value));
} catch (Exception exD) {
// Extension value is not a double
try {
extensionValue = TimeParser.parseAsDate(value);
} catch (Exception exP) {
// Extension value is not a date
}
}
} catch (Exception ex) {
iter.remove();
continue;
}
extension = new ExtensionEvent(extensionId, extensionValue);
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
iter.remove();
}
}
// Extension value is a string
if (extensionValue == null) {
extensionValue = value;
}
extension = new ExtensionEvent(namespace, extensionName, extensionValue);
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
return onePermit;
return true;
}
/**
* Checks an object callback event.
*
* @param objectEvent The object callback event to check.
* @return
* <code>true</code> if the object callback event is permitted.
* @param user The user name.
* @return <code>true</code> if the object callback event is permitted.
*/
private boolean objectCallbackCheck(ObjectEvent objectEvent, String user, String owner) {
String readPoint = (objectEvent.getReadPoint() != null) ? objectEvent.getReadPoint().getUri() : null;
String bizLoc = (objectEvent.getBizLocation() != null) ? objectEvent.getBizLocation().getUri() : null;
String bizStep = (objectEvent.getBizStep() != null) ? objectEvent.getBizStep().getUri() : null;
Date eventTime = objectEvent.getEventTime();
Date recordTime = objectEvent.getRecordTime();
String operation = (objectEvent.getAction() != null) ? objectEvent.getAction().name() : null;
private boolean checkObjectEvent(ObjectEventType objectEvent, String user, String owner) {
Date eventTime = (objectEvent.getEventTime() != null) ? objectEvent.getEventTime().toGregorianCalendar().getTime() : null;
Date recordTime = (objectEvent.getRecordTime() != null) ? objectEvent.getRecordTime().toGregorianCalendar().getTime() : null;
String eventType = XACMLConstantsEventType.OBJECT;
String disposition = (objectEvent.getDisposition() != null) ? objectEvent.getDisposition().getUri() : null;
String bizStep = objectEvent.getBizStep();
String operation = (objectEvent.getAction() != null) ? objectEvent.getAction().value() : null;
String bizLoc = (objectEvent.getBizLocation() != null) ? objectEvent.getBizLocation().getId() : null;
String readPoint = (objectEvent.getReadPoint() != null) ? objectEvent.getReadPoint().getId() : null;
String disposition = objectEvent.getDisposition();
Long quantity = null;
String parentId = null;
String childEpc = null;
Long quantity = null;
String epc = null;
String bizTrans = null;
ExtensionEvent extension = null;
boolean onePermit = false;
if (objectEvent.getEpcList() == null || objectEvent.getEpcList().isEmpty()) {
if (objectEvent.getBizTransList() == null || objectEvent.getBizTransList().isEmpty()) {
if (objectEvent.getEpcList().getEpc() == null || objectEvent.getEpcList().getEpc().isEmpty()) {
if (objectEvent.getBizTransactionList() == null || objectEvent.getBizTransactionList().getBizTransaction() == null
|| objectEvent.getBizTransactionList().getBizTransaction().isEmpty()) {
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
} else {
Iterator<BusinessTransaction> iterBizTrans = objectEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getBizTransaction().getUri();
for (BusinessTransactionType bizTransType : objectEvent.getBizTransactionList().getBizTransaction()) {
bizTrans = bizTransType.getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
} else {
iterBizTrans.remove();
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
}
} else {
if (objectEvent.getBizTransList() == null || objectEvent.getBizTransList().isEmpty()) {
Iterator<String> iterEpc = objectEvent.getEpcList().iterator();
while (iterEpc.hasNext()) {
epc = iterEpc.next();
if (objectEvent.getBizTransactionList() == null || objectEvent.getBizTransactionList().getBizTransaction() == null
|| objectEvent.getBizTransactionList().getBizTransaction().isEmpty()) {
for (EPC epcType : objectEvent.getEpcList().getEpc()) {
epc = epcType.getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
} else {
iterEpc.remove();
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
} else {
String allowedEpc = null;
String allowedBizTrans = null;
Iterator<String> iterEpc = objectEvent.getEpcList().iterator();
while (iterEpc.hasNext()) {
epc = iterEpc.next();
Iterator<BusinessTransaction> iterBizTrans = objectEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getBizTransaction().getUri();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
allowedEpc = epc;
allowedBizTrans = bizTrans;
onePermit = true;
break;
}
Iterator<BusinessTransactionType> iterBizTransType = objectEvent.getBizTransactionList().getBizTransaction().iterator();
for (EPC epcType : objectEvent.getEpcList().getEpc()) {
epc = epcType.getValue();
if (iterBizTransType.hasNext()) {
bizTrans = iterBizTransType.next().getValue();
}
if (allowedEpc == null) {
iterEpc.remove();
} else {
break;
}
}
if (allowedEpc != null) {
Iterator<BusinessTransaction> iterBizTrans = objectEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getBizTransaction().getUri();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
iterBizTrans.remove();
}
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
if (allowedBizTrans != null) {
iterEpc = objectEvent.getEpcList().iterator();
while (iterEpc.hasNext()) {
epc = iterEpc.next();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
iterEpc.remove();
}
while (iterBizTransType.hasNext()) {
bizTrans = iterBizTransType.next().getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
}
}
if (onePermit) {
epc = null;
bizTrans = null;
Iterator<EventFieldExtension> iter = objectEvent.getExtensions().iterator();
while (iter.hasNext()) {
EventFieldExtension extensionField = iter.next();
String extensionId = extensionField.getFieldname();
String extensionValueType = extensionField.getValueColumnName();
Object extensionValue = null;
epc = null;
bizTrans = null;
for (Object obj : objectEvent.getAny()) {
Element element = (Element) obj;
String namespace = element.getNamespaceURI();
String extensionName = element.getLocalName();
String value = element.getTextContent();
// Gets the extension value
Object extensionValue = null;
try {
extensionValue = new Integer(Integer.parseInt(value));
} catch (Exception ex) {
// Extension value is not an integer
try {
if ("intValue".equals(extensionValueType)) {
extensionValue = new Integer(extensionField.getIntValue());
} else if ("floatValue".equals(extensionValueType)) {
extensionValue = new Float(extensionField.getFloatValue());
} else if ("dateValue".equals(extensionValueType)) {
extensionValue = new Date(extensionField.getDateValue().getTime());
} else if ("strValue".equals(extensionValueType)) {
extensionValue = extensionField.getStrValue();
} else {
iter.remove();
continue;
extensionValue = new Float(Float.parseFloat(value));
} catch (Exception exF) {
// Extension value is not a float
try {
extensionValue = new Double(Double.parseDouble(value));
} catch (Exception exD) {
// Extension value is not a double
try {
extensionValue = TimeParser.parseAsDate(value);
} catch (Exception exP) {
// Extension value is not a date
}
}
} catch (Exception ex) {
iter.remove();
continue;
}
extension = new ExtensionEvent(extensionId, extensionValue);
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
iter.remove();
}
}
// Extension value is a string
if (extensionValue == null) {
extensionValue = value;
}
extension = new ExtensionEvent(namespace, extensionName, extensionValue);
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
return onePermit;
return true;
}
/**
* Checks an quantity callback event.
*
* @param quantityEvent The quantity callback event to check.
* @return
* <code>true</code> if the quantity callback event is permitted.
* @param user The user name.
* @return <code>true</code> if the quantity callback event is permitted.
*/
private boolean quantityCallbackCheck(QuantityEvent quantityEvent, String user, String owner) {
String readPoint = (quantityEvent.getReadPoint() != null) ? quantityEvent.getReadPoint().getUri() : null;
String bizLoc = (quantityEvent.getBizLocation() != null) ? quantityEvent.getBizLocation().getUri() : null;
String bizStep = (quantityEvent.getBizStep() != null) ? quantityEvent.getBizStep().getUri() : null;
Date eventTime = quantityEvent.getEventTime();
Date recordTime = quantityEvent.getRecordTime();
private boolean checkQuantityEvent(QuantityEventType quantityEvent, String user, String owner) {
Date eventTime = (quantityEvent.getEventTime() != null) ? quantityEvent.getEventTime().toGregorianCalendar().getTime() : null;
Date recordTime = (quantityEvent.getRecordTime() != null) ? quantityEvent.getRecordTime().toGregorianCalendar().getTime() : null;
String eventType = XACMLConstantsEventType.QUANTITY;
String disposition = (quantityEvent.getDisposition() != null) ? quantityEvent.getDisposition().getUri() : null;
Long quantity = quantityEvent.getQuantity();
String epc = (quantityEvent.getEpcClass() != null) ? quantityEvent.getEpcClass().getUri() : null;
String readPoint = (quantityEvent.getReadPoint() != null) ? quantityEvent.getReadPoint().getId() : null;
String bizLoc = (quantityEvent.getBizLocation() != null) ? quantityEvent.getBizLocation().getId() : null;
String bizStep = quantityEvent.getBizStep();
String disposition = quantityEvent.getDisposition();
String epc = quantityEvent.getEpcClass();
Long quantity = new Long(quantityEvent.getQuantity());
String operation = null;
String parentId = null;
String childEpc = null;
String bizTrans = null;
ExtensionEvent extension = null;
boolean onePermit = false;
Iterator<BusinessTransaction> iterBizTrans = quantityEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getType().getUri();
if (quantityEvent.getBizTransactionList() == null || quantityEvent.getBizTransactionList().getBizTransaction() == null
|| quantityEvent.getBizTransactionList().getBizTransaction().isEmpty()) {
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
} else {
iterBizTrans.remove();
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
if (onePermit) {
bizTrans = null;
Iterator<EventFieldExtension> iter = quantityEvent.getExtensions().iterator();
while (iter.hasNext()) {
EventFieldExtension extensionField = iter.next();
String extensionId = extensionField.getFieldname();
String extensionValueType = extensionField.getValueColumnName();
Object extensionValue = null;
try {
if ("intValue".equals(extensionValueType)) {
extensionValue = new Integer(extensionField.getIntValue());
} else if ("floatValue".equals(extensionValueType)) {
extensionValue = new Float(extensionField.getFloatValue());
} else if ("dateValue".equals(extensionValueType)) {
extensionValue = new Date(extensionField.getDateValue().getTime());
} else if ("strValue".equals(extensionValueType)) {
extensionValue = extensionField.getStrValue();
} else {
iter.remove();
continue;
}
} catch (Exception ex) {
iter.remove();
continue;
}
extension = new ExtensionEvent(extensionId, extensionValue);
} else {
for (BusinessTransactionType bizTransType : quantityEvent.getBizTransactionList().getBizTransaction()) {
bizTrans = bizTransType.getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
iter.remove();
return false;
}
}
}
return onePermit;
bizTrans = null;
for (Object obj : quantityEvent.getAny()) {
Element element = (Element) obj;
String namespace = element.getNamespaceURI();
String extensionName = element.getLocalName();
String value = element.getTextContent();
// Gets the extension value
Object extensionValue = null;
try {
extensionValue = new Integer(Integer.parseInt(value));
} catch (Exception ex) {
// Extension value is not an integer
try {
extensionValue = new Float(Float.parseFloat(value));
} catch (Exception exF) {
// Extension value is not a float
try {
extensionValue = new Double(Double.parseDouble(value));
} catch (Exception exD) {
// Extension value is not a double
try {
extensionValue = TimeParser.parseAsDate(value);
} catch (Exception exP) {
// Extension value is not a date
}
}
}
}
// Extension value is a string
if (extensionValue == null) {
extensionValue = value;
}
extension = new ExtensionEvent(namespace, extensionName, extensionValue);
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
return true;
}
/**
* Checks a transaction callback event.
*
* @param transactionEvent The transaction callback event to check.
* @return
* <code>true</code> if the transaction callback event is permitted.
* @param user The user name.
* @return <code>true</code> if the transaction callback event is permitted.
*/
private boolean transactionCallbackCheck(TransactionEvent transactionEvent, String user, String owner) {
String readPoint = (transactionEvent.getReadPoint() != null) ? transactionEvent.getReadPoint().getUri() : null;
String bizLoc = (transactionEvent.getBizLocation() != null) ? transactionEvent.getBizLocation().getUri() : null;
String bizStep = (transactionEvent.getBizStep() != null) ? transactionEvent.getBizStep().getUri() : null;
Date eventTime = transactionEvent.getEventTime();
Date recordTime = transactionEvent.getRecordTime();
String operation = (transactionEvent.getAction() != null) ? transactionEvent.getAction().name() : null;
private boolean checkTransactionEvent(TransactionEventType transactionEvent, String user, String owner) {
Date eventTime = (transactionEvent.getEventTime() != null) ? transactionEvent.getEventTime().toGregorianCalendar().getTime() : null;
Date recordTime = (transactionEvent.getRecordTime() != null) ? transactionEvent.getRecordTime().toGregorianCalendar().getTime() : null;
String eventType = XACMLConstantsEventType.TRANSACTION;
String disposition = (transactionEvent.getDisposition() != null) ? transactionEvent.getDisposition().getUri() : null;
String parentId = transactionEvent.getParentId();
String operation = (transactionEvent.getAction() != null) ? transactionEvent.getAction().value() : null;
String readPoint = (transactionEvent.getReadPoint() != null) ? transactionEvent.getReadPoint().getId() : null;
String bizLoc = (transactionEvent.getBizLocation() != null) ? transactionEvent.getBizLocation().getId() : null;
String bizStep = transactionEvent.getBizStep();
String disposition = transactionEvent.getDisposition();
String parentId = transactionEvent.getParentID();
Long quantity = null;
String childEpc = null;
String epc = null;
String bizTrans = null;
ExtensionEvent extension = null;
boolean onePermit = false;
if (transactionEvent.getEpcList() == null || transactionEvent.getEpcList().isEmpty()) {
if (transactionEvent.getBizTransList() == null || transactionEvent.getBizTransList().isEmpty()) {
if (transactionEvent.getEpcList() == null || transactionEvent.getEpcList().getEpc() == null || transactionEvent.getEpcList().getEpc().isEmpty()) {
if (transactionEvent.getBizTransactionList() == null || transactionEvent.getBizTransactionList().getBizTransaction() == null
|| transactionEvent.getBizTransactionList().getBizTransaction().isEmpty()) {
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
} else {
Iterator<BusinessTransaction> iterBizTrans = transactionEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getBizTransaction().getUri();
for (BusinessTransactionType bizTransType : transactionEvent.getBizTransactionList().getBizTransaction()) {
bizTrans = bizTransType.getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
} else {
iterBizTrans.remove();
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
}
} else {
if (transactionEvent.getBizTransList() == null || transactionEvent.getBizTransList().isEmpty()) {
Iterator<String> iterEpc = transactionEvent.getEpcList().iterator();
while (iterEpc.hasNext()) {
epc = iterEpc.next();
if (transactionEvent.getBizTransactionList() == null || transactionEvent.getBizTransactionList().getBizTransaction() == null
|| transactionEvent.getBizTransactionList().getBizTransaction().isEmpty()) {
for (EPC epcType : transactionEvent.getEpcList().getEpc()) {
epc = epcType.getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
onePermit = true;
} else {
iterEpc.remove();
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
} else {
String allowedEpc = null;
String allowedBizTrans = null;
Iterator<String> iterEpc = transactionEvent.getEpcList().iterator();
while (iterEpc.hasNext()) {
epc = iterEpc.next();
Iterator<BusinessTransaction> iterBizTrans = transactionEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getType().getUri();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (xacmlCheck(xacmlEvent, user)) {
allowedEpc = epc;
allowedBizTrans = bizTrans;
onePermit = true;
break;
}
}
if (allowedEpc == null) {
iterEpc.remove();
} else {
break;
Iterator<BusinessTransactionType> iterBizTransType = transactionEvent.getBizTransactionList().getBizTransaction().iterator();
for (EPC epcType : transactionEvent.getEpcList().getEpc()) {
epc = epcType.getValue();
if (iterBizTransType.hasNext()) {
bizTrans = iterBizTransType.next().getValue();
}
}
if (allowedEpc != null) {
Iterator<BusinessTransaction> iterBizTrans = transactionEvent.getBizTransList().iterator();
while (iterBizTrans.hasNext()) {
bizTrans = iterBizTrans.next().getType().getUri();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
iterBizTrans.remove();
}
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
if (allowedBizTrans != null) {
iterEpc = transactionEvent.getEpcList().iterator();
epc = iterEpc.next();
while (iterBizTransType.hasNext()) {
bizTrans = iterBizTransType.next().getValue();
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
iterEpc.remove();
return false;
}
}
}
}
if (onePermit) {
epc = null;
bizTrans = null;
Iterator<EventFieldExtension> iter = transactionEvent.getExtensions().iterator();
while (iter.hasNext()) {
EventFieldExtension extensionField = iter.next();
String extensionId = extensionField.getFieldname();
String extensionValueType = extensionField.getValueColumnName();
Object extensionValue = null;
epc = null;
bizTrans = null;
for (Object obj : transactionEvent.getAny()) {
Element element = (Element) obj;
String namespace = element.getNamespaceURI();
String extensionName = element.getLocalName();
String value = element.getTextContent();
// Gets the extension value
Object extensionValue = null;
try {
extensionValue = new Integer(Integer.parseInt(value));
} catch (Exception ex) {
// Extension value is not an integer
try {
if ("intValue".equals(extensionValueType)) {
extensionValue = new Integer(extensionField.getIntValue());
} else if ("floatValue".equals(extensionValueType)) {
extensionValue = new Float(extensionField.getFloatValue());
} else if ("dateValue".equals(extensionValueType)) {
extensionValue = new Date(extensionField.getDateValue().getTime());
} else if ("strValue".equals(extensionValueType)) {
extensionValue = extensionField.getStrValue();
} else {
iter.remove();
continue;
extensionValue = new Float(Float.parseFloat(value));
} catch (Exception exF) {
// Extension value is not a float
try {
extensionValue = new Double(Double.parseDouble(value));
} catch (Exception exD) {
// Extension value is not a double
try {
extensionValue = TimeParser.parseAsDate(value);
} catch (Exception exP) {
// Extension value is not a date
}
}
} catch (Exception ex) {
iter.remove();
continue;
}
extension = new ExtensionEvent(extensionId, extensionValue);
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
iter.remove();
}
}
// Extension value is a string
if (extensionValue == null) {
extensionValue = value;
}
extension = new ExtensionEvent(namespace, extensionName, extensionValue);
XACMLEPCISEvent xacmlEvent = new XACMLEPCISEvent(owner, bizStep, epc, eventTime, recordTime, operation,
eventType, parentId, childEpc, quantity, readPoint, bizLoc, bizTrans, disposition, extension);
if (!xacmlCheck(xacmlEvent, user)) {
return false;
}
}
return onePermit;
return true;
}
}

Formats disponibles : Unified diff