private void updateRegisteredUser(UserEntity registeredUser, UserDetails details) { if ((registeredUser.getFirstname() != null && !registeredUser.getFirstname().equals(details.getFirstname())) || (registeredUser.getLastname() != null && !registeredUser.getLastname().equals(details.getLastname())) || (registeredUser.getEmail() != null && !registeredUser.getEmail().equals(details.getEmail()))) { UpdateUserEntity updateUserEntity = new UpdateUserEntity(registeredUser); updateUserEntity.setFirstname(details.getFirstname()); updateUserEntity.setLastname(details.getLastname()); updateUserEntity.setEmail(details.getEmail()); userService.update(registeredUser.getId(), updateUserEntity); } }
@Override public Document transform(Indexable indexable) { Document doc = new Document(); UserEntity user = (UserEntity) indexable; doc.add(new StringField(FIELD_ID, user.getId(), Field.Store.YES)); doc.add(new StringField(FIELD_TYPE, FIELD_TYPE_VALUE, Field.Store.YES)); doc.add(new StringField(FIELD_SOURCE, user.getSource(), Field.Store.NO)); doc.add(new StringField(FIELD_REFERENCE, user.getSourceId(), Field.Store.NO)); if (user.getDisplayName() != null) { doc.add(new StringField(FIELD_DISPLAYNAME, user.getDisplayName(), Field.Store.NO)); doc.add(new TextField(FIELD_DISPLAYNAME_SPLIT, user.getDisplayName(), Field.Store.NO)); } if (user.getFirstname() != null) { doc.add(new StringField(FIELD_FIRSTNAME, user.getFirstname(), Field.Store.NO)); } if (user.getLastname() != null) { doc.add(new StringField(FIELD_LASTNAME, user.getLastname(), Field.Store.NO)); } if (user.getEmail() != null) { doc.add(new StringField(FIELD_EMAIL, user.getEmail(), Field.Store.NO)); } return doc; }
private UserDetails mapUserEntityToUserDetails(UserEntity userEntity) { List<GrantedAuthority> authorities = AuthorityUtils.NO_AUTHORITIES; if (userEntity.getRoles() != null && userEntity.getRoles().size() > 0) { authorities = AuthorityUtils.commaSeparatedStringToAuthorityList( userEntity.getRoles().stream().map(r -> r.getScope().name()+':'+r.getName()).collect(Collectors.joining(",")) ); } io.gravitee.management.idp.api.authentication.UserDetails userDetails = new io.gravitee.management.idp.api.authentication.UserDetails( userEntity.getId(), userEntity.getPassword(), authorities); userDetails.setFirstname(userEntity.getFirstname()); userDetails.setLastname(userEntity.getLastname()); userDetails.setEmail(userEntity.getEmail()); userDetails.setSource(RepositoryIdentityProvider.PROVIDER_TYPE); userDetails.setSourceId(userEntity.getSourceId()); return userDetails; }
public PrimaryOwnerEntity(UserEntity user) { this.id = user.getId(); this.email = user.getEmail(); this.displayName = user.getDisplayName(); }
public UpdateUserEntity(UserEntity userEntity) { this.firstname = userEntity.getFirstname(); this.lastname = userEntity.getLastname(); this.email = userEntity.getEmail(); this.picture = userEntity.getPicture(); }
private UserDetails mapUserEntityToUserDetails(UserEntity userEntity) { List<GrantedAuthority> authorities = AuthorityUtils.NO_AUTHORITIES; if (userEntity.getRoles() != null && userEntity.getRoles().size() > 0) { authorities = AuthorityUtils.commaSeparatedStringToAuthorityList( userEntity.getRoles().stream().collect(Collectors.joining(",")) ); } return new User(userEntity.getUsername(), "unknown", authorities); }
return null; UserEntity userEntity = new UserEntity(); userEntity.setId(user.getId()); userEntity.setSource(user.getSource()); userEntity.setSourceId(user.getSourceId()); userEntity.setEmail(user.getEmail()); userEntity.setFirstname(user.getFirstname()); userEntity.setLastname(user.getLastname()); userEntity.setPassword(user.getPassword()); userEntity.setCreatedAt(user.getCreatedAt()); userEntity.setUpdatedAt(user.getUpdatedAt()); userEntity.setLastConnectionAt(user.getLastConnectionAt()); userEntity.setPicture(user.getPicture()); userEntity.setRoles(roles);
if (user.getEmail() == null) { throw new EmailRequiredException(userId); final String fromName = user.getFirstname() == null ? user.getEmail() : user.getFirstname() + ' ' + user.getLastname(); emailService.sendEmailNotification( new EmailNotificationBuilder() .from(user.getEmail()) .fromName(fromName) .to(emailTo)
Membership membership = new Membership(primaryOwner.getId(), createdApi.getId(), MembershipReferenceType.API); membership.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name())); membership.setCreatedAt(repoApi.getCreatedAt()); membershipRepository.create(membership); if (primaryOwner.getEmail() != null && !primaryOwner.getEmail().isEmpty()) { GenericNotificationConfigEntity notificationConfigEntity = new GenericNotificationConfigEntity(); notificationConfigEntity.setName("Default Mail Notifications"); notificationConfigEntity.setHooks(Arrays.stream(ApiHook.values()).map(Enum::name).collect(toList())); notificationConfigEntity.setNotifier(NotifierServiceImpl.DEFAULT_EMAIL_NOTIFIER_ID); notificationConfigEntity.setConfig(primaryOwner.getEmail()); genericNotificationConfigService.create(notificationConfigEntity);
UserDetails userDetails = new UserDetails(userEntity.getId(), password, authorities); userDetails.setId(userEntity.getId()); userDetails.setEmail(details.getEmail()); userDetails.setFirstname(details.getFirstname()); userDetails.setLastname(details.getLastname()); userDetails.setSource(userEntity.getSource()); userDetails.setSourceId(userEntity.getSourceId()); userDetails.setRoles(userEntity.getRoles(). stream(). map(userEntityRole -> {
@Override public String getId() { return userEntity.getId(); }
.to(userEntity.getEmail()) .subject("User registration - " + userEntity.getDisplayName()) .template(EmailNotificationBuilder.EmailTemplate.USER_REGISTRATION) .params(params)
UserEntity userEntity = userService.findById(member.getId()); if (userEntity != null) { return new MemberToImport(userEntity.getSource(), userEntity.getSourceId(), member.getRole()); MemberEntity membership = membershipService.addOrUpdateMember( new MembershipService.MembershipReference(MembershipReferenceType.API, createdOrUpdatedApiEntity.getId()), new MembershipService.MembershipUser(userEntity.getId(), null), new MembershipService.MembershipRole(RoleScope.API, memberEntity.getRole())); if (SystemRole.PRIMARY_OWNER.name().equals(memberEntity.getRole())) {
@Override public String getDisplayName() { return userEntity.getDisplayName(); }
@Override public String getEmail() { return userEntity.getEmail(); }
Member member = new Member(); member.setRole(m.getRole()); member.setSource(userEntity.getSource()); member.setSourceId(userEntity.getSourceId()); members.add(member);
@Override public String getFirstname() { return userEntity.getFirstname(); }
@Override public String getLastname() { return userEntity.getLastname(); }
@GET @Produces(APPLICATION_JSON) @Permissions( @Permission(value = RolePermission.MANAGEMENT_USERS, acls = RolePermissionAction.READ) ) public UserEntity getUser(@PathParam("id") String userId) { UserEntity user = userService.findByIdWithRoles(userId); // Delete password for security reason user.setPassword(null); user.setPicture(null); return user; }
@Override protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException { try { UserEntity user = userService.findBySource(RepositoryIdentityProvider.PROVIDER_TYPE, username, true); if (RepositoryIdentityProvider.PROVIDER_TYPE.equals(user.getSource())) { if (user.getPassword() == null) { throw new BadCredentialsException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials")); } return mapUserEntityToUserDetails(user); } else { throw new UserNotFoundException(username); } } catch (UserNotFoundException notFound) { throw new UsernameNotFoundException(String.format("User '%s' not found", username), notFound); } catch (Exception repositoryProblem) { LOGGER.error("Failed to retrieveUser : {}", username, repositoryProblem); throw new InternalAuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem); } }