use of org.motechproject.mots.domain.security.User in project mots by motech-implementations.
the class UserController method createUser.
/**
* Create User.
* @param userDto DTO of User to be created
* @return created User
*/
@RequestMapping(value = "/user", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public UserDto createUser(@RequestBody @Valid UserDto userDto, BindingResult bindingResult) {
checkBindingResult(bindingResult);
User user = userMapper.fromDto(userDto);
return userMapper.toDto(userService.registerNewUser(user));
}
use of org.motechproject.mots.domain.security.User in project mots by motech-implementations.
the class UserController method saveUser.
/**
* Update User.
* @param id id of User to update
* @param userDto DTO of User to be updated
* @return updated User
*/
@RequestMapping(value = "/user/{id}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public UserDto saveUser(@PathVariable("id") UUID id, @RequestBody @Valid UserDto userDto, BindingResult bindingResult) {
checkBindingResult(bindingResult);
boolean encodeNewPassword = true;
if (StringUtils.isEmpty(userDto.getPassword())) {
encodeNewPassword = false;
}
User existingUser = userService.getUser(id);
userMapper.passwordNullSafeUpdateFromDto(userDto, existingUser);
return userMapper.toDto(userService.saveUser(existingUser, encodeNewPassword));
}
use of org.motechproject.mots.domain.security.User in project mots by motech-implementations.
the class UserController method saveUserProfile.
/**
* Update profile information about User.
* @param id id of User to update Profile
* @param userProfileDto DTO of User Profile to be updated
* @return updated User Profile
*/
@RequestMapping(value = "/user/profile/{id}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public UserProfileDto saveUserProfile(@PathVariable("id") UUID id, @RequestBody @Valid UserProfileDto userProfileDto, BindingResult bindingResult) {
checkBindingResult(bindingResult);
final User updatedUserProfile = userService.editUserProfile(id, userProfileDto);
return userMapper.toUserProfileDto(updatedUserProfile);
}
use of org.motechproject.mots.domain.security.User in project mots by motech-implementations.
the class UserRepositoryIntegrationTest method shouldFindUserByUserName.
@Test
public void shouldFindUserByUserName() {
// when
Page<User> result = userRepository.search(user1.getUsername(), null, null, null, null);
// then
assertThat(result.getTotalElements(), is(1L));
User foundUser = result.getContent().get(0);
assertThat(foundUser.getUsername(), is(user1.getUsername()));
}
use of org.motechproject.mots.domain.security.User in project mots by motech-implementations.
the class WithMockCustomUserSecurityContextFactory method createSecurityContext.
@Override
public SecurityContext createSecurityContext(WithMockAdminUser customUser) {
Set<UserPermission> rights = new HashSet<>();
rights.add(UserPermission.CREATE_FACILITIES);
rights.add(UserPermission.DISPLAY_FACILITIES);
rights.add(UserPermission.MANAGE_FACILITIES);
Set<UserRole> grantedAuthorities = new HashSet<>();
grantedAuthorities.add(new UserRole("test-role", rights));
UserDetails principal = new User(customUser.username(), customUser.password(), customUser.email(), customUser.name(), grantedAuthorities, customUser.enabled());
SecurityContext context = SecurityContextHolder.createEmptyContext();
Authentication authentication = new UsernamePasswordAuthenticationToken(customUser.username(), principal.getPassword(), principal.getAuthorities());
context.setAuthentication(authentication);
return context;
}
Aggregations