Search in sources :

Example 6 with UserBean

use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.

the class UserResourceImpl method getInfo.

// TODO(msavy): refactor and move to service
/**
 * {@inheritDoc}
 */
@Override
public CurrentUserBean getInfo() {
    String userId = securityContext.getCurrentUser();
    return tryAction(() -> {
        CurrentUserBean currentUser = new CurrentUserBean();
        UserBean user = userService.getUserById(userId);
        if (user == null) {
            user = new UserBean();
            user.setUsername(userId);
            if (securityContext.getFullName() != null) {
                user.setFullName(securityContext.getFullName());
            } else {
                user.setFullName(userId);
            }
            if (securityContext.getEmail() != null) {
                user.setEmail(securityContext.getEmail());
            } else {
                // $NON-NLS-1$
                user.setEmail("");
            }
            user.setJoinedOn(new Date());
            if (securityContext.getLocale() != null) {
                user.setLocale(securityContext.getLocale());
            }
            storage.createUser(user);
            userBootstrapper.bootstrapUser(user, storage);
            currentUser.setPermissions(new HashSet<>());
        } else {
            LOGGER.debug("Got existing user: {0}", user);
            Set<PermissionBean> permissions = query.getPermissions(userId);
            currentUser.setPermissions(permissions);
            updateMutableFields(user);
        }
        currentUser.initFromUser(user);
        currentUser.setAdmin(securityContext.isAdmin());
        return currentUser;
    });
}
Also used : UpdateUserBean(io.apiman.manager.api.beans.idm.UpdateUserBean) UserBean(io.apiman.manager.api.beans.idm.UserBean) CurrentUserBean(io.apiman.manager.api.beans.idm.CurrentUserBean) PermissionBean(io.apiman.manager.api.beans.idm.PermissionBean) CurrentUserBean(io.apiman.manager.api.beans.idm.CurrentUserBean) Date(java.util.Date)

Example 7 with UserBean

use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.

the class UserService method update.

// TODO(msavy): for IDM-driven solutions, we should lock this off.
public void update(String userId, UpdateUserBean user) throws UserNotFoundException {
    UserBean updatedUser = tryAction(() -> storage.getUser(userId));
    if (updatedUser == null) {
        throw ExceptionFactory.userNotFoundException(userId);
    }
    if (user.getEmail() != null) {
        updatedUser.setEmail(user.getEmail());
    }
    if (user.getFullName() != null) {
        updatedUser.setFullName(user.getFullName());
    }
    if (user.getLocale() != null) {
        updatedUser.setLocale(user.getLocale());
    }
    tryAction(() -> storage.updateUser(updatedUser));
}
Also used : UpdateUserBean(io.apiman.manager.api.beans.idm.UpdateUserBean) UserBean(io.apiman.manager.api.beans.idm.UserBean)

Example 8 with UserBean

use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.

the class DefaultTestDataSeeder method seed.

/**
 * @see io.apiman.manager.test.server.ISeeder#seed(io.apiman.manager.api.core.IStorage)
 */
@SuppressWarnings("nls")
@Override
public void seed(IStorage storage) throws StorageException {
    for (String[] userInfo : TestUsers.USERS) {
        UserBean userBean = new UserBean();
        userBean.setUsername(userInfo[0]);
        userBean.setFullName(userInfo[2]);
        userBean.setEmail(userInfo[3]);
        userBean.setJoinedOn(new Date());
        userBean.setLocale(Locale.ENGLISH);
        if ("true".equals(System.getProperty("apiman.test.admin-user-only", "false")) && !userBean.getUsername().equals("admin")) {
            continue;
        }
        storage.createUser(userBean);
    }
}
Also used : UserBean(io.apiman.manager.api.beans.idm.UserBean) Date(java.util.Date)

Example 9 with UserBean

use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.

the class StorageImportDispatcher method user.

/**
 * @see io.apiman.manager.api.exportimport.read.IImportReaderDispatcher#user(io.apiman.manager.api.beans.idm.UserBean)
 */
@Override
public void user(UserBean user) {
    try {
        // $NON-NLS-1$
        logger.info(Messages.i18n.format("StorageImportDispatcher.ImportingUser") + user.getUsername());
        UserBean userBean = storage.getUser(user.getUsername());
        if (userBean == null) {
            storage.createUser(user);
        } else {
            storage.updateUser(user);
        }
    } catch (StorageException e) {
        error(e);
    }
}
Also used : UserBean(io.apiman.manager.api.beans.idm.UserBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 10 with UserBean

use of io.apiman.manager.api.beans.idm.UserBean in project apiman by apiman.

the class StorageExporter method exportUsers.

private void exportUsers() {
    try {
        Iterator<UserBean> iter;
        iter = storage.getAllUsers();
        writer.startUsers();
        while (iter.hasNext()) {
            UserBean bean = iter.next();
            // $NON-NLS-1$
            logger.info(Messages.i18n.format("StorageExporter.ExportingUser") + bean);
            writer.writeUser(bean);
        }
        writer.endUsers();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : UserBean(io.apiman.manager.api.beans.idm.UserBean)

Aggregations

UserBean (io.apiman.manager.api.beans.idm.UserBean)11 StorageException (io.apiman.manager.api.core.exceptions.StorageException)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 RoleBean (io.apiman.manager.api.beans.idm.RoleBean)2 RoleMembershipBean (io.apiman.manager.api.beans.idm.RoleMembershipBean)2 UpdateUserBean (io.apiman.manager.api.beans.idm.UpdateUserBean)2 MemberBean (io.apiman.manager.api.beans.members.MemberBean)2 MemberRoleBean (io.apiman.manager.api.beans.members.MemberRoleBean)2 Streams (com.google.common.collect.Streams)1 ApimanLoggerFactory (io.apiman.common.logging.ApimanLoggerFactory)1 IApimanLogger (io.apiman.common.logging.IApimanLogger)1 Api (io.apiman.gateway.engine.beans.Api)1 Client (io.apiman.gateway.engine.beans.Client)1 Contract (io.apiman.gateway.engine.beans.Contract)1 Policy (io.apiman.gateway.engine.beans.Policy)1 PublishingException (io.apiman.gateway.engine.beans.exceptions.PublishingException)1 ContractActionDto (io.apiman.manager.api.beans.actions.ContractActionDto)1 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)1 ApiGatewayBean (io.apiman.manager.api.beans.apis.ApiGatewayBean)1