Search in sources :

Example 1 with GoogleUser

use of org.broadinstitute.consent.http.authentication.GoogleUser in project consent by DataBiosphere.

the class ResearcherServiceTest method setUp.

@Before
public void setUp() {
    GoogleUser googleUser = new GoogleUser();
    googleUser.setName("Test User");
    googleUser.setEmail("test@gmail.com");
    authUser = new AuthUser(googleUser);
    user = new User();
    user.setEmail(authUser.getEmail());
    user.setDacUserId(RandomUtils.nextInt(1, 10));
    user.setDisplayName(RandomStringUtils.random(10));
    MockitoAnnotations.initMocks(this);
}
Also used : GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) AuthUser(org.broadinstitute.consent.http.models.AuthUser) Before(org.junit.Before)

Example 2 with GoogleUser

use of org.broadinstitute.consent.http.authentication.GoogleUser in project consent by DataBiosphere.

the class DACUserResourceTest method setUp.

@Before
public void setUp() throws Exception {
    openMocks(this);
    GoogleUser googleUser = new GoogleUser();
    googleUser.setName("Test User");
    googleUser.setEmail("test@gmail.com");
    authUser = new AuthUser(googleUser);
    when(uriInfo.getRequestUriBuilder()).thenReturn(uriBuilder);
    when(uriBuilder.path(Mockito.anyString())).thenReturn(uriBuilder);
    when(uriBuilder.build(anyString())).thenReturn(new URI("http://localhost:8180/api/dacuser/"));
}
Also used : GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) AuthUser(org.broadinstitute.consent.http.models.AuthUser) URI(java.net.URI) Before(org.junit.Before)

Example 3 with GoogleUser

use of org.broadinstitute.consent.http.authentication.GoogleUser in project consent by DataBiosphere.

the class UserResource method createResearcher.

@POST
@Consumes("application/json")
@Produces("application/json")
@PermitAll
public Response createResearcher(@Context UriInfo info, @Auth AuthUser user) {
    GoogleUser googleUser = user.getGoogleUser();
    if (googleUser == null || googleUser.getEmail() == null || googleUser.getName() == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity(new Error("Unable to verify google identity", Response.Status.BAD_REQUEST.getStatusCode())).build();
    }
    try {
        if (userService.findUserByEmail(googleUser.getEmail()) != null) {
            return Response.status(Response.Status.CONFLICT).entity(new Error("Registered user exists", Response.Status.CONFLICT.getStatusCode())).build();
        }
    } catch (NotFoundException nfe) {
    // no-op, we expect to not find the new user in this case.
    }
    User dacUser = new User(googleUser);
    UserRole researcher = new UserRole(UserRoles.RESEARCHER.getRoleId(), UserRoles.RESEARCHER.getRoleName());
    dacUser.setRoles(Collections.singletonList(researcher));
    try {
        URI uri;
        dacUser = userService.createUser(dacUser);
        uri = info.getRequestUriBuilder().path("{email}").build(dacUser.getEmail());
        return Response.created(new URI(uri.toString().replace("user", "dacuser"))).entity(dacUser).build();
    } catch (Exception e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())).build();
    }
}
Also used : GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) SimplifiedUser(org.broadinstitute.consent.http.service.UserService.SimplifiedUser) GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) UserRole(org.broadinstitute.consent.http.models.UserRole) Error(org.broadinstitute.consent.http.models.dto.Error) NotFoundException(javax.ws.rs.NotFoundException) URI(java.net.URI) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PermitAll(javax.annotation.security.PermitAll)

Example 4 with GoogleUser

use of org.broadinstitute.consent.http.authentication.GoogleUser in project consent by DataBiosphere.

the class DACUserResource method findByAuthUser.

private User findByAuthUser(AuthUser user) {
    GoogleUser googleUser = user.getGoogleUser();
    User dacUser = userService.findUserByEmail(googleUser.getEmail());
    if (dacUser == null) {
        throw new NotFoundException("Unable to find user :" + user.getEmail());
    }
    return dacUser;
}
Also used : GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) NotFoundException(javax.ws.rs.NotFoundException)

Example 5 with GoogleUser

use of org.broadinstitute.consent.http.authentication.GoogleUser in project consent by DataBiosphere.

the class UserResourceTest method setUp.

@Before
public void setUp() throws URISyntaxException {
    GoogleUser googleUser = new GoogleUser();
    googleUser.setName("Test User");
    googleUser.setEmail(TEST_EMAIL);
    authUser = new AuthUser(googleUser).setAuthToken("auth-token").setUserStatusInfo(userStatusInfo);
    openMocks(this);
    when(uriInfo.getRequestUriBuilder()).thenReturn(uriBuilder);
    when(uriBuilder.path(anyString())).thenReturn(uriBuilder);
    when(uriBuilder.build(anyString())).thenReturn(new URI("http://localhost:8180/dacuser/api"));
}
Also used : GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) AuthUser(org.broadinstitute.consent.http.models.AuthUser) URI(java.net.URI) Before(org.junit.Before)

Aggregations

GoogleUser (org.broadinstitute.consent.http.authentication.GoogleUser)5 AuthUser (org.broadinstitute.consent.http.models.AuthUser)5 URI (java.net.URI)3 User (org.broadinstitute.consent.http.models.User)3 Before (org.junit.Before)3 NotFoundException (javax.ws.rs.NotFoundException)2 PermitAll (javax.annotation.security.PermitAll)1 BadRequestException (javax.ws.rs.BadRequestException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 UserRole (org.broadinstitute.consent.http.models.UserRole)1 Error (org.broadinstitute.consent.http.models.dto.Error)1 SimplifiedUser (org.broadinstitute.consent.http.service.UserService.SimplifiedUser)1