use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.
the class DeviceCommandManagementServiceTest method setUpClass.
// @BeforeClass
public static void setUpClass() {
try {
//
// Login
String username = "kapua-sys";
String password = "kapua-password";
AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
UsernamePasswordTokenFactory credentialsFactory = locator.getFactory(UsernamePasswordTokenFactory.class);
authenticationService.login(credentialsFactory.newInstance(username, password.toCharArray()));
//
// Get current user Id
adminUserId = KapuaSecurityUtils.getSession().getUserId();
adminScopeId = KapuaSecurityUtils.getSession().getScopeId();
//
// Create test account
KapuaLocator locator = KapuaLocator.getInstance();
//
// Account creation
String accountName = String.format("test-acct-%d", (new Date()).getTime());
AccountService accountService = locator.getService(AccountService.class);
AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
AccountCreator accountCreator = accountFactory.newAccountCreator(adminScopeId, accountName);
accountCreator.setAccountPassword("!bV0123456789");
accountCreator.setOrganizationName(accountName);
accountCreator.setOrganizationEmail(accountName + "@m.com");
account = accountService.create(accountCreator);
} catch (KapuaException exc) {
exc.printStackTrace();
}
}
use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.
the class GwtAccountServiceImpl method find.
public GwtAccount find(String accountIdString) throws GwtKapuaException {
KapuaId accountId = KapuaEid.parseShortId(accountIdString);
GwtAccount gwtAccount = null;
try {
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
gwtAccount = KapuaGwtConverter.convert(accountService.find(accountId));
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtAccount;
}
use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.
the class GwtAccountServiceImpl method update.
public GwtAccount update(GwtXSRFToken xsrfToken, GwtAccount gwtAccount) throws GwtKapuaException {
//
// Checking validity of the given XSRF Token
checkXSRFToken(xsrfToken);
GwtAccount gwtAccountUpdated = null;
KapuaId scopeId = KapuaEid.parseShortId(gwtAccount.getId());
try {
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(scopeId);
account.getOrganization().setName(gwtAccount.getGwtOrganization().getName());
account.getOrganization().setPersonName(gwtAccount.getGwtOrganization().getPersonName());
account.getOrganization().setEmail(gwtAccount.getGwtOrganization().getEmailAddress());
account.getOrganization().setPhoneNumber(gwtAccount.getGwtOrganization().getPhoneNumber());
account.getOrganization().setAddressLine1(gwtAccount.getGwtOrganization().getAddressLine1());
account.getOrganization().setAddressLine2(gwtAccount.getGwtOrganization().getAddressLine2());
account.getOrganization().setZipPostCode(gwtAccount.getGwtOrganization().getZipPostCode());
account.getOrganization().setCity(gwtAccount.getGwtOrganization().getCity());
account.getOrganization().setStateProvinceCounty(gwtAccount.getGwtOrganization().getStateProvinceCounty());
account.getOrganization().setCountry(gwtAccount.getGwtOrganization().getCountry());
account.setOptlock(gwtAccount.getOptlock());
account = accountService.update(account);
// convert to GwtAccount and return
gwtAccountUpdated = KapuaGwtConverter.convert(account);
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtAccountUpdated;
}
use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.
the class GwtAccountServiceImpl method findByAccountName.
@Override
public GwtAccount findByAccountName(String accountName) throws GwtKapuaException {
GwtAccount gwtAccount = null;
try {
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.findByName(accountName);
if (account != null) {
gwtAccount = KapuaGwtConverter.convert(account);
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtAccount;
}
use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.
the class GwtAuthorizationServiceImpl method establishSession.
private GwtSession establishSession() throws KapuaException {
KapuaLocator locator = KapuaLocator.getInstance();
//
// Get info from session
KapuaSession kapuaSession = KapuaSecurityUtils.getSession();
//
// Get user info
UserService userService = locator.getService(UserService.class);
User user = userService.find(kapuaSession.getScopeId(), kapuaSession.getUserId());
//
// Get permission info
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
boolean hasAccountCreate = authorizationService.isPermitted(permissionFactory.newPermission(AccountDomain.ACCOUNT, Actions.write, kapuaSession.getScopeId()));
boolean hasAccountRead = authorizationService.isPermitted(permissionFactory.newPermission(AccountDomain.ACCOUNT, Actions.read, kapuaSession.getScopeId()));
boolean hasAccountUpdate = authorizationService.isPermitted(permissionFactory.newPermission(AccountDomain.ACCOUNT, Actions.write, kapuaSession.getScopeId()));
boolean hasAccountDelete = authorizationService.isPermitted(permissionFactory.newPermission(AccountDomain.ACCOUNT, Actions.delete, kapuaSession.getScopeId()));
boolean hasAccountAll = authorizationService.isPermitted(permissionFactory.newPermission(AccountDomain.ACCOUNT, null, null));
boolean hasDeviceCreate = authorizationService.isPermitted(permissionFactory.newPermission(DeviceDomain.DEVICE, Actions.write, kapuaSession.getScopeId()));
boolean hasDeviceRead = authorizationService.isPermitted(permissionFactory.newPermission(DeviceDomain.DEVICE, Actions.read, kapuaSession.getScopeId()));
boolean hasDeviceUpdate = authorizationService.isPermitted(permissionFactory.newPermission(DeviceDomain.DEVICE, Actions.write, kapuaSession.getScopeId()));
boolean hasDeviceDelete = authorizationService.isPermitted(permissionFactory.newPermission(DeviceDomain.DEVICE, Actions.delete, kapuaSession.getScopeId()));
boolean hasDeviceManage = authorizationService.isPermitted(permissionFactory.newPermission(DeviceLifecycleDomain.DEVICE_LIFECYCLE, Actions.write, kapuaSession.getScopeId()));
boolean hasDataRead = authorizationService.isPermitted(permissionFactory.newPermission("data", Actions.read, kapuaSession.getScopeId()));
boolean hasUserCreate = authorizationService.isPermitted(permissionFactory.newPermission("user", Actions.write, kapuaSession.getScopeId()));
boolean hasUserRead = authorizationService.isPermitted(permissionFactory.newPermission("user", Actions.read, kapuaSession.getScopeId()));
boolean hasUserUpdate = authorizationService.isPermitted(permissionFactory.newPermission("user", Actions.write, kapuaSession.getScopeId()));
boolean hasUserDelete = authorizationService.isPermitted(permissionFactory.newPermission("user", Actions.delete, kapuaSession.getScopeId()));
//
// Get account info
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(kapuaSession.getScopeId());
//
// Convert entities
GwtUser gwtUser = KapuaGwtConverter.convert(user);
GwtAccount gwtAccount = KapuaGwtConverter.convert(account);
//
// Build the session
GwtSession gwtSession = new GwtSession();
// Console info
SystemSetting commonsConfig = SystemSetting.getInstance();
gwtSession.setVersion(commonsConfig.getString(SystemSettingKey.VERSION));
gwtSession.setBuildVersion(commonsConfig.getString(SystemSettingKey.BUILD_VERSION));
gwtSession.setBuildNumber(commonsConfig.getString(SystemSettingKey.BUILD_NUMBER));
// User info
gwtSession.setGwtUser(gwtUser);
gwtSession.setGwtAccount(gwtAccount);
gwtSession.setRootAccount(gwtAccount);
gwtSession.setSelectedAccount(gwtAccount);
// Permission info
gwtSession.setAccountCreatePermission(hasAccountCreate);
gwtSession.setAccountReadPermission(hasAccountRead);
gwtSession.setAccountUpdatePermission(hasAccountUpdate);
gwtSession.setAccountDeletePermission(hasAccountDelete);
gwtSession.setAccountAllPermission(hasAccountAll);
gwtSession.setDeviceCreatePermission(hasDeviceCreate);
gwtSession.setDeviceReadPermission(hasDeviceRead);
gwtSession.setDeviceUpdatePermission(hasDeviceUpdate);
gwtSession.setDeviceDeletePermission(hasDeviceDelete);
gwtSession.setDeviceManagePermission(hasDeviceManage);
gwtSession.setDataReadPermission(hasDataRead);
gwtSession.setUserCreatePermission(hasUserCreate);
gwtSession.setUserReadPermission(hasUserRead);
gwtSession.setUserUpdatePermission(hasUserUpdate);
gwtSession.setUserDeletePermission(hasUserDelete);
return gwtSession;
}
Aggregations