Search in sources :

Example 1 with User

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);
}
Also used : User(cern.modesti.user.User) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 2 with User

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);
            }
        }
    }
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(cern.modesti.user.User) InputStreamReader(java.io.InputStreamReader) Resource(org.springframework.core.io.Resource) BufferedReader(java.io.BufferedReader) UserImpl(cern.modesti.user.UserImpl)

Example 3 with 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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(cern.modesti.user.User) Resource(org.springframework.hateoas.Resource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with User

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);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(cern.modesti.user.User) Authentication(org.springframework.security.core.Authentication) Request(cern.modesti.request.Request) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 5 with User

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);
}
Also used : User(cern.modesti.user.User) TaskAction(cern.modesti.workflow.task.TaskAction)

Aggregations

User (cern.modesti.user.User)11 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)3 Request (cern.modesti.request.Request)2 NotAuthorisedException (cern.modesti.workflow.task.NotAuthorisedException)2 TaskAction (cern.modesti.workflow.task.TaskAction)2 Resource (org.springframework.hateoas.Resource)2 ResponseEntity (org.springframework.http.ResponseEntity)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 Authentication (org.springframework.security.core.Authentication)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RequestProvider (cern.modesti.plugin.RequestProvider)1 UnsupportedRequestException (cern.modesti.plugin.UnsupportedRequestException)1 Point (cern.modesti.point.Point)1 PointImpl (cern.modesti.point.PointImpl)1 RequestHistoryServiceImpl (cern.modesti.request.history.RequestHistoryServiceImpl)1 UserImpl (cern.modesti.user.UserImpl)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Task (org.activiti.engine.task.Task)1 DateTime (org.joda.time.DateTime)1