use of org.eclipse.kapua.app.console.shared.model.GwtSession in project kapua by eclipse.
the class LoginDialog method performLogin.
// Login
public void performLogin() {
final GwtUser tmpUser = new GwtUser(username.getValue(), password.getValue());
// FIXME: use some Credentials object instead of using GwtUser!
gwtAuthorizationService.login(tmpUser, new AsyncCallback<GwtSession>() {
@Override
public void onFailure(Throwable caught) {
ConsoleInfo.display(MSGS.loginError(), caught.getLocalizedMessage());
reset();
}
@Override
public void onSuccess(final GwtSession gwtSession) {
currentSession = gwtSession;
callMainScreen();
}
});
}
use of org.eclipse.kapua.app.console.shared.model.GwtSession 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;
}
use of org.eclipse.kapua.app.console.shared.model.GwtSession in project kapua by eclipse.
the class GwtAuthorizationServiceImpl method getCurrentSession.
/**
* Return the currently authenticated user or null if no session has been established.
*/
public GwtSession getCurrentSession() throws GwtKapuaException {
GwtSession gwtSession = null;
try {
Subject currentUser = SecurityUtils.getSubject();
if (currentUser != null && currentUser.isAuthenticated()) {
Session session = currentUser.getSession();
gwtSession = (GwtSession) session.getAttribute(SESSION_CURRENT);
// Store the user information in the sessions
String username = (String) currentUser.getPrincipal();
KapuaLocator locator = KapuaLocator.getInstance();
UserService userService = locator.getService(UserService.class);
User user = userService.findByName(username);
// get the session
if (gwtSession == null) {
gwtSession = establishSession();
} else {
gwtSession.setGwtUser(KapuaGwtConverter.convert(user));
}
}
} catch (Throwable t) {
s_logger.warn("Error in getCurrentSession.", t);
KapuaExceptionHandler.handle(t);
}
return gwtSession;
}
use of org.eclipse.kapua.app.console.shared.model.GwtSession in project kapua by eclipse.
the class GwtAuthorizationServiceImpl method login.
/**
* Login call in response to the login dialog.
*/
public GwtSession login(GwtUser tmpUser) throws GwtKapuaException {
// VIP
// keep this here to make sure we initialize the logger.
// Without the following, console logger may not log anything when deployed into tomcat.
s_logger.info(">>> THIS IS INFO <<<");
s_logger.warn(">>> THIS IS WARN <<<");
s_logger.debug(">>> THIS IS DEBUG <<<");
GwtSession gwtSession = null;
try {
// Get the user
KapuaLocator locator = KapuaLocator.getInstance();
AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
UsernamePasswordTokenFactory credentialsFactory = locator.getFactory(UsernamePasswordTokenFactory.class);
AuthenticationCredentials credentials = credentialsFactory.newInstance(tmpUser.getUsername(), tmpUser.getPassword().toCharArray());
// Login
authenticationService.login(credentials);
// Get the session infos
gwtSession = establishSession();
} catch (Throwable t) {
logout();
KapuaExceptionHandler.handle(t);
}
return gwtSession;
}
Aggregations