use of cern.modesti.user.User in project modesti by jlsalmon.
the class MockUserServiceImpl method login.
public void login(String username) {
User user = findOneByUsername(username);
Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
}
use of cern.modesti.user.User in project modesti by jlsalmon.
the class MockUserServiceImpl method loadMockUsers.
private void loadMockUsers() throws IOException {
for (Resource resource : resolver.getResources("classpath*:mock-users.txt")) {
BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
String[] props = line.split(" ");
List<SimpleGrantedAuthority> roles = Arrays.stream(props[4].split(",")).map(SimpleGrantedAuthority::new).collect(Collectors.toList());
User user = new UserImpl(users.size() + 1, props[0], props[1], props[2], props[3], roles);
boolean store = true;
for (User existingUser : users) {
if (existingUser.getUsername().equals(user.getUsername())) {
store = false;
}
}
if (store) {
addMockUser(user);
}
}
}
}
use of cern.modesti.user.User in project modesti by jlsalmon.
the class TaskController method action.
@RequestMapping(value = "/{name}", method = POST, produces = "application/hal+json")
public HttpEntity<Resource<TaskInfo>> action(@PathVariable("id") String id, @PathVariable("name") String taskName, @RequestBody TaskAction action, Principal principal) {
User user = (User) ((UsernamePasswordAuthenticationToken) principal).getPrincipal();
TaskInfo task = taskService.execute(id, taskName, action, user);
if (task != null) {
Resource<TaskInfo> resource = new Resource<>(task);
resource.add(linkTo(methodOn(TaskController.class).getTask(id, resource.getContent().getName())).withSelfRel());
return new ResponseEntity<>(resource, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.OK);
}
use of cern.modesti.user.User in project modesti by jlsalmon.
the class UserTaskAssignmentHandler method notify.
@Override
public void notify(DelegateTask task) {
log.debug(format("handling assignment of task %s", task.getName()));
// Save the new assignee to the request object
Request request = requestService.findOneByRequestId((String) task.getVariable("requestId"));
if (task.getEventName().equals(TaskListener.EVENTNAME_ASSIGNMENT)) {
User assignee = userService.findOneByUsername(task.getAssignee());
String username = assignee == null ? null : assignee.getUsername();
request.setAssignee(username);
} else if (task.getEventName().equals(TaskListener.EVENTNAME_DELETE)) {
request.setAssignee(null);
}
// service account (which has admin privileges).
if (userService.getCurrentUser() == null) {
Authentication authentication = new UsernamePasswordAuthenticationToken("modesti", null, Collections.singletonList(new SimpleGrantedAuthority("modesti-administrators")));
SecurityContextHolder.getContext().setAuthentication(authentication);
}
requestService.save(request);
}
use of cern.modesti.user.User in project modesti by jlsalmon.
the class BaseIntegrationTest method doAction.
public void doAction(String requestId, TaskInfo task, TaskAction.Action action) {
assertNotNull(task);
User user = userService.getCurrentUser();
taskService.execute(requestId, task.getName(), new TaskAction(action, user.getUsername()), user);
}
Aggregations