Search in sources :

Example 36 with User

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;
}
Also used : User(com.aidanwhiteley.books.domain.User) Book(com.aidanwhiteley.books.domain.Book) Page(org.springframework.data.domain.Page) Principal(java.security.Principal) Around(org.aspectj.lang.annotation.Around)

Aggregations

User (com.aidanwhiteley.books.domain.User)36 Test (org.junit.Test)19 IntegrationTest (com.aidanwhiteley.books.util.IntegrationTest)16 Book (com.aidanwhiteley.books.domain.Book)15 BookRepositoryTest (com.aidanwhiteley.books.repository.BookRepositoryTest)9 URI (java.net.URI)3 DefaultOAuth2User (org.springframework.security.oauth2.core.user.DefaultOAuth2User)3 OAuth2User (org.springframework.security.oauth2.core.user.OAuth2User)3 Principal (java.security.Principal)2 Around (org.aspectj.lang.annotation.Around)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ClientRoles (com.aidanwhiteley.books.controller.dtos.ClientRoles)1 AccessForbiddenException (com.aidanwhiteley.books.controller.exceptions.AccessForbiddenException)1 Comment (com.aidanwhiteley.books.domain.Comment)1 Owner (com.aidanwhiteley.books.domain.Owner)1 Claims (io.jsonwebtoken.Claims)1 ExpiredJwtException (io.jsonwebtoken.ExpiredJwtException)1 LocalDateTime (java.time.LocalDateTime)1 List (java.util.List)1 Cookie (javax.servlet.http.Cookie)1