Search in sources :

Example 1 with GwtSession

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();
        }
    });
}
Also used : GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) GwtSession(org.eclipse.kapua.app.console.shared.model.GwtSession)

Example 2 with GwtSession

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) GwtAccount(org.eclipse.kapua.app.console.shared.model.GwtAccount) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) User(org.eclipse.kapua.service.user.User) UserService(org.eclipse.kapua.service.user.UserService) KapuaSession(org.eclipse.kapua.commons.security.KapuaSession) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) GwtAccount(org.eclipse.kapua.app.console.shared.model.GwtAccount) SystemSetting(org.eclipse.kapua.commons.setting.system.SystemSetting) GwtSession(org.eclipse.kapua.app.console.shared.model.GwtSession) GwtAuthorizationService(org.eclipse.kapua.app.console.shared.service.GwtAuthorizationService) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) AccountService(org.eclipse.kapua.service.account.AccountService)

Example 3 with 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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) User(org.eclipse.kapua.service.user.User) UserService(org.eclipse.kapua.service.user.UserService) GwtSession(org.eclipse.kapua.app.console.shared.model.GwtSession) Subject(org.apache.shiro.subject.Subject) Session(org.apache.shiro.session.Session) GwtSession(org.eclipse.kapua.app.console.shared.model.GwtSession) KapuaSession(org.eclipse.kapua.commons.security.KapuaSession)

Example 4 with 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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) AuthenticationCredentials(org.eclipse.kapua.service.authentication.AuthenticationCredentials) UsernamePasswordTokenFactory(org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory) GwtSession(org.eclipse.kapua.app.console.shared.model.GwtSession) AuthenticationService(org.eclipse.kapua.service.authentication.AuthenticationService)

Aggregations

GwtSession (org.eclipse.kapua.app.console.shared.model.GwtSession)4 GwtUser (org.eclipse.kapua.app.console.shared.model.GwtUser)3 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)3 KapuaSession (org.eclipse.kapua.commons.security.KapuaSession)2 User (org.eclipse.kapua.service.user.User)2 UserService (org.eclipse.kapua.service.user.UserService)2 Session (org.apache.shiro.session.Session)1 Subject (org.apache.shiro.subject.Subject)1 GwtAccount (org.eclipse.kapua.app.console.shared.model.GwtAccount)1 GwtAuthorizationService (org.eclipse.kapua.app.console.shared.service.GwtAuthorizationService)1 SystemSetting (org.eclipse.kapua.commons.setting.system.SystemSetting)1 Account (org.eclipse.kapua.service.account.Account)1 AccountService (org.eclipse.kapua.service.account.AccountService)1 AuthenticationCredentials (org.eclipse.kapua.service.authentication.AuthenticationCredentials)1 AuthenticationService (org.eclipse.kapua.service.authentication.AuthenticationService)1 UsernamePasswordTokenFactory (org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory)1 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)1 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)1