use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class MailTemplatesCT method modifyUnknown_ShouldThrowNotFoundException.
@Test
public void modifyUnknown_ShouldThrowNotFoundException() {
MailTemplate detachedMailTemplate = new MailTemplate();
detachedMailTemplate.setId(9999L);
try {
service.modify(detachedMailTemplate);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class UsersCT method modify_ShouldThrowUnauthorizedError_WhenAuthenticatedUserDoesNotMatchLogin.
@Test
public void modify_ShouldThrowUnauthorizedError_WhenAuthenticatedUserDoesNotMatchLogin() throws Exception {
User detachedUserToModify = new User("test2@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
try {
when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(testUser.firstUser().getLogin()));
service.modify(sessionContextMock, detachedUserToModify);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class UsersCT method create_shouldThrowConflictExWhenUserWithGivenLoginAlreadyExists.
@Test
public void create_shouldThrowConflictExWhenUserWithGivenLoginAlreadyExists() throws Exception {
User user = new User();
user.setLogin("test@test.com");
try {
service.create(sessionContextMock, user);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.CONFLICT);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class Users method resetPassword.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{userLogin}/password")
@PermitAll
public void resetPassword(@NotNull @PathParam("userLogin") String userLogin, @QueryParam("token") String token, @NotNull String newPassword) {
User user;
if (sessionContext.isCallerInRole(ADMIN)) {
user = userFinder.findByLogin(userLogin);
} else if (sessionContext.isCallerInRole(USER)) {
user = userFinder.findByLogin(sessionContext.getCallerPrincipal().getName());
if (!userLogin.equals(user.getLogin())) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
} else {
user = userFinder.findByLogin(userLogin);
if (user == null || !user.getActionToken().equals(UUID.fromString(token))) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
user.setActionToken(null);
}
user.setPassword(hashSha256Base64(newPassword));
user.setActivated(true);
sendMail(user, Mails.userChangePassword);
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class Catalogs method delete.
@DELETE
@Transactional
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN })
@Path("/{catalogId}")
public void delete(@Context SecurityContext securityContext, @PathParam("catalogId") Long catalogId) {
Catalog loadedCatalog = entityManager.find(Catalog.class, catalogId);
checkNotNull(loadedCatalog);
if (isAdminUser(securityContext) || isOwner(securityContext, loadedCatalog.getOwner()))
entityManager.remove(loadedCatalog);
else
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
Aggregations