Search in sources :

Example 1 with GwtUser

use of org.eclipse.kapua.app.console.shared.model.GwtUser 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 GwtUser

use of org.eclipse.kapua.app.console.shared.model.GwtUser 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 GwtUser

use of org.eclipse.kapua.app.console.shared.model.GwtUser in project kapua by eclipse.

the class GwtUserServiceImpl method findAll.

public ListLoadResult<GwtUser> findAll(String scopeIdString) throws GwtKapuaException {
    KapuaId scopeId = KapuaEid.parseShortId(scopeIdString);
    List<GwtUser> gwtUserList = new ArrayList<GwtUser>();
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        UserService userService = locator.getService(UserService.class);
        UserFactory userFactory = locator.getFactory(UserFactory.class);
        UserQuery query = userFactory.newQuery(scopeId);
        UserListResult list = userService.query(query);
        for (User user : list.getItems()) {
            gwtUserList.add(KapuaGwtConverter.convert(user));
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return new BaseListLoadResult<GwtUser>(gwtUserList);
}
Also used : BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) User(org.eclipse.kapua.service.user.User) GwtUserService(org.eclipse.kapua.app.console.shared.service.GwtUserService) UserService(org.eclipse.kapua.service.user.UserService) UserQuery(org.eclipse.kapua.service.user.UserQuery) ArrayList(java.util.ArrayList) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) UserFactory(org.eclipse.kapua.service.user.UserFactory) KapuaId(org.eclipse.kapua.model.id.KapuaId) UserListResult(org.eclipse.kapua.service.user.UserListResult)

Example 4 with GwtUser

use of org.eclipse.kapua.app.console.shared.model.GwtUser in project kapua by eclipse.

the class GwtUserServiceImpl method update.

public GwtUser update(GwtXSRFToken xsrfToken, GwtUser gwtUser) throws GwtKapuaException {
    checkXSRFToken(xsrfToken);
    GwtUser gwtUserUpdated = null;
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        UserService userService = locator.getService(UserService.class);
        KapuaId scopeId = KapuaEid.parseShortId(gwtUser.getScopeId());
        KapuaId userId = KapuaEid.parseShortId(gwtUser.getId());
        User user = userService.find(scopeId, userId);
        if (user != null) {
            // 
            // Update user
            user.setName(gwtUser.getUnescapedUsername());
            user.setDisplayName(gwtUser.getUnescapedDisplayName());
            user.setEmail(gwtUser.getUnescapedEmail());
            user.setPhoneNumber(gwtUser.getUnescapedPhoneNumber());
            // status
            user.setStatus(UserStatus.valueOf(gwtUser.getStatus()));
            // 
            // Update permissions
            Set<String> newPermissions = new HashSet<String>();
            if (gwtUser.getPermissions() != null) {
                // build the set of permissions
                newPermissions.addAll(Arrays.asList(gwtUser.getPermissions().split(",")));
            }
            UserPermissionService userPermissionService = locator.getService(UserPermissionService.class);
            UserPermissionFactory userPermissionFactory = locator.getFactory(UserPermissionFactory.class);
            PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
            Set<UserPermissionCreator> newUserPermissions = new HashSet<UserPermissionCreator>();
            for (String p : newPermissions) {
                UserPermissionCreator userPermissionCreator = userPermissionFactory.newCreator(user.getScopeId());
                userPermissionCreator.setUserId(scopeId);
                String[] tokens = p.split(":");
                String domain = null;
                Actions action = null;
                KapuaId targetScopeId = null;
                if (tokens.length > 0) {
                    domain = tokens[0];
                }
                if (tokens.length > 1) {
                    action = Actions.valueOf(tokens[1]);
                }
                if (tokens.length > 2) {
                    targetScopeId = KapuaEid.parseShortId(tokens[2]);
                }
                Permission permission = permissionFactory.newPermission(domain, action, targetScopeId);
                userPermissionCreator.setPermission(permission);
                userPermissionService.create(userPermissionCreator);
            }
            userPermissionService.merge(newUserPermissions);
            // Update credentials
            if (gwtUser.getPassword() != null) {
                CredentialService credentialService = locator.getService(CredentialService.class);
                CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class);
                CredentialListResult credentials = credentialService.findByUserId(scopeId, userId);
                if (!credentials.isEmpty()) {
                    // 
                    // Delete old PASSWORD credential
                    Credential oldCredential = null;
                    for (Credential c : credentials.getItems()) {
                        if (CredentialType.PASSWORD.equals(c.getCredentialType())) {
                            oldCredential = c;
                            break;
                        }
                    }
                    credentialService.delete(oldCredential.getScopeId(), oldCredential.getId());
                    // 
                    // Create new PASSWORD credential
                    CredentialCreator credentialCreator = credentialFactory.newCreator(scopeId, user.getId(), CredentialType.PASSWORD, gwtUser.getPassword());
                    credentialService.create(credentialCreator);
                }
            }
            // optlock
            user.setOptlock(gwtUser.getOptlock());
            // update the user
            userService.update(user);
            // 
            // convert to GwtAccount and return
            // reload the user as we want to load all its permissions
            gwtUserUpdated = KapuaGwtConverter.convert(userService.find(user.getScopeId(), user.getId()));
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return gwtUserUpdated;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Credential(org.eclipse.kapua.service.authentication.credential.Credential) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) User(org.eclipse.kapua.service.user.User) GwtUserService(org.eclipse.kapua.app.console.shared.service.GwtUserService) UserService(org.eclipse.kapua.service.user.UserService) Actions(org.eclipse.kapua.service.authorization.permission.Actions) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) UserPermissionFactory(org.eclipse.kapua.service.authorization.user.permission.UserPermissionFactory) CredentialFactory(org.eclipse.kapua.service.authentication.credential.CredentialFactory) CredentialCreator(org.eclipse.kapua.service.authentication.credential.CredentialCreator) CredentialService(org.eclipse.kapua.service.authentication.credential.CredentialService) Permission(org.eclipse.kapua.service.authorization.permission.Permission) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) UserPermissionService(org.eclipse.kapua.service.authorization.user.permission.UserPermissionService) UserPermissionFactory(org.eclipse.kapua.service.authorization.user.permission.UserPermissionFactory) CredentialListResult(org.eclipse.kapua.service.authentication.credential.CredentialListResult) KapuaId(org.eclipse.kapua.model.id.KapuaId) HashSet(java.util.HashSet) UserPermissionCreator(org.eclipse.kapua.service.authorization.user.permission.UserPermissionCreator)

Example 5 with GwtUser

use of org.eclipse.kapua.app.console.shared.model.GwtUser in project kapua by eclipse.

the class GwtUserServiceImpl method delete.

public void delete(GwtXSRFToken xsrfToken, String accountId, GwtUser gwtUser) throws GwtKapuaException {
    checkXSRFToken(xsrfToken);
    KapuaId scopeId = KapuaEid.parseShortId(accountId);
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        UserService userService = locator.getService(UserService.class);
        User user = userService.find(scopeId, KapuaEid.parseShortId(gwtUser.getId()));
        if (user != null) {
            userService.delete(user);
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) User(org.eclipse.kapua.service.user.User) GwtUserService(org.eclipse.kapua.app.console.shared.service.GwtUserService) UserService(org.eclipse.kapua.service.user.UserService) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Aggregations

GwtUser (org.eclipse.kapua.app.console.shared.model.GwtUser)12 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)6 User (org.eclipse.kapua.service.user.User)6 UserService (org.eclipse.kapua.service.user.UserService)6 GwtUserService (org.eclipse.kapua.app.console.shared.service.GwtUserService)5 KapuaId (org.eclipse.kapua.model.id.KapuaId)5 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)4 GwtXSRFToken (org.eclipse.kapua.app.console.shared.model.GwtXSRFToken)3 ListLoadResult (com.extjs.gxt.ui.client.data.ListLoadResult)2 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)2 ListStore (com.extjs.gxt.ui.client.store.ListStore)2 Button (com.extjs.gxt.ui.client.widget.button.Button)2 CheckBox (com.extjs.gxt.ui.client.widget.form.CheckBox)2 GwtSession (org.eclipse.kapua.app.console.shared.model.GwtSession)2 GwtUserCreator (org.eclipse.kapua.app.console.shared.model.GwtUserCreator)2 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 BaseListLoader (com.extjs.gxt.ui.client.data.BaseListLoader)1 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)1