use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class AccountController method createUserAccount.
@PostMapping(consumes = "application/json", value = "/rest/accounts")
@PreAuthorize("hasAuthority('sysadmin') or #user.name == authentication.name")
public ResponseEntity<Boolean> createUserAccount(Principal user) {
OAuth2Authentication oauth2User = (OAuth2Authentication) user;
if (accountService.getUser(oauth2User.getName()) != null) {
return new ResponseEntity<>(false, HttpStatus.CREATED);
}
User createdUser = null;
try {
createdUser = accountService.createNonTechnicalUser(oauth2User.getName(), getAuthenticationProvider(oauth2User), null);
} catch (InvalidUserException iue) {
return new ResponseEntity<>(false, HttpStatus.BAD_REQUEST);
}
SpringUserUtils.refreshSpringSecurityUser(createdUser, userNamespaceRoleService);
return new ResponseEntity<>(true, HttpStatus.CREATED);
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class AccountController method updateAccount.
@PutMapping("/rest/accounts/{username:.+}")
@PreAuthorize("hasAuthority('sysadmin') or #username == authentication.name")
public ResponseEntity<UserDto> updateAccount(@PathVariable("username") final String username, HttpEntity<String> httpEntity) {
User account = accountService.getUser(username);
if (account == null) {
return new ResponseEntity<>((UserDto) null, HttpStatus.NOT_FOUND);
}
account.setEmailAddress(httpEntity.getBody());
accountService.updateUser(account);
return new ResponseEntity<>(UserDto.fromUser(account), HttpStatus.OK);
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class AccountController method getUser.
@GetMapping("/rest/accounts/{username:.+}")
@PreAuthorize("isAuthenticated()")
public ResponseEntity<UserDto> getUser(@ApiParam(value = "Username", required = true) @PathVariable String username) {
IUserContext userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication());
User user = accountService.getUser(ControllerUtils.sanitize(username));
if (user != null) {
// logged-on user's name
return new ResponseEntity<>(UserDto.fromUser(user, !userContext.getUsername().equals(username)), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class HomeController method getUser.
@ApiOperation(value = "Returns the currently logged in User")
@ApiResponses(value = { @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 200, message = "OK") })
@RequestMapping(value = { "/user", "/me" }, method = RequestMethod.GET)
public ResponseEntity<Map<String, Object>> getUser(Principal user, final HttpServletRequest request) throws ParseException {
Map<String, Object> map = new LinkedHashMap<>();
if (user == null)
return new ResponseEntity<>(map, HttpStatus.UNAUTHORIZED);
IOAuthProvider provider = registry.getByPrincipal(user);
OAuthUser oauthUser = provider.createUser((OAuth2Authentication) user);
User userAccount = accountService.getUser(oauthUser.getUserId());
Date updateCutoff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(updateDate);
map.put("name", oauthUser.getUserId());
if (Objects.nonNull(userAccount)) {
map.put("subject", userAccount.getSubject());
}
map.put("displayName", oauthUser.getDisplayName());
map.put("isRegistered", Boolean.toString(userAccount != null));
map.put("roles", oauthUser.getRoles());
map.put("needUpdate", Boolean.toString(needUpdate(userAccount, updateCutoff)));
map.put("logOutUrl", provider.getWebflowConfiguration().get().getLogoutUrl(request));
map.put("provider", new OAuthProvider(provider.getId(), provider.getLabel(), provider.getWebflowConfiguration().get()));
map.put("sysadmin", userAccount == null ? false : userRepositoryRoleService.isSysadmin(userAccount));
return new ResponseEntity<>(map, HttpStatus.OK);
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class UserService method delete.
@Transactional
public void delete(final String userId) {
User userToDelete = cache.withUser(userId).getUser();
if (userToDelete != null) {
eventPublisher.publishEvent(new AppEvent(this, userId, EventType.USER_DELETED));
userRepository.delete(userToDelete);
if (userToDelete.hasEmailAddress()) {
notificationService.sendNotification(new DeleteAccountMessage(userToDelete));
}
}
}
Aggregations