• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WithAnonymousUser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.security.test.context.support.WithAnonymousUser的典型用法代码示例。如果您正苦于以下问题:Java WithAnonymousUser类的具体用法?Java WithAnonymousUser怎么用?Java WithAnonymousUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WithAnonymousUser类属于org.springframework.security.test.context.support包,在下文中一共展示了WithAnonymousUser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: postPathsforAnonymousUsers

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void postPathsforAnonymousUsers() throws Exception {

    // all posts
    mockMvc.perform(get("/json/posts/page/2"))
            .andExpect(status().isOk());

    // titles only
    mockMvc.perform(get("/json/posts/titles/page/2"))
            .andExpect(status().isOk());

    // by tag
    mockMvc.perform(get("/json/posts/tag/1/page/2"))
            .andExpect(status().isOk());

    // by tag titles
    mockMvc.perform(get("/json/posts/titles/tag/1/page/2"))
            .andExpect(status().isOk());

}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:22,代码来源:PostsRestControllerTests.java


示例2: registerPOST_userIsNotLoggedInAndInfoIsValidAndUserDoesNotExist_redirectToLogInView

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
/**
 * If the user is not logged in, is currently in the registration page and tries to register under the conditions:
 * - their input is valid;
 * - the username does not exist in the database,
 * they should be sent to the login page
 * @throws Exception
 */
@Test
@WithAnonymousUser
public void registerPOST_userIsNotLoggedInAndInfoIsValidAndUserDoesNotExist_redirectToLogInView() throws Exception
{
    User user = new User();
    user.setUsername("user");
    user.setPassword("password");

    mockMvc.perform(post("/register")
            .with(csrf())
            .param("username", user.getUsername())
            .param("password", user.getPassword()))
            .andExpect(status().isFound())
            .andExpect(redirectedUrl("/login"));
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:23,代码来源:AccessControllerTest.java


示例3: registerPOST_userIsNotLoggedInAndInfoIsValidAndUserExists_redirectToRegisterViewWithError

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
/**
 * If the user is not logged in, is currently in the registration page and tries to register under the conditions:
 * - their input is valid;
 * - the username exists in the database,
 * they should be sent back to the registration page with an error
 * @throws Exception
 */
@Test
@WithAnonymousUser
public void registerPOST_userIsNotLoggedInAndInfoIsValidAndUserExists_redirectToRegisterViewWithError() throws Exception
{
    User user = new User();
    user.setUsername("user");
    user.setPassword("password");
    Mockito.when(userRepository.findOne("user")).thenReturn(user);

    mockMvc.perform(post("/register")
            .with(csrf())
            .param("username", user.getUsername())
            .param("password", user.getPassword()))
            .andExpect(status().isFound())
            .andExpect(redirectedUrl("/register?exists"));
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:24,代码来源:AccessControllerTest.java


示例4: registerPOST_userIsNotLoggedInAndInfoIsNotValid_redirectToRegisterViewWithError

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
/**
 * If the user is not logged in, is currently in the registration page and tries to register under the condition:
 * - their input is invalid,
 * they should be sent back to the registration page with an error
 * @throws Exception
 */
@Test
@WithAnonymousUser
public void registerPOST_userIsNotLoggedInAndInfoIsNotValid_redirectToRegisterViewWithError() throws Exception
{
    User user = new User();
    user.setUsername("");
    user.setPassword("");

    mockMvc.perform(post("/register")
            .with(csrf())
            .param("username", user.getUsername())
            .param("password", user.getPassword()))
            .andExpect(status().isOk())
            .andExpect(model().hasErrors());
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:22,代码来源:AccessControllerTest.java


示例5: successfulAuthenticationWithAnonymousUser

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void successfulAuthenticationWithAnonymousUser() throws Exception {

    JwtAuthenticationRequest jwtAuthenticationRequest = new JwtAuthenticationRequest("user", "password");

    this.mvc.perform(post("/api/auth")
            .contentType(MediaType.APPLICATION_JSON)
            .content(new ObjectMapper().writeValueAsString(jwtAuthenticationRequest)))
            .andExpect(status().is2xxSuccessful());
}
 
开发者ID:adriano-fonseca,项目名称:rest-api-jwt-spring-security,代码行数:12,代码来源:AuthenticationRestControllerTest.java


示例6: shouldGetUnauthorizedWithAnonymousUser

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void shouldGetUnauthorizedWithAnonymousUser() throws Exception {

    this.mvc.perform(get("/refresh"))
            .andExpect(status().isUnauthorized());

}
 
开发者ID:adriano-fonseca,项目名称:rest-api-jwt-spring-security,代码行数:9,代码来源:AuthenticationRestControllerTest.java


示例7: anonymousCannotAccessAdmin

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void anonymousCannotAccessAdmin() throws Exception {

    // Whereas Erwin is forbidden, anonymous users redirected to login page
    RequestBuilder request = get("/admin").with(csrf());
    mvc.perform(request)
            .andExpect(status().is3xxRedirection())
            .andExpect(loginPage());
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:11,代码来源:AdminControllerTests.java


示例8: anonymousUserCannotAccessResetPasswordPage

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void anonymousUserCannotAccessResetPasswordPage() throws Exception {
    RequestBuilder request = get("/users/resetpassword").with(csrf());
    mvc.perform(request)
            .andExpect(status().is3xxRedirection())
            .andExpect(loginPage());
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:9,代码来源:UserPasswordControllerTests.java


示例9: resetPasswordPageWithTokenReturnsChangePasswordView

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void resetPasswordPageWithTokenReturnsChangePasswordView() throws Exception {
    RequestBuilder request = get("/users/resetpassword/" + UUID.randomUUID().toString()).with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("userPasswordDTO"))
            .andExpect(view().name(USER_CHANGEPASSWORD_VIEW));
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:10,代码来源:UserPasswordControllerTests.java


示例10: resetPasswordFromEmail

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void resetPasswordFromEmail() throws Exception {

    UserToken userToken = userService.createUserToken(erwin);
    RequestBuilder request = post("/users/resetpassword")
            .param("userId", "-400")
            .param("verificationToken", userToken.getToken())
            .param("password", "password")
            .param("repeatedPassword", "password").with(csrf());
    mvc.perform(request)
            .andExpect(model().attribute("feedbackMessage", containsString("login")));
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:14,代码来源:UserPasswordControllerTests.java


示例11: googleAnalyticsAnonymousUserTest

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void googleAnalyticsAnonymousUserTest() throws Exception {
    RequestBuilder request = get("/").with(csrf());
    MvcResult result = mockMvc.perform(request)
            .andReturn();

    assertTrue(result
            .getResponse()
            .getContentAsString()
            .contains(TRACKING_ID));
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:13,代码来源:GlobalControllerTests.java


示例12: logIn_userIsNotLoggedIn_goToLogInView

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
/**
 * If the user is not logged in and tries to load the login page, they should be sent to the login page
 * @throws Exception
 */
@Test
@WithAnonymousUser
public void logIn_userIsNotLoggedIn_goToLogInView() throws Exception
{
    mockMvc.perform(get("/login"))
            .andExpect(status().isOk());
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:12,代码来源:AccessControllerTest.java


示例13: registerGET_userIsNotLoggedIn_returnModelWithEmptyUser

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
/**
 * If the user is not logged in and tries to load the registration page, they should be sent to the registration page
 * @throws Exception
 */
@Test
@WithAnonymousUser
public void registerGET_userIsNotLoggedIn_returnModelWithEmptyUser() throws Exception
{
    mockMvc.perform(get("/register"))
            .andExpect(status().isOk())
            .andExpect(model().attribute("user",
                    hasProperty("username", isEmptyOrNullString())));
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:14,代码来源:AccessControllerTest.java


示例14: registerPOST_userIsNotLoggedInAndUsernameIsNull_redirectToRegisterViewWithError

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
/**
 * If the user is not logged in, is currently in the registration page and tries to register under the condition:
 * - their username is null (this condition should not be possible under normal usage),
 * they should be sent back to the registration page with an error
 * @throws Exception
 */
@Test
@WithAnonymousUser
public void registerPOST_userIsNotLoggedInAndUsernameIsNull_redirectToRegisterViewWithError() throws Exception
{
    User user = new User();
    user.setPassword("");

    mockMvc.perform(post("/register")
            .with(csrf())
            .param("username", user.getUsername())
            .param("password", user.getPassword()))
            .andExpect(status().isOk())
            .andExpect(model().hasErrors());
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:21,代码来源:AccessControllerTest.java


示例15: registerPOST_userIsNotLoggedInAndPasswordIsNull_redirectToRegisterViewWithError

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
/**
 * If the user is not logged in, is currently in the registration page and tries to register under the condition:
 * - their password is null (this condition should not be possible under normal usage),
 * they should be sent back to the registration page with an error
 * @throws Exception
 */
@Test
@WithAnonymousUser
public void registerPOST_userIsNotLoggedInAndPasswordIsNull_redirectToRegisterViewWithError() throws Exception
{
    User user = new User();
    user.setUsername("");

    mockMvc.perform(post("/register")
            .with(csrf())
            .param("username", user.getUsername())
            .param("password", user.getPassword()))
            .andExpect(status().isOk())
            .andExpect(model().hasErrors());
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:21,代码来源:AccessControllerTest.java


示例16: expectAnonymousUsersToBeAbleToCallCreateAuthenticationToken

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void expectAnonymousUsersToBeAbleToCallCreateAuthenticationToken() throws Exception {

    final JwtAuthenticationRequest jwtAuthenticationRequest =
            new JwtAuthenticationRequest("not-being-tested-here", "not-being-tested-here");

    mockMvc.perform(post("/auth")
            .contentType(MediaType.APPLICATION_JSON)
            .content(new ObjectMapper().writeValueAsString(jwtAuthenticationRequest)))
            .andExpect(status().is2xxSuccessful());
}
 
开发者ID:gazbert,项目名称:bxbot-ui-server,代码行数:13,代码来源:TestAuthenticationController.java


示例17: whenCreateTokenCalledWithBadCredentialsThenExpectUnauthorizedResponse

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void whenCreateTokenCalledWithBadCredentialsThenExpectUnauthorizedResponse() throws Exception {

    final JwtAuthenticationRequest jwtAuthenticationRequest =
            new JwtAuthenticationRequest("user", "bad-password");

    when(authenticationManager.authenticate(any())).thenThrow(new BadCredentialsException("invalid password!"));

    mockMvc.perform(post("/auth")
            .contentType(MediaType.APPLICATION_JSON)
            .content(new ObjectMapper().writeValueAsString(jwtAuthenticationRequest)))
            .andExpect(status().isUnauthorized());
}
 
开发者ID:gazbert,项目名称:bxbot-ui-server,代码行数:15,代码来源:TestAuthenticationController.java


示例18: test_welcome_WithAnonymousUser

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void test_welcome_WithAnonymousUser() throws Exception {
    mockMvc
            .perform(get("/"))
            .andExpect(status().isOk())
            .andExpect(view().name("index"))
            .andDo(print())
    ;
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:11,代码来源:WelcomeControllerTests.java


示例19: securityEnabled

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
@WithAnonymousUser
public void securityEnabled() throws Exception {
    mvc
            .perform(get("/admin/h2")
                    .header("X-Requested-With", "XMLHttpRequest")
            )
            .andExpect(status().isUnauthorized());
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:10,代码来源:CalendarApplicationTests.java


示例20: test_events_WithAnonymousUser

import org.springframework.security.test.context.support.WithAnonymousUser; //导入依赖的package包/类
@Test
    @WithAnonymousUser
    public void test_events_WithAnonymousUser() throws Exception {
        mvc.perform(get("/events/"))
                .andExpect(status().is3xxRedirection())
                .andExpect(redirectedUrl("http://localhost/login/form"))
//                .andExpect(redirectedUrlPattern("/login/form"))
        ;
    }
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:10,代码来源:CalendarApplicationTests.java



注:本文中的org.springframework.security.test.context.support.WithAnonymousUser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Monster类代码示例发布时间:2022-05-22
下一篇:
Java ZoomEvent类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap