Skip to content

Commit

Permalink
Device management operations with no account:read permission fixed
Browse files Browse the repository at this point in the history
Fix for #1039, #1040, #1041, #1042 and #1043

Signed-off-by: Claudio Mezzasalma <claudio.mezzasalma@eurotech.com>
  • Loading branch information
Claudio Mezzasalma committed Nov 22, 2017
1 parent 5185ece commit 7b217fc
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.xml.stream.XMLStreamException;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.util.ArgumentValidator;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.locator.KapuaProvider;
Expand Down Expand Up @@ -120,7 +121,7 @@ public DeviceAssets get(KapuaId scopeId, KapuaId deviceId, DeviceAssets deviceAs
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return deviceAssetsResponse;
}
Expand Down Expand Up @@ -190,7 +191,7 @@ public DeviceAssets read(KapuaId scopeId, KapuaId deviceId, DeviceAssets deviceA
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return deviceAssetsResponse;
}
Expand Down Expand Up @@ -260,7 +261,7 @@ public DeviceAssets write(KapuaId scopeId, KapuaId deviceId, DeviceAssets device
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return deviceAssetsResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Date;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.util.ArgumentValidator;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.locator.KapuaLocator;
Expand Down Expand Up @@ -123,7 +124,7 @@ public DeviceBundles get(KapuaId scopeId, KapuaId deviceId, Long timeout)
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return deviceBundleList;
}
Expand Down Expand Up @@ -180,7 +181,7 @@ public void start(KapuaId scopeId, KapuaId deviceId, String bundleId, Long timeo
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}

@SuppressWarnings({ "unchecked", "rawtypes" })
Expand Down Expand Up @@ -235,7 +236,7 @@ public void stop(KapuaId scopeId, KapuaId deviceId, String bundleId, Long timeou
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Date;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.util.ArgumentValidator;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.locator.KapuaProvider;
Expand Down Expand Up @@ -108,7 +109,7 @@ public DeviceCommandOutput exec(KapuaId scopeId, KapuaId deviceId, DeviceCommand
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

//
// Parse the response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.KapuaIllegalArgumentException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.util.ArgumentValidator;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.locator.KapuaLocator;
Expand Down Expand Up @@ -136,7 +137,7 @@ public DeviceConfiguration get(KapuaId scopeId, KapuaId deviceId, String configu
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return deviceConfiguration;
}
Expand Down Expand Up @@ -210,7 +211,7 @@ public void put(KapuaId scopeId, KapuaId deviceId, DeviceComponentConfiguration
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

}

Expand Down Expand Up @@ -291,6 +292,6 @@ public void put(KapuaId scopeId, KapuaId deviceId, DeviceConfiguration deviceCon
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Date;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.util.ArgumentValidator;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.locator.KapuaLocator;
Expand Down Expand Up @@ -125,7 +126,7 @@ public DeviceSnapshots get(KapuaId scopeId, KapuaId deviceId, Long timeout)
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return deviceSnapshots;
}
Expand Down Expand Up @@ -181,6 +182,6 @@ public void rollback(KapuaId scopeId, KapuaId deviceId, String snapshotId, Long
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.model.id.IdGenerator;
import org.eclipse.kapua.commons.model.id.KapuaEid;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.util.ArgumentValidator;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.locator.KapuaLocator;
Expand Down Expand Up @@ -143,7 +144,7 @@ public DevicePackages getInstalled(KapuaId scopeId, KapuaId deviceId, Long timeo
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return devicePackages;
}
Expand Down Expand Up @@ -213,7 +214,7 @@ public void downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloa
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}

@Override
Expand Down Expand Up @@ -266,7 +267,7 @@ public void downloadStop(KapuaId scopeId, KapuaId deviceId, Long timeout)
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}

@Override
Expand Down Expand Up @@ -328,7 +329,7 @@ public DevicePackageDownloadOperation downloadStatus(KapuaId scopeId, KapuaId de
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return downloadOperation;
}
Expand Down Expand Up @@ -393,7 +394,7 @@ public void installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallR
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

}

Expand Down Expand Up @@ -470,7 +471,7 @@ public DevicePackageInstallOperation installStatus(KapuaId scopeId, KapuaId devi
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return installOperation;
}
Expand Down Expand Up @@ -534,7 +535,7 @@ public void uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninst
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}

@Override
Expand Down Expand Up @@ -610,7 +611,7 @@ public DevicePackageUninstallOperation uninstallStatus(KapuaId scopeId, KapuaId
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return uninstallOperation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.kapua.service.device.registry.lifecycle.internal;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.locator.KapuaProvider;
import org.eclipse.kapua.message.KapuaPayload;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void birth(KapuaId connectionId, KapuaBirthMessage message)
deviceEventCreator.setPosition(position);
}

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}

@Override
Expand Down Expand Up @@ -151,7 +152,7 @@ public void death(KapuaId connectionId, KapuaDisconnectMessage message)
deviceEventCreator.setPosition(position);
}

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}

@Override
Expand Down Expand Up @@ -183,7 +184,7 @@ public void missing(KapuaId connectionId, KapuaMissingMessage message)
deviceEventCreator.setPosition(position);
}

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

}

Expand Down Expand Up @@ -216,6 +217,6 @@ public void applications(KapuaId connectionId, KapuaAppsMessage message)
deviceEventCreator.setPosition(position);
}

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.kapua.KapuaErrorCodes;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.KapuaRuntimeException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.util.ArgumentValidator;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.locator.KapuaProvider;
Expand Down Expand Up @@ -115,7 +116,7 @@ public GenericResponseMessage exec(
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());

deviceEventService.create(deviceEventCreator);
KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator));

return responseMessage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.kapua.translator.kapua.kura;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.message.KapuaChannel;
import org.eclipse.kapua.message.KapuaMessage;
Expand Down Expand Up @@ -41,7 +42,7 @@ public KuraRequestMessage translate(FROM_M kapuaMessage) throws KapuaException {
// Kura channel
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(kapuaMessage.getScopeId());
Account account = KapuaSecurityUtils.doPrivileged(() -> accountService.find(kapuaMessage.getScopeId()));

Device device = null;
DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.message.KapuaChannel;
import org.eclipse.kapua.message.KapuaMessage;
Expand All @@ -32,7 +33,7 @@ public TO_M translate(KuraResponseMessage kuraMessage) throws KapuaException {

final KapuaLocator locator = KapuaLocator.getInstance();
final AccountService accountService = locator.getService(AccountService.class);
final Account account = accountService.findByName(kuraMessage.getChannel().getScope());
final Account account = KapuaSecurityUtils.doPrivileged(() -> accountService.findByName(kuraMessage.getChannel().getScope()));

if (account == null) {
throw new KapuaEntityNotFoundException(Account.TYPE, kuraMessage.getChannel().getScope());
Expand Down

0 comments on commit 7b217fc

Please sign in to comment.