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

Java DefaultSavedRequest类代码示例

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

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



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

示例1: test_for_issue

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
public void test_for_issue() throws Exception {
        MockHttpServletRequest mockReq = new MockHttpServletRequest();
        DefaultSavedRequest request = new DefaultSavedRequest(mockReq, new PortResolver() {

            public int getServerPort(ServletRequest servletRequest) {
                return 0;
            }
        });

        String str = JSON.toJSONString(request, SerializerFeature.WriteClassName);
//        System.out.println(str);


        JSON.parseObject(str, Object.class, config);

        JSON.parseObject(str);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:DefaultSavedRequestTest.java


示例2: getAuthParameters

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
/**
 * Generate an authorization parameter map from the session's token request
 * @param defaultSavedRequest the default saved request from the session
 * @return a map of parameters containing the OAuth2 request details
 */
private Map<String, String> getAuthParameters(DefaultSavedRequest defaultSavedRequest) {
    Map<String, String> authParams = new HashMap<>();

    authParams.put(OAuth2Utils.CLIENT_ID,
            defaultSavedRequest.getParameterMap().get(OAuth2Utils.CLIENT_ID)[0]);

    authParams.put(OAuth2Utils.REDIRECT_URI,
            defaultSavedRequest.getParameterMap().get(OAuth2Utils.REDIRECT_URI)[0]);

    if(defaultSavedRequest.getParameterMap().get(OAuth2Utils.STATE) != null) {
        authParams.put(OAuth2Utils.STATE,
                defaultSavedRequest.getParameterMap().get(OAuth2Utils.STATE)[0]);
    }

    authParams.put(OAuth2Utils.RESPONSE_TYPE, "code");
    authParams.put(OAuth2Utils.USER_OAUTH_APPROVAL, "true");
    authParams.put(OAuth2Utils.GRANT_TYPE, "authorization_code");
    return authParams;
}
 
开发者ID:kbastani,项目名称:cloud-native-microservice-strangler-example,代码行数:25,代码来源:LoginController.java


示例3: testDisplayLoginPageWithOriginalSavedRequestIfSetupComplete

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@Test
public void testDisplayLoginPageWithOriginalSavedRequestIfSetupComplete() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE);
    when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.TRUE);
    when(mockSyncService.isDataStreamEnabled()).thenReturn(Boolean.TRUE);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/login"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:25,代码来源:AuthControllerTests.java


示例4: testDisplayLoginPageAfterAjaxRequestWhichFailedDueToExpiredSession

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@Test
public void testDisplayLoginPageAfterAjaxRequestWhichFailedDueToExpiredSession() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE);
    when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.TRUE);
    when(mockSyncService.isDataStreamEnabled()).thenReturn(Boolean.TRUE);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest");
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/login"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:26,代码来源:AuthControllerTests.java


示例5: testDisplaySyncStatusPageWhenOperationalSyncIncomplete

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@Test
public void testDisplaySyncStatusPageWhenOperationalSyncIncomplete() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.TRUE);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest");
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/initializing"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:24,代码来源:AuthControllerTests.java


示例6: testDisplayReindexStatusPageWhenReindexingIncomplete

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@Test
public void testDisplayReindexStatusPageWhenReindexingIncomplete() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE);
    when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.FALSE);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest");
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/reindexing"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:25,代码来源:AuthControllerTests.java


示例7: login

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(HttpServletRequest request, HttpServletResponse response, Model model) {
    HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
    httpSessionSecurityContextRepository.loadContext(holder);

    try {
        // 使用提供的证书认证用户
        List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN");
        Authentication auth = new UsernamePasswordAuthenticationToken(request.getParameter("username"), request.getParameter("password"), authorities);
        SecurityContextHolder.getContext().setAuthentication(authenticationManager.authenticate(auth));

        // 认证用户
        if(!auth.isAuthenticated())
            throw new CredentialException("用户不能够被认证");
    } catch (Exception ex) {
        // 用户不能够被认证,重定向回登录页
        logger.info(ex);
        return "login";
    }

    // 从会话得到默认保存的请求
    DefaultSavedRequest defaultSavedRequest = (DefaultSavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST");
    // 为令牌请求生成认证参数Map
    Map<String, String> authParams = getAuthParameters(defaultSavedRequest);
    AuthorizationRequest authRequest = new DefaultOAuth2RequestFactory(clientDetailsService).createAuthorizationRequest(authParams);
    authRequest.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"));
    model.addAttribute("authorizationRequest", authRequest);

    httpSessionSecurityContextRepository.saveContext(SecurityContextHolder.getContext(), holder.getRequest(), holder.getResponse());
    return "authorize";
}
 
开发者ID:chaokunyang,项目名称:microservices-event-sourcing,代码行数:32,代码来源:LoginController.java


示例8: getAuthParameters

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
/**
 * 为会话的令牌请求生成认证参数Map
 * @param defaultSavedRequest 会话中默认保存的SPRING_SECURITY_SAVED_REQUEST请求
 * @return 包含OAuth2请求明细的参数Map
 */
private Map<String,String> getAuthParameters(DefaultSavedRequest defaultSavedRequest) {
    Map<String, String> authParams = new HashMap<>();
    authParams.put(OAuth2Utils.CLIENT_ID, defaultSavedRequest.getParameterMap().get(OAuth2Utils.CLIENT_ID)[0]);
    authParams.put(OAuth2Utils.REDIRECT_URI, defaultSavedRequest.getParameterMap().get(OAuth2Utils.REDIRECT_URI)[0]);
    if(defaultSavedRequest.getParameterMap().get(OAuth2Utils.STATE) != null) {
        authParams.put(OAuth2Utils.STATE, defaultSavedRequest.getParameterMap().get(OAuth2Utils.STATE)[0]);
    }

    authParams.put(OAuth2Utils.RESPONSE_TYPE, "code");
    authParams.put(OAuth2Utils.USER_OAUTH_APPROVAL, "true");
    authParams.put(OAuth2Utils.GRANT_TYPE, "authorization_code");

    return authParams;
}
 
开发者ID:chaokunyang,项目名称:microservices-event-sourcing,代码行数:20,代码来源:LoginController.java


示例9: testDisplayDataStreamErrorPageWhenDataStreamFailure

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@Test
public void testDisplayDataStreamErrorPageWhenDataStreamFailure() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.TRUE);
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE);
    when(mockSyncService.isDataStreamEnabled()).thenReturn(Boolean.FALSE);
    Map<String, Object> derr = new HashMap<>();
    derr.put("disableMsg","There's a bar stuck in the foo");
    when(mockSyncService.getDataStreamErrorDetails()).thenReturn(derr);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest");
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/dataStreamError"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:29,代码来源:AuthControllerTests.java


示例10: saveRequest

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
/**
 * Saves a request in cache.
 * @param request HTTP request
 * @param response HTTP response
 */
@Override
public void saveRequest(HttpServletRequest request, HttpServletResponse response) {
	if (anyRequestMatcher.matches(request) && !ajaxRequestMatcher.matches(request)) {
		DefaultSavedRequest savedRequest = new DefaultSavedRequest(request, portResolver);
		HttpUtils.setStateParam(Config.RETURNTO_COOKIE,
				Utils.base64enc(savedRequest.getRedirectUrl().getBytes()), request, response);
	}
}
 
开发者ID:Erudika,项目名称:para,代码行数:14,代码来源:SimpleRequestCache.java


示例11: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
    HttpServletResponse response, Authentication authentication)
    throws ServletException, IOException {
  DefaultSavedRequest defaultSavedRequest = (DefaultSavedRequest) request
      .getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST_KEY");

  if (defaultSavedRequest != null) {
    log.debug("saved url: " + defaultSavedRequest.getRedirectUrl());
    getRedirectStrategy().sendRedirect(request, response,
        defaultSavedRequest.getRedirectUrl());
  } else {
    super.onAuthenticationSuccess(request, response, authentication);
  }
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:LearningAnalyticsProcessor,代码行数:16,代码来源:SecurityConfig.java


示例12: login

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(HttpServletRequest request, HttpServletResponse response, Model model) {

    HttpRequestResponseHolder responseHolder = new HttpRequestResponseHolder(request, response);
    sessionRepository.loadContext(responseHolder);

    try {
        // Authenticate the user with the supplied credentials
        List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN");

        Authentication auth =
                new UsernamePasswordAuthenticationToken(request.getParameter("username"),
                        request.getParameter("password"), authorities);

        SecurityContextHolder.getContext()
                .setAuthentication(authenticationManager.authenticate(auth));

        // Authenticate the user
        if(!authenticationManager.authenticate(auth).isAuthenticated())
            throw new CredentialException("User could not be authenticated");

    } catch (Exception ex) {
        // The user couldn't be authenticated, redirect back to login
        ex.printStackTrace();
        return "login";
    }

    // Get the default saved request from session
    DefaultSavedRequest defaultSavedRequest = ((DefaultSavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST"));

    // Generate an authorization parameter map for the token request
    Map<String, String> authParams = getAuthParameters(defaultSavedRequest);

    // Create the authorization request and put it in the view model
    AuthorizationRequest authRequest = new DefaultOAuth2RequestFactory(clients).createAuthorizationRequest(authParams);
    authRequest.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"));
    sessionRepository.saveContext(SecurityContextHolder.getContext(), responseHolder.getRequest(), responseHolder.getResponse());
    model.addAttribute("authorizationRequest", authRequest);

    // Return the token authorization view
    return "authorize";
}
 
开发者ID:kbastani,项目名称:cloud-native-microservice-strangler-example,代码行数:43,代码来源:LoginController.java


示例13: handleRequest

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(
        HttpServletRequest request, 
        HttpSession session, 
        Principal principal, 
        Model model) {
	logger.info("handleRequest");
    
    // Check if the Contributor has not yet provided all required details
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (StringUtils.isBlank(contributor.getEmail())) {
        return "redirect:/content/contributor/add-email";
    } else if (StringUtils.isBlank(contributor.getFirstName()) || StringUtils.isBlank(contributor.getLastName())) {
        return "redirect:/content/contributor/edit-name";
    } else if (contributor.getLocale() == null) {
        return "redirect:/content/contributor/edit-locale";
    } else if ((contributor.getTeams() == null) || contributor.getTeams().isEmpty()) {
        return "redirect:/content/contributor/edit-teams";
    } else if (StringUtils.isBlank(contributor.getMotivation())) {
        return "redirect:/content/contributor/edit-motivation";
    } else if (contributor.getTimePerWeek() == null) {
        return "redirect:/content/contributor/edit-time";
    } else {
        // Redirect to originally requested URL
        DefaultSavedRequest defaultSavedRequest = (DefaultSavedRequest) session.getAttribute("SPRING_SECURITY_SAVED_REQUEST");
        logger.info("defaultSavedRequest: " + defaultSavedRequest);
        if (defaultSavedRequest != null) {
            logger.info("Redirecting to " + defaultSavedRequest.getServletPath());
            return "redirect:" + defaultSavedRequest.getServletPath();
        }
    }
    
    model.addAttribute("numberCount", numberDao.readCount(contributor.getLocale()));
    model.addAttribute("letterCount", letterDao.readCount(contributor.getLocale()));
    model.addAttribute("syllableCount", syllableDao.readCount(contributor.getLocale()));
    model.addAttribute("wordCount", wordDao.readCount(contributor.getLocale()));
    model.addAttribute("storyBookCount", storyBookDao.readCount(contributor.getLocale()));
    model.addAttribute("audioCount", audioDao.readCount(contributor.getLocale()));
    model.addAttribute("imageCount", imageDao.readCount(contributor.getLocale()));
    model.addAttribute("videoCount", videoDao.readCount(contributor.getLocale()));
	
    return "content/main";
}
 
开发者ID:elimu-ai,项目名称:webapp,代码行数:44,代码来源:MainContentController.java


示例14: testSavedRequestIsNotAjax

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
@Test
public void testSavedRequestIsNotAjax() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    SavedRequest savedRequest = new DefaultSavedRequest(request, mockPortResolver);
    assertThat(WebUtils.isAjax(savedRequest), equalTo(false));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:7,代码来源:WebUtilsTests.java


示例15: getCallbackURL

import org.springframework.security.web.savedrequest.DefaultSavedRequest; //导入依赖的package包/类
/**
 * Get the callback URL for the specified request.
 *
 * @param request The request.
 * @return The callback URL.
 */
protected String getCallbackURL(HttpServletRequest request) {
	return new DefaultSavedRequest(request, getPortResolver()).getRedirectUrl();
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:10,代码来源:OAuthConsumerContextFilter.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java StreamUtil类代码示例发布时间:2022-05-22
下一篇:
Java JobStats类代码示例发布时间: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