Search in sources :

Example 11 with UserService

use of org.eclipse.kapua.service.user.UserService in project kapua by eclipse.

the class GwtUserServiceImpl method find.

public GwtUser find(String accountId, String userIdString) throws GwtKapuaException {
    KapuaId scopeId = KapuaEid.parseShortId(accountId);
    KapuaId userId = KapuaEid.parseShortId(userIdString);
    GwtUser gwtUser = null;
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        UserService userService = locator.getService(UserService.class);
        User user = userService.find(scopeId, userId);
        if (user != null) {
            gwtUser = KapuaGwtConverter.convert(user);
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return gwtUser;
}
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) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 12 with UserService

use of org.eclipse.kapua.service.user.UserService in project kapua by eclipse.

the class DeviceCommandManagementServiceTest method setUpTest.

@Ignore
@Before
public void setUpTest() throws Exception {
    // 
    // User creation
    String userName = String.format("test-usr-%d", (new Date()).getTime());
    UserService userService = locator.getService(UserService.class);
    UserFactory userFactory = locator.getFactory(UserFactory.class);
    UserCreator userCreator = userFactory.newCreator(account.getId(), userName);
    user = userService.create(userCreator);
    // 
    // User permission creation
    UserPermissionService userPermissionService = locator.getService(UserPermissionService.class);
    UserPermissionFactory userPermissionFactory = locator.getFactory(UserPermissionFactory.class);
    UserPermissionCreator userPermissionCreator = userPermissionFactory.newCreator(account.getId());
    PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
    userPermissionCreator.setUserId(user.getId());
    userPermissionCreator.setPermission(permissionFactory.newPermission(DeviceLifecycleDomain.DEVICE_LIFECYCLE, Actions.connect, account.getId()));
    userPermissionService.create(userPermissionCreator);
    // 
    // User credentials creation
    CredentialService credentialService = locator.getService(CredentialService.class);
    CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class);
    CredentialCreator credentialCreator = credentialFactory.newCreator(account.getId(), user.getId(), CredentialType.PASSWORD, "kapua-password");
    credentialService.create(credentialCreator);
}
Also used : CredentialService(org.eclipse.kapua.service.authentication.credential.CredentialService) UserService(org.eclipse.kapua.service.user.UserService) 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) UserFactory(org.eclipse.kapua.service.user.UserFactory) UserPermissionService(org.eclipse.kapua.service.authorization.user.permission.UserPermissionService) UserPermissionFactory(org.eclipse.kapua.service.authorization.user.permission.UserPermissionFactory) UserCreator(org.eclipse.kapua.service.user.UserCreator) CredentialCreator(org.eclipse.kapua.service.authentication.credential.CredentialCreator) Date(java.util.Date) UserPermissionCreator(org.eclipse.kapua.service.authorization.user.permission.UserPermissionCreator) Before(org.junit.Before) Ignore(org.junit.Ignore)

Aggregations

UserService (org.eclipse.kapua.service.user.UserService)12 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)11 User (org.eclipse.kapua.service.user.User)11 GwtUser (org.eclipse.kapua.app.console.shared.model.GwtUser)7 KapuaId (org.eclipse.kapua.model.id.KapuaId)6 GwtUserService (org.eclipse.kapua.app.console.shared.service.GwtUserService)5 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)5 CredentialService (org.eclipse.kapua.service.authentication.credential.CredentialService)4 UserPermissionFactory (org.eclipse.kapua.service.authorization.user.permission.UserPermissionFactory)4 UserPermissionService (org.eclipse.kapua.service.authorization.user.permission.UserPermissionService)4 UserFactory (org.eclipse.kapua.service.user.UserFactory)4 KapuaSession (org.eclipse.kapua.commons.security.KapuaSession)3 CredentialCreator (org.eclipse.kapua.service.authentication.credential.CredentialCreator)3 CredentialFactory (org.eclipse.kapua.service.authentication.credential.CredentialFactory)3 Permission (org.eclipse.kapua.service.authorization.permission.Permission)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Callable (java.util.concurrent.Callable)2 ShiroException (org.apache.shiro.ShiroException)2 AuthenticationException (org.apache.shiro.authc.AuthenticationException)2