// check the message, if it was treated with confidentiality and integrity
CryptDataHolder ctyptDataHolder = new CryptDataHolder(action, msgUnitRaw, null);
msgUnitRaw = sessionSecCtx.importMessage(ctyptDataHolder);
MsgUnit msgUnit = null;
try {
// Parse XML key and XML QoS
msgUnit = new MsgUnit(glob, msgUnitRaw.getKey(), msgUnitRaw.getContent(), msgUnitRaw.getQos(), action);
}
catch (XmlBlasterException e) {
// to log SaxParseException, all other exceptions are logged by AvailabilityChecker
if (!e.isInternal()) log.warning(e.getMessage() + ":\n" + msgUnitRaw.getKey() + "\n" + msgUnitRaw.getQos());
if (sessionInfo.getConnectQos().allowExceptionsThrownToClient()) {
throw e; // normal use case
}
else {
// e.g. if a dumb device (phone) can't cope with exception, handle it server side
MsgErrorInfo msgErrorInfo = new MsgErrorInfo(glob, sessionInfo.getSessionName(), msgUnitRaw, e);
sessionInfo.getMsgErrorHandler().handleError(msgErrorInfo);
}
}
QosData qosData = msgUnit.getQosData();
// Currently we have misused used the clientProperty to transport this information
if (qosData.getClientProperty(Constants.PERSISTENCE_ID) != null)
qosData.isFromPersistenceRecovery(true);
// Check if server is ready (throws XmlBlasterException otherwise)
this.availabilityChecker.checkServerIsReady(sessionInfo.getSessionName(), addressServer, msgUnit, action);
// Protect against faked sender name
if (sessionInfo.getConnectQos().isClusterNode()) {
if (qosData.getSender() == null) // In cluster routing don't overwrite the original sender
qosData.setSender(sessionInfo.getSessionName());
}
else {
if (qosData.getSender() == null) {
qosData.setSender(sessionInfo.getSessionName());
}
else if (!sessionInfo.getSessionName().equalsAbsolute(qosData.getSender())) {
//if (! publishQos.isFromPersistenceStore()) {
if (!this.authenticate.isAcceptWrongSenderAddress(sessionInfo)) {
log.warning(sessionInfo.getId() + " sends message '" + msgUnit.getKeyOid() + "' with invalid sender name '" + qosData.getSender() + "', we fix this");
qosData.setSender(sessionInfo.getSessionName());
}
else {
log.info(sessionInfo.getId() + " sends message '" + msgUnit.getKeyOid() + "' with invalid sender name '" + qosData.getSender() + "', we accept it");
}
}
}
/*
msgUnitRaw = new MsgUnitRaw(
(msgUnit.getKey().size() > 0) ? sessionSecCtx.importMessage(msgUnit.getKey()) : msgUnit.getKey(),
(msgUnit.getContent().length > 0) ? sessionSecCtx.importMessage(msgUnit.getContent()) : msgUnit.getContent(),
(msgUnit.getQos().size() > 0) ? sessionSecCtx.importMessage(msgUnit.getQos()) : msgUnit.getQos());
*/
// check if this user is permitted to do this action with this message
I_Subject subjSecCtx = sessionSecCtx.getSubject();
SessionHolder sessionHolder = new SessionHolder(sessionInfo, addressServer);
DataHolder dataHolder = new DataHolder(action, msgUnit);
if (!sessionSecCtx.isAuthorized(sessionHolder, dataHolder)) {
String key = (msgUnit.getKeyData()==null) ? msgUnit.getKey() : msgUnit.getKeyData().getUrl();
throw new XmlBlasterException(glob, ErrorCode.USER_SECURITY_AUTHORIZATION_NOTAUTHORIZED, ME,
"Subject '" + subjSecCtx.getName() + "' is not permitted to perform action '" + action +
"' on key '" + key + "'" +
((dataHolder.getNotAuthorizedInfo()==null)?"":": "+dataHolder.getNotAuthorizedInfo()));
}