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;
});
}
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));
}
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);
}
}
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);
}
}
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);
}
}
Aggregations