@Override public void execute() throws SBonitaException { if (userName != null) { sUser = identityService.getUserByUserName(userName); } else { sUser = identityService.getUser(userId); } }
@Override public void execute() throws SBonitaException { // FIXME: if RDBMS has foreign keys, getUser, getRole, getGroup can be ommitted: final SUser user = identityService.getUser(userId); final SRole role = identityService.getRole(roleId); final SGroup group = identityService.getGroup(groupId); userMembership = BuilderFactory.get(SUserMembershipBuilderFactory.class).createNewInstance(user.getId(), group.getId(), role.getId()).setAssignedBy(assignedBy) .setAssignedDate(System.currentTimeMillis()).done(); identityService.createUserMembership(userMembership); }
private void deleteActorMembersOfGroupChildren(final long groupId) throws SIdentityException, SActorMemberNotFoundException, SActorMemberDeletionException, SBonitaReadException { int i = 0; List<SGroup> childrenGroup; do { childrenGroup = identityService.getGroupChildren(groupId, i, BATCH_SIZE); i += BATCH_SIZE; for (final SGroup sGroup : childrenGroup) { deleteActorMembersOfGroup(sGroup.getId()); } } while (childrenGroup.size() == BATCH_SIZE); }
private void checkPathUnicity(long groupId, GroupUpdater updater, IdentityService identityService) throws SGroupNotFoundException, AlreadyExistsException { final Serializable updatedName = updater.getFields().get(GroupField.NAME); SGroup sGroupToBeUpdated = identityService.getGroup(groupId); String name = updatedName != null ? updatedName.toString() : sGroupToBeUpdated.getName(); StringBuilder sb = new StringBuilder(); String parentPath = updater.getFields().get(GroupField.PARENT_PATH) != null ? updater.getFields().get(GroupField.PARENT_PATH).toString() : ""; sb.append(parentPath).append("/").append(name); try { if (updatedName != null) { SGroup group = identityService.getGroupByPath(sb.toString()); if (group.getId() != groupId) { throw new AlreadyExistsException("Group named \"" + name + "\" already exists"); } } } catch (final SGroupNotFoundException e) { } }
SUser user = null; try { user = identityService.getUserByUserName(userName); } catch (final SUserNotFoundException e) { errors.add(new ImportError(userName, Type.USER)); SGroup group = null; try { group = identityService.getGroupByPath(groupPath); } catch (final SGroupNotFoundException e) { errors.add(new ImportError(groupPath, Type.GROUP)); SRole role = null; try { role = identityService.getRoleByName(roleName); } catch (final SRoleNotFoundException e) { errors.add(new ImportError(roleName, Type.ROLE)); SGroup group = null; try { group = identityService.getGroupByPath(membership.getGroup()); } catch (final SGroupNotFoundException e) { errors.add(new ImportError(membership.getGroup(), Type.GROUP)); role = identityService.getRoleByName(membership.getRole()); } catch (final SRoleNotFoundException e) { errors.add(new ImportError(membership.getRole(), Type.ROLE));
private void addRoleAndGroupToProfile() throws SGroupNotFoundException, SRoleNotFoundException, SProfileMemberCreationException { final SGroup group = identityService.getGroup(groupId); final SRole role = identityService.getRole(roleId); if (group != null && role != null) { sProfileMember = profileService .addRoleAndGroupToProfile(profileId, roleId, groupId, role.getName(), group.getName(), group.getParentPath()); } }
private void checkIfUserExists(final long userId) throws SCommandParameterizationException { try { final IdentityService identityService = serviceAccessor.getIdentityService(); identityService.getUser(userId); } catch (final SUserNotFoundException e) { throw new SCommandParameterizationException("No such user refer to this userId :" + userId, e); } } }
switch (memberType) { case USER: final SUser user = serviceAccessor.getIdentityService().getUser(userId); builder.setUserId(userId); builder.setDisplayNamePart1(user.getFirstName()); SGroup group = serviceAccessor.getIdentityService().getGroup(groupId); builder.setGroupId(groupId); builder.setDisplayNamePart1(group.getName()); SRole role = serviceAccessor.getIdentityService().getRole(roleId); builder.setRoleId(roleId); builder.setDisplayNamePart1(role.getName()); group = serviceAccessor.getIdentityService().getGroup(groupId); role = serviceAccessor.getIdentityService().getRole(roleId); builder.setGroupId(groupId); builder.setRoleId(roleId);
private void updateLastConnectionDate(SUser user) throws SLoginException { try { identityService.updateUser(user, updateBuilder().updateLastConnection(System.currentTimeMillis()).done()); } catch (SUserUpdateException e) { throw new SLoginException(e); } }
private void addRoleToProfile() throws SRoleNotFoundException, SProfileMemberCreationException { final SRole role = identityService.getRole(roleId); if (role != null) { sProfileMember = profileService.addRoleToProfile(profileId, roleId, role.getName()); } }
private List<String> getGroups(SProfile profile) throws SBonitaReadException, SGroupNotFoundException { ArrayList<String> groups = new ArrayList<>(); int pageIndex = 0; List<SProfileMember> sProfileMembers; do { sProfileMembers = searchProfileMembers(pageIndex, profile.getId(), GROUP_SUFFIX); for (final SProfileMember sProfileMember : sProfileMembers) { groups.add(identityService.getGroup(sProfileMember.getGroupId()).getPath()); } pageIndex++; } while (sProfileMembers.size() > 0); return groups; }
public Map<String, SUser> importUsers(final List<ExportedUser> usersToImport) throws SBonitaException { final Map<String, SUser> userNameToSUsers = new HashMap<>((int) Math.min(Integer.MAX_VALUE, identityService.getNumberOfUsers())); for (final ExportedUser userToImport : usersToImport) { SUser sUser; if (hasUserWithUserName(userToImport.getUserName())) { sUser = identityService.getUserByUserName(userToImport.getUserName()); strategy.foundExistingUser(sUser, userToImport); } else { sUser = addAllUserInfo(userToImport); } userNameToSUsers.put(sUser.getUserName(), sUser); } return userNameToSUsers; }
@Override public void execute() throws SBonitaException { try { long id = userId; if (id == -1) { id = getIdentityService().getUserByUserName(userName).getId(); } deleteUserMembershipsByUser(id); deleteActorMembersOfUser(id); deleteProfileMembersOfUser(id); getIdentityService().deleteUser(id); } catch (SUserNotFoundException notFound) { // not found, don't do anything specific } }
/** * @see org.bonitasoft.engine.authentication.GenericAuthenticationService#checkUserCredentials(java.util.Map) */ @Override public String checkUserCredentials(Map<String, Serializable> credentials) { final String methodName = "checkUserCredentials"; try { final String password = String.valueOf(credentials.get(AuthenticationConstants.BASIC_PASSWORD)); final String userName = String.valueOf(credentials.get(AuthenticationConstants.BASIC_USERNAME)); if (logger.isLoggable(this.getClass(), TechnicalLogSeverity.TRACE)) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogBeforeMethod(this.getClass(), methodName)); } final SUser user = identityService.getUserByUserName(userName); if (identityService.checkCredentials(user, password)) { if (logger.isLoggable(this.getClass(), TechnicalLogSeverity.TRACE)) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogAfterMethod(this.getClass(), methodName)); } return userName; } if (logger.isLoggable(this.getClass(), TechnicalLogSeverity.TRACE)) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogAfterMethod(this.getClass(), methodName)); } } catch (final SUserNotFoundException sunfe) { if (logger.isLoggable(this.getClass(), TechnicalLogSeverity.TRACE)) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogOnExceptionMethod(this.getClass(), methodName, sunfe)); } } return null; }
@Override public Role updateRole(final long roleId, final RoleUpdater updateDescriptor) throws RoleNotFoundException, UpdateException { if (updateDescriptor == null || updateDescriptor.getFields().isEmpty()) { throw new UpdateException("The update descriptor does not contain field updates"); } final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final IdentityService identityService = tenantAccessor.getIdentityService(); try { final EntityUpdateDescriptor changeDescriptor = getRoleUpdateDescriptor(updateDescriptor, tenantAccessor.getTechnicalLoggerService()); return ModelConvertor.toRole(identityService.updateRole(identityService.getRole(roleId), changeDescriptor, getIconUpdater(updateDescriptor))); } catch (final SRoleNotFoundException e) { throw new RoleNotFoundException(e); } catch (SIdentityException e) { throw new UpdateException(e); } }
public SGroup update() throws SIdentityException { SGroup sGroup = identityService.getGroup(groupId); final SGroupBuilderFactory sGroupBuilderFactory = BuilderFactory.get(SGroupBuilderFactory.class); // if the parent path changes it's also necessary to change the children's parent path final String parentPathKey = sGroupBuilderFactory.getParentPathKey(); final String nameKey = sGroupBuilderFactory.getNameKey(); final Map<String, Object> fields = changeDescriptor.getFields(); if (fields.containsKey(parentPathKey) || fields.containsKey(nameKey)) { final String parentPath = fields.containsKey(parentPathKey) ? (String) fields.get(parentPathKey) : sGroup.getParentPath(); final String groupName = fields.containsKey(nameKey) ? (String) fields.get(nameKey) : sGroup.getName(); updateChildren(sGroup, parentPath, sGroupBuilderFactory.getIdKey(), parentPathKey, groupName); } identityService.updateGroup(sGroup, changeDescriptor, iconUpdater); return sGroup; }
private void updateChildren(final SGroup group, final String parentPath, final String idKey, final String parentPathKey, final String groupName) throws SIdentityException { List<SGroup> groupChildren; int i = 0; do { groupChildren = identityService.getGroupChildren(group.getId(), i * BATCH_SIZE, BATCH_SIZE, idKey, OrderByType.ASC); i++; for (final SGroup child : groupChildren) { if (parentPath != null) { updateChildren(child, parentPath + '/' + groupName, idKey, parentPathKey, child.getName()); } else { updateChildren(child, '/' + groupName, idKey, parentPathKey, child.getName()); } } } while (!groupChildren.isEmpty()); final EntityUpdateDescriptor updateDescriptor = new EntityUpdateDescriptor(); updateDescriptor.addField(parentPathKey, parentPath); identityService.updateGroup(group, updateDescriptor, null); }
private SUser getUser(String userName) throws SUserNotFoundException { try { return identityService.getUserByUserName(userName); } catch (SUserNotFoundException e) { debugLog("Unable to find user with username " + userName + " in database."); throw e; } }
@Override public Group createGroup(final GroupCreator creator) throws CreationException { if (creator == null) { throw new CreationException("Cannot create a null group"); } String groupName = creator.getFields().get(GroupCreator.GroupField.NAME).toString(); if (groupName.contains("/")) { throw new InvalidGroupNameException("Cannot create a group with '/' in its name"); } final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final IdentityService identityService = tenantAccessor.getIdentityService(); if (creator.getFields().containsKey(GroupCreator.GroupField.ICON_NAME) || creator.getFields().containsKey(GroupCreator.GroupField.ICON_PATH)) { tenantAccessor.getTechnicalLoggerService().log(IdentityAPIImpl.class, TechnicalLogSeverity.WARNING, "setIconName and setIconPath are deprecated, use setIcon instead"); } final SGroup sGroup = ModelConvertor.constructSGroup(creator); try { identityService.getGroupByPath(sGroup.getPath()); throw new AlreadyExistsException("Group named \"" + sGroup.getName() + "\" already exists"); } catch (final SGroupNotFoundException ignored) { } try { identityService.createGroup(sGroup, (String) creator.getFields().get(GroupCreator.GroupField.ICON_FILENAME), (byte[]) creator.getFields().get(GroupCreator.GroupField.ICON_CONTENT)); } catch (SGroupCreationException e) { throw new CreationException(e); } return ModelConvertor.toGroup(sGroup); }
private SCustomUserInfoDefinition addCustomUserInfoDefinition(ExportedCustomUserInfoDefinition creator) throws SCustomUserInfoDefinitionAlreadyExistsException, SCustomUserInfoDefinitionCreationException { final SCustomUserInfoDefinitionBuilder userInfoBuilder = BuilderFactory.get(SCustomUserInfoDefinitionBuilderFactory.class).createNewInstance(); userInfoBuilder.setName(creator.getName()); userInfoBuilder.setDescription(creator.getDescription()); return identityService.createCustomUserInfoDefinition(userInfoBuilder.done()); }