本文整理汇总了Java中org.springframework.security.test.context.support.WithUserDetails类的典型用法代码示例。如果您正苦于以下问题:Java WithUserDetails类的具体用法?Java WithUserDetails怎么用?Java WithUserDetails使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WithUserDetails类属于org.springframework.security.test.context.support包,在下文中一共展示了WithUserDetails类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_user1_defaultAfterLogin
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails("[email protected]")
public void test_user1_defaultAfterLogin() throws Exception {
mvc
.perform(get("/default"))
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("/"))
.andDo(print())
;
}
示例2: testGetVoteMvc
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails("jos")
public void testGetVoteMvc() throws Exception {
final long qaId = 123;
final Vote vote = new Vote(null, null, true);
final CustomUserDetails josUserDetails = (CustomUserDetails)this.userDetailsService.loadUserByUsername("jos");
given(this.voteService.getVoteByUser(qaId, josUserDetails)).willReturn(vote);
this.mvc.perform(get("/vote/" + qaId)
.with(csrf())
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.up", is(vote.isUp())));
}
示例3: withoutPermissionTest
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails("joao")
public void withoutPermissionTest() {
List<BoxConfigurationData> groupDTOs = new ArrayList<BoxConfigurationData>();
BoxConfigurationData b = new BoxConfigurationData();
b.setId("box1");
b.setBoxesDefinition(new ArrayList<BoxDefinitionData>());
b.setProcesses(new ArrayList<RequirementDefinitionDTO>());
groupDTOs.add(b);
BoxConfigurationData b2 = new BoxConfigurationData();
b2.setId("box2");
b2.setBoxesDefinition(new ArrayList<BoxDefinitionData>());
b2.setProcesses(new ArrayList<RequirementDefinitionDTO>());
groupDTOs.add(b2);
String idUsuario = "joao";
authorizationService.filterBoxWithPermissions(groupDTOs, idUsuario);
Assert.assertEquals(0, groupDTOs.size());
}
示例4: testLoadDraft
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@WithUserDetails("vinicius.nunes")
@Test
public void testLoadDraft() {
tester = new SingularWicketTester(singularApplication);
FormPage p = saveDraft();
RequirementInstance requirement = getRequirementFrom(p);
ActionContext context = new ActionContext();
context.setFormName(SPackageFOO.STypeFOO.FULL_NAME);
context.setFormAction(FormAction.FORM_FILL);
context.setRequirementId(requirement.getCod());
FormPage p2 = new FormPage(context);
tester.startPage(p2);
tester.assertRenderedPage(FormPage.class);
TextField<String> t2 = (TextField<String>) new AssertionsWComponent(p2).getSubComponents(TextField.class).first().getTarget();
assertEquals(SUPER_TESTE_STRING, t2.getDefaultModelObject());
}
示例5: deleteItem
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@WithUserDetails("vinicius.nunes")
@Test(expected = RestartResponseException.class)
public void deleteItem() {
tester = new SingularWicketTester(singularApplication);
BoxPage boxPage = new BoxPage(null);
tester.startPage(boxPage);
tester.assertRenderedPage(BoxPage.class);
tester.assertNoErrorMessage();
Component deleteButton = tester.getAssertionsPage()
.getSubComponentWithId("actions")
.getSubComponentWithId("3")
.getSubComponentWithId("link")
.getTarget();
tester.executeAjaxEvent(deleteButton, "click");
tester.assertNoErrorMessage();
Component confirmButton = tester.getAssertionsPage()
.getSubComponentWithId("confirm-btn")
.getTarget();
tester.executeAjaxEvent(confirmButton, "click");
tester.assertNoErrorMessage();
tester.assertRenderedPage(BoxPage.class);
tester.assertNoErrorMessage();
}
示例6: cancelDeleteItem
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@WithUserDetails("vinicius.nunes")
@Test(expected = RestartResponseException.class)
public void cancelDeleteItem() {
tester = new SingularWicketTester(singularApplication);
BoxPage boxPage = new BoxPage(null);
tester.startPage(boxPage);
tester.assertRenderedPage(BoxPage.class);
Component deleteButton = tester.getAssertionsPage()
.getSubComponentWithId("actions")
.getSubComponentWithId("3")
.getSubComponentWithId("link")
.getTarget();
tester.executeAjaxEvent(deleteButton, "click");
tester.assertNoErrorMessage();
Component confirmButton = tester.getAssertionsPage()
.getSubComponentWithId("cancel-btn")
.getTarget();
tester.executeAjaxEvent(confirmButton, "click");
tester.assertRenderedPage(BoxPage.class);
tester.assertNoErrorMessage();
}
示例7: historyForm
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@WithUserDetails("vinicius.nunes")
@Test(expected = RestartResponseException.class)
public void historyForm() {
tester = new SingularWicketTester(singularApplication);
sendRequirement(tester, SPackageFOO.STypeFOO.FULL_NAME, this::fillForm);
BoxPage boxPage = new BoxPage(null);
tester.startPage(boxPage);
Component historyLink = tester.getAssertionsPage()
.getSubComponentWithId("actions")
.getSubComponentWithId("5")
.getSubComponentWithId("link")
.getTarget();
tester.clickLink(historyLink);
tester.assertRenderedPage(HistoryPage.class);
}
示例8: testGetArtistMostPopularTracks
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails("[email protected]")
public void testGetArtistMostPopularTracks() throws Exception {
final Track track1 = new Track("track1", new Artist("The Beatles"), "album1", "/root/track1.mp3", null);
final Track track2 = new Track("track2", new Artist("The Beatles"), "album2", "/root/track2.mp3", null);
final Track track3 = new Track("track3", new Artist("Not The Beatles"), "album3", "/root/track3.mp3", null);
final Track track4 = new Track("track4", new Artist("The Beatles"), "album4", "/root/track4.mp3", null);
trackService.save(track1);
trackService.save(track2);
trackService.save(track3);
trackService.save(track4);
final List<Integer> trackIds = Arrays.asList(track1.getId(), track2.getId(), track3.getId(), track4.getId());
dbHistoryPopulateService.populateTrackListened(trackIds, SecurityUtil.currentUser().getId());
assertEquals(trackIds.size() - 1, trackService.getArtistMostPopularTracks("The Beatles").size());
}
示例9: testGetArtistMostPopularAlbums
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails("[email protected]")
public void testGetArtistMostPopularAlbums() throws Exception {
final Track track1 = new Track("track1", new Artist("Johann Sebastian Bach"), "The Best", "/root/track1.mp3", null);
final Track track2 = new Track("track2", new Artist("Johann Sebastian Bach"), "The Best", "/root/track2.mp3", null);
final Track track3 = new Track("track3", new Artist("Johann Sebastian Bach"), "The Best", "/root/track3.mp3", null);
final Track track4 = new Track("track4", new Artist("Johann Sebastian Bach"), "Not The Best", "/root/track4.mp3", null);
trackService.save(track1);
trackService.save(track2);
trackService.save(track3);
trackService.save(track4);
final List<Integer> trackIds = Arrays.asList(track1.getId(), track2.getId(), track3.getId(), track4.getId());
dbHistoryPopulateService.populateTrackListened(trackIds, SecurityUtil.currentUser().getId());
assertEquals(2, trackService.getArtistMostPopularAlbums("Johann Sebastian Bach").size());
}
示例10: registeredUserCannotAccessAdmin
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails(value = "erwin",
userDetailsServiceBeanName = "currentUserDetailsService")
public void registeredUserCannotAccessAdmin() throws Exception {
// Erwin a registered user but not in ROLE_POSTS
RequestBuilder request = get("/admin").with(csrf());
mvc.perform(request)
.andExpect(status().isForbidden())
.andExpect(forwardedUrl("/403"));
}
示例11: userLikedPosts_LoadsLikesView
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails(value = "keith")
public void userLikedPosts_LoadsLikesView() throws Exception {
this.mockMvc.perform(get("/posts/likes/3"))
.andExpect(status().isOk())
.andExpect(view().name(POSTS_LIKES_VIEW));
}
示例12: postPathsforAuthenticatedUsers
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails(value = "keith", userDetailsServiceBeanName = "currentUserDetailsService")
public void postPathsforAuthenticatedUsers() throws Exception {
// liked posts
mockMvc.perform(get("/json/posts/likes/3/page/2"))
.andExpect(status().isOk());
}
示例13: newLikedPostReturnsPlusOne
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails(value = "erwin", userDetailsServiceBeanName = "currentUserDetailsService")
public void newLikedPostReturnsPlusOne() throws Exception {
// no pre-existing post likes for Erwin
mockMvc.perform(get("/json/posts/post/like/3"))
.andExpect(content().string("1"))
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON));
}
示例14: existingLikedPostClickReturnsMinusOne
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails(value = "keith", userDetailsServiceBeanName = "currentUserDetailsService")
public void existingLikedPostClickReturnsMinusOne() throws Exception {
// pre-existing postId 3 like for Keith
mockMvc.perform(get("/json/posts/post/like/3"))
.andExpect(content().string("-1"))
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON));
}
示例15: loggedInUserCanAccessResetPasswordPage
import org.springframework.security.test.context.support.WithUserDetails; //导入依赖的package包/类
@Test
@WithUserDetails(value = "keith", userDetailsServiceBeanName = "currentUserDetailsService")
public void loggedInUserCanAccessResetPasswordPage() throws Exception {
RequestBuilder request = get("/users/resetpassword").with(csrf());
mvc.perform(request)
.andExpect(status().isOk())
.andExpect(model().attributeExists("userPasswordDTO"))
.andExpect(view().name(USER_CHANGEPASSWORD_VIEW));
}