Search in sources :

Example 1 with AuthenticationPrincipalArgumentResolver

use of org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver in project theskeleton by codenergic.

the class UserPostRestControllerTest method init.

@Before
public void init() {
    mockMvc = MockMvcBuilders.standaloneSetup(new UserPostRestController(postService)).setCustomArgumentResolvers(new UserArgumentResolver(username -> new UserEntity().setUsername(username)), new AuthenticationPrincipalArgumentResolver(), new PageableHandlerMethodArgumentResolver()).apply(documentationConfiguration(restDocumentation)).build();
    Authentication authentication = new TestingAuthenticationToken(new UserEntity().setId(USER_ID).setUsername(USERNAME), "1234");
    SecurityContextHolder.getContext().setAuthentication(authentication);
}
Also used : PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) Authentication(org.springframework.security.core.Authentication) UserArgumentResolver(org.codenergic.theskeleton.core.web.UserArgumentResolver) AuthenticationPrincipalArgumentResolver(org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) UserEntity(org.codenergic.theskeleton.user.UserEntity) Before(org.junit.Before)

Example 2 with AuthenticationPrincipalArgumentResolver

use of org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver in project theskeleton by codenergic.

the class GalleryRestControllerTest method init.

@Before
public void init() {
    mockMvc = MockMvcBuilders.standaloneSetup(new GalleryRestController(galleryService)).setCustomArgumentResolvers(new AuthenticationPrincipalArgumentResolver(), new PageableHandlerMethodArgumentResolver()).apply(documentationConfiguration(restDocumentation)).build();
    Authentication authentication = new UsernamePasswordAuthenticationToken(new UserEntity().setId(USER_ID).setUsername(USERNAME), "1234");
    SecurityContextHolder.getContext().setAuthentication(authentication);
}
Also used : PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AuthenticationPrincipalArgumentResolver(org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver) UserEntity(org.codenergic.theskeleton.user.UserEntity) Before(org.junit.Before)

Example 3 with AuthenticationPrincipalArgumentResolver

use of org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver in project theskeleton by codenergic.

the class UserFollowerRestControllerTest method init.

@Before
public void init() {
    when(userDetailsService.loadUserByUsername(USERNAME)).thenReturn(new UserEntity().setId(USER_ID).setUsername(USERNAME));
    mockMvc = MockMvcBuilders.standaloneSetup(new UserFollowerRestController(userFollowerService)).setCustomArgumentResolvers(new UserArgumentResolver(userDetailsService), new AuthenticationPrincipalArgumentResolver(), new PageableHandlerMethodArgumentResolver()).apply(documentationConfiguration(restDocumentation)).build();
    Authentication authentication = new UsernamePasswordAuthenticationToken(new UserEntity().setId(USER_ID).setUsername(USERNAME), "1234");
    SecurityContextHolder.getContext().setAuthentication(authentication);
}
Also used : PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) Authentication(org.springframework.security.core.Authentication) UserArgumentResolver(org.codenergic.theskeleton.core.web.UserArgumentResolver) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AuthenticationPrincipalArgumentResolver(org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver) UserEntity(org.codenergic.theskeleton.user.UserEntity) Before(org.junit.Before)

Example 4 with AuthenticationPrincipalArgumentResolver

use of org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver in project spring-security by spring-projects.

the class WebMvcSecurityConfiguration method addArgumentResolvers.

@Override
@SuppressWarnings("deprecation")
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
    argumentResolvers.add(new AuthenticationPrincipalArgumentResolver());
    argumentResolvers.add(new org.springframework.security.web.bind.support.AuthenticationPrincipalArgumentResolver());
}
Also used : AuthenticationPrincipalArgumentResolver(org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver)

Example 5 with AuthenticationPrincipalArgumentResolver

use of org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver in project spring-security by spring-projects.

the class WebMvcSecurityConfiguration method addArgumentResolvers.

@Override
@SuppressWarnings("deprecation")
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
    AuthenticationPrincipalArgumentResolver authenticationPrincipalResolver = new AuthenticationPrincipalArgumentResolver();
    authenticationPrincipalResolver.setBeanResolver(this.beanResolver);
    argumentResolvers.add(authenticationPrincipalResolver);
    argumentResolvers.add(new org.springframework.security.web.bind.support.AuthenticationPrincipalArgumentResolver());
    CurrentSecurityContextArgumentResolver currentSecurityContextArgumentResolver = new CurrentSecurityContextArgumentResolver();
    currentSecurityContextArgumentResolver.setBeanResolver(this.beanResolver);
    argumentResolvers.add(currentSecurityContextArgumentResolver);
    argumentResolvers.add(new CsrfTokenArgumentResolver());
}
Also used : CurrentSecurityContextArgumentResolver(org.springframework.security.web.method.annotation.CurrentSecurityContextArgumentResolver) CsrfTokenArgumentResolver(org.springframework.security.web.method.annotation.CsrfTokenArgumentResolver) AuthenticationPrincipalArgumentResolver(org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver)

Aggregations

AuthenticationPrincipalArgumentResolver (org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver)6 UserEntity (org.codenergic.theskeleton.user.UserEntity)4 Before (org.junit.Before)4 PageableHandlerMethodArgumentResolver (org.springframework.data.web.PageableHandlerMethodArgumentResolver)4 Authentication (org.springframework.security.core.Authentication)4 UserArgumentResolver (org.codenergic.theskeleton.core.web.UserArgumentResolver)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)3 Date (java.util.Date)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 CsrfTokenArgumentResolver (org.springframework.security.web.method.annotation.CsrfTokenArgumentResolver)1 CurrentSecurityContextArgumentResolver (org.springframework.security.web.method.annotation.CurrentSecurityContextArgumentResolver)1