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);
}
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/"));
}
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();
}
}
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;
}
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"));
}
Aggregations