use of com.aidanwhiteley.books.domain.User in project books by aidanwhiteley.
the class LimitDataVisibilityAspect method limitPageOfBookDataImpl.
@SuppressWarnings("unchecked")
@Around("limitPageBookData()")
public Object limitPageOfBookDataImpl(ProceedingJoinPoint joinPoint) throws Throwable {
Object retVal = joinPoint.proceed();
Principal principal = getPrincipal(joinPoint);
Optional<User> user = authUtils.extractUserFromPrincipal(principal, true);
if (retVal instanceof Page) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("About to call setPermissionsAndContentForUser for {}", joinPoint.getSignature());
}
User theUser = user.orElse(null);
((Page<Book>) retVal).getContent().forEach(s -> s.setPermissionsAndContentForUser(theUser));
} else {
LOGGER.error("Unexpected return type found by aspect");
}
return retVal;
}
use of com.aidanwhiteley.books.domain.User in project books by aidanwhiteley.
the class ActuatorTest method checkActuatorEndpointsNotAvailableWithAdminRole.
@Test
void checkActuatorEndpointsNotAvailableWithAdminRole() {
// Re-use existing test class functionality to get a user without the ACTUATOR role
User user = BookControllerTestUtils.getTestUser();
user.addRole(User.Role.ROLE_ADMIN);
ResponseEntity<String> response = getResponseStringEntity(user, "/actuator");
assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode(), "User with only ROLE_ADMIN should be forbidden");
}
use of com.aidanwhiteley.books.domain.User in project books by aidanwhiteley.
the class ActuatorTest method checkExpectedEndpointAvailable.
@Test
void checkExpectedEndpointAvailable() {
User user = BookControllerTestUtils.getTestUser();
user.addRole(User.Role.ROLE_ACTUATOR);
ResponseEntity<String> response = getResponseStringEntity(user, "/actuator/scheduledtasks");
assertEquals(HttpStatus.OK, response.getStatusCode(), "User with ROLE_ACTUATOR should be able to see scheduledtasks");
}
use of com.aidanwhiteley.books.domain.User in project books by aidanwhiteley.
the class JwtAuthenticationUtilsTest method tryToGetUserFromPrincipal.
@Test
void tryToGetUserFromPrincipal() {
// For dumb coverage reasons we want some debug logging to run - it does give us a chance to view the output
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.getLogger(JwtAuthenticationUtils.class).setLevel(Level.valueOf("DEBUG"));
Optional<User> aUser = jwtAuthenticationUtils.extractUserFromPrincipal(getPrincipal(), false);
assertFalse(aUser.isPresent(), "Dummy user shouldnt be found in database");
context.getLogger(JwtAuthenticationUtils.class).setLevel(Level.valueOf("WARN"));
}
use of com.aidanwhiteley.books.domain.User in project books by aidanwhiteley.
the class UserServiceTest method testCreateActuatorUser.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
void testCreateActuatorUser() {
UserService userService = configureUserService();
userService.setAllowActuatorUserCreation(true);
User user = userService.createOrUpdateActuatorUser().get();
assertNotNull(user);
String id = user.getId();
assertEquals(LOCAL, user.getAuthProvider());
User user2 = userService.createOrUpdateActuatorUser().get();
String id2 = user.getId();
assertEquals(id, id2);
assertTrue(user2.getLastLogon().isAfter(user.getFirstLogon()), "Logon timestamp should have been updated");
}
Aggregations