Search in sources :

Example 41 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class UserServiceImplTest method testCreateGoodPassword.

@Test
public void testCreateGoodPassword() {
    final User u = user();
    final String password = u.getPassword();
    final String encodedPassword = "ENCODED_" + password;
    when(passwordEncoder.encode(password)).thenReturn(encodedPassword);
    when(userRepository.save(u)).thenReturn(u);
    userService.create(u);
    assertEquals("User password was not encoded.", encodedPassword, u.getPassword());
    verify(passwordEncoder).encode(password);
    verify(userRepository).save(u);
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) Test(org.junit.Test)

Example 42 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class UserServiceImplTest method user.

private User user() {
    String username = "fbristow";
    String password = "Password1!";
    String email = "fbristow@gmail.com";
    String firstName = "Franklin";
    String lastName = "Bristow";
    String phoneNumber = "7029";
    User u = new User(username, email, password, firstName, lastName, phoneNumber);
    return u;
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User)

Example 43 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class UserServiceImplTest method testLoadUserByUsername.

@Test
public void testLoadUserByUsername() {
    User user = user();
    user.setSystemRole(Role.ROLE_USER);
    String username = user.getUsername();
    String password = user.getPassword();
    when(userRepository.loadUserByUsername(username)).thenReturn(user);
    UserDetails userDetails = userService.loadUserByUsername(username);
    assertEquals(username, userDetails.getUsername());
    assertEquals(password, userDetails.getPassword());
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) UserDetails(org.springframework.security.core.userdetails.UserDetails) Test(org.junit.Test)

Example 44 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class AssemblyFileProcessorTest method setUp.

@Before
public void setUp() throws IridaWorkflowNotFoundException {
    MockitoAnnotations.initMocks(this);
    processor = new AssemblyFileProcessor(objectRepository, submissionRepository, workflowsService, userRepository, ssoRepository, psjRepository);
    UUID workflowUUID = UUID.randomUUID();
    IridaWorkflowDescription workflowDescription = new IridaWorkflowDescription(workflowUUID, null, null, null, null, ImmutableList.of(), ImmutableList.of(), ImmutableList.of());
    IridaWorkflow workflow = new IridaWorkflow(workflowDescription, null);
    when(workflowsService.getDefaultWorkflowByType(AnalysisType.ASSEMBLY_ANNOTATION)).thenReturn(workflow);
    when(userRepository.loadUserByUsername("admin")).thenReturn(new User());
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) AssemblyFileProcessor(ca.corefacility.bioinformatics.irida.processing.impl.AssemblyFileProcessor) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) UUID(java.util.UUID) Before(org.junit.Before)

Example 45 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class RESTUsersController method getUserProjects.

/**
 * Get the collection of projects for a specific user.
 *
 * @param username
 *            the username for the desired user.
 * @return a model containing the collection of projects for that user.
 */
@RequestMapping(value = "/api/{username}/projects", method = RequestMethod.GET)
public ModelMap getUserProjects(@PathVariable String username) {
    logger.debug("Loading projects for user [" + username + "]");
    ModelMap mav = new ModelMap();
    // get the appropriate user from the database
    User u = userService.getUserByUsername(username);
    // get all of the projects that this user belongs to
    ResourceCollection<Project> resources = new ResourceCollection<>();
    List<Join<Project, User>> projects = projectService.getProjectsForUser(u);
    ControllerLinkBuilder linkBuilder = linkTo(RESTProjectsController.class);
    // add the project and a self-rel link to the project representation
    for (Join<Project, User> join : projects) {
        Project project = join.getSubject();
        project.add(linkBuilder.slash(project.getId()).withSelfRel());
        resources.add(project);
    }
    // add the resources to the response
    mav.addAttribute("projectResources", resources);
    // respond to the user
    return mav;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ModelMap(org.springframework.ui.ModelMap) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ControllerLinkBuilder(org.springframework.hateoas.mvc.ControllerLinkBuilder) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (ca.corefacility.bioinformatics.irida.model.user.User)252 Test (org.junit.Test)153 Project (ca.corefacility.bioinformatics.irida.model.project.Project)84 WithMockUser (org.springframework.security.test.context.support.WithMockUser)57 Authentication (org.springframework.security.core.Authentication)45 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)34 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 PageRequest (org.springframework.data.domain.PageRequest)26 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)25 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)24 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)24 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)19 Principal (java.security.Principal)19 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)18 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)18 List (java.util.List)18 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)17 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)16 ArrayList (java.util.ArrayList)16