當前位置: 首頁>>代碼示例>>Java>>正文


Java SavedRequest類代碼示例

本文整理匯總了Java中org.springframework.security.web.savedrequest.SavedRequest的典型用法代碼示例。如果您正苦於以下問題:Java SavedRequest類的具體用法?Java SavedRequest怎麽用?Java SavedRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SavedRequest類屬於org.springframework.security.web.savedrequest包,在下文中一共展示了SavedRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
    SavedRequest savedRequest = this.requestCache.getRequest(request, response);
    if(savedRequest == null) {
        //super.onAuthenticationSuccess(request, response, authentication);
        handle(request, response, authentication);
        super.clearAuthenticationAttributes(request);
    } else {
        String targetUrlParameter = this.getTargetUrlParameter();
        if(!this.isAlwaysUseDefaultTargetUrl() && (targetUrlParameter == null || !StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
            this.clearAuthenticationAttributes(request);
            String targetUrl = savedRequest.getRedirectUrl();
            this.logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
            //this.getRedirectStrategy().sendRedirect(request, response, targetUrl);
        } else {
            this.requestCache.removeRequest(request, response);
            //super.onAuthenticationSuccess(request, response, authentication);
            handle(request, response, authentication);
            super.clearAuthenticationAttributes(request);
        }
    }
}
 
開發者ID:luotuo,項目名稱:springboot-security-wechat,代碼行數:22,代碼來源:MyAuthenticationSuccessHandler.java

示例2: loginSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
/**
 * 如果是訪問受限頁麵後,跳轉到登錄頁的,則在targetUrl保存之前受限頁麵的路徑,供頁麵調用
 *
 * @param request
 * @param response
 * @return
 */
@RequestMapping(value = "/login/success", method = RequestMethod.GET)
public @ResponseBody  JSONObject loginSuccess(HttpServletRequest request, HttpServletResponse response) {
	SavedRequest savedRequest = requestCache.getRequest(request, response);
	String targetUrl = null;
	if (savedRequest != null) {
		targetUrl = savedRequest.getRedirectUrl();
	}
	Map<String, Object> result = new HashMap<>();
	result.put("success", true);
	result.put("targetUrl", targetUrl);
	UserDetails userDetails = UserDetailsUtil.getCurrentUser();
	result.put("userDetails",userDetails);

	if(userDetails!=null) {
		SessionInfo sessionInfo = new SessionInfo();
		sessionInfo.setUsername(userDetails.getUsername());
		request.getSession().setAttribute("sessionInfo", sessionInfo);
		result.put("sessionInfo",sessionInfo);
	}
	return JsonUtil.getSuccessJsonObject(result);
}
 
開發者ID:fier-liu,項目名稱:FCat,代碼行數:29,代碼來源:SecurityController.java

示例3: parseSpringSecurityLoginUrlWithExtraParameters

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
/**
 * 坑爹大全 !
 * 在 spring security 中,loginPage("/login") 是個特殊的 url (其他的 url 沒有此限製,非 spring security 環境也無此限製)
 * 處理 /login 的 controller ,利用 @RequestParam(value = "error", required = false) 是無法接到任何參數信息的
 * "http://localhost:8888/login?error=錯誤信息" 的 error 參數無法接到,不光是 error ,所有的參數都接不到
 * spring security 把  "http://localhost:8888/login?error=錯誤信息"
 * 處理為 "http://localhost:8888/login" ,直接發給 controller ,為啥呢?
 * 當常見的需求是,登陸成功或者不成功,還想返回 /login ,並且傳遞點參數 /login?error=失敗
 * 無法處理
 * 但 spring security 又提供了一個 org.springframework.security.web.savedrequest.SavedRequest ,來還原原始 request,可以利用它來獲取參數
 * 這麽做為什麽?不知道
 * 又浪費了幾個小時查找資料
 *
 * @param request  GET 方式發送的 http://localhost:8888/login?error=abc&rr=dce
 * @param response
 * @return
 */
public static Map<String, String> parseSpringSecurityLoginUrlWithExtraParameters(HttpServletRequest request, HttpServletResponse response) {

    SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
    if (savedRequest == null)
        return Maps.newHashMap(); // 空 map,避免異常

    Map<String, String[]> map0 = savedRequest.getParameterMap(); //難道參數的值是個多個字符串? 為什麽返回 Map<String, String[]>  ?
    Map map = new HashMap<String, String>(map0.size());

    for (Map.Entry<String, String[]> entry : map0.entrySet()) {
        map.put(entry.getKey(), entry.getValue()[0]);
    }

    MyFastJsonUtils.prettyPrint(map);

    return map;
}
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:35,代碼來源:SpringUtils.java

示例4: getRequestReturnsSavedIfSavedRequestCookieExistsOnRequest

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
@Test
public void getRequestReturnsSavedIfSavedRequestCookieExistsOnRequest() throws Exception {
    CookieRequestCache requestCache = createCookieRequestCache();
    MockHttpServletRequest request = new MockHttpServletRequest();
    String savedUrl = "https://example.com/some/path/name?query=value&a=b";
    String encodedUrl = Base64.getMimeEncoder(Integer.MAX_VALUE, new byte[]{'\n'}).encodeToString(savedUrl.getBytes(StandardCharsets.ISO_8859_1));
    request.setCookies(new Cookie(COOKIE_NAME, encodedUrl));

    SavedRequest savedRequest = requestCache.getRequest(request, new MockHttpServletResponse());

    assertThat(savedRequest, notNullValue());
    assertThat(savedRequest.getRedirectUrl(), equalTo(savedUrl));
    assertThat(savedRequest.getCookies().size(), equalTo(0));
    assertThat(savedRequest.getMethod(), equalToIgnoringCase("GET"));
    assertThat(savedRequest.getHeaderValues("anything").size(), equalTo(0));
    assertThat(savedRequest.getHeaderNames().size(), equalTo(0));
    assertThat(savedRequest.getLocales().size(), equalTo(0));
    assertThat(savedRequest.getParameterValues("anything").length, equalTo(0));
    assertThat(savedRequest.getParameterMap().size(), equalTo(0));
}
 
開發者ID:AusDTO,項目名稱:spring-security-stateless,代碼行數:21,代碼來源:CookieRequestCacheTest.java

示例5: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
	SavedRequest savedRequest = requestCache.getRequest(request, response);

	if (savedRequest == null) {
		clearAuthenticationAttributes(request);
		return;
	}

	String targetUrlParam = getTargetUrlParameter();
	if (isAlwaysUseDefaultTargetUrl() || (targetUrlParam != null && StringUtils.hasText(request.getParameter(targetUrlParam)))) {
		requestCache.removeRequest(request, response);
		clearAuthenticationAttributes(request);
		return;
	}

	clearAuthenticationAttributes(request);
}
 
開發者ID:TechGapItalia,項目名稱:tgi-commons,代碼行數:19,代碼來源:RestSuccessHandler.java

示例6: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws ServletException, IOException {
    SavedRequest savedRequest = requestCache.getRequest(request, response);

    if (savedRequest == null) {
        clearAuthenticationAttributes(request);
        return;
    }
    String targetUrlParam = getTargetUrlParameter();
    if (isAlwaysUseDefaultTargetUrl()
            || (targetUrlParam != null && StringUtils.hasText(request.getParameter(targetUrlParam)))) {
        requestCache.removeRequest(request, response);
        clearAuthenticationAttributes(request);
        return;
    }
    clearAuthenticationAttributes(request);
}
 
開發者ID:MaritimeConnectivityPlatform,項目名稱:IdentityRegistry,代碼行數:19,代碼來源:RestAuthenticationSuccessHandler.java

示例7: getTargetUrlFromSavedRequest

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
private String getTargetUrlFromSavedRequest(HttpServletRequest request,
        SavedRequest savedRequest) {
    String targetUrl = null;
    if (savedRequest != null) {
        // get saved absolute target URL
        targetUrl = savedRequest.getRedirectUrl();
        String url = targetUrl.toLowerCase(Locale.ENGLISH);
        // assert that there is no down-grade to HTTP if current request is HTTPS
        if (request.isSecure() && !url.startsWith("https:")) {
            // convert to relative URL
            targetUrl = convertToRelativeUrl(request, targetUrl);
        }
        if (targetUrl == null) {
            LOGGER.debug(
                    "Target URL from saved request could not be converted to a relative URL: {}",
                    savedRequest.getRedirectUrl());
        } else {
            LOGGER.debug("Found target URL in saved request: {}", targetUrl);
        }
    }
    return targetUrl;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:23,代碼來源:CommunoteAuthenticationSuccessHandler.java

示例8: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
		throws IOException, ServletException {

	SavedRequest savedRequest = requestCache.getRequest(request, response);

	if (savedRequest == null) {
		clearAuthenticationAttributes(request);
		return;
	}

	String targetUrlParam = getTargetUrlParameter();
	if (isAlwaysUseDefaultTargetUrl()
			|| (targetUrlParam != null
			&& StringUtils.hasText(request.getParameter(targetUrlParam)))) {
		requestCache.removeRequest(request, response);
		clearAuthenticationAttributes(request);
		return;
	}

	clearAuthenticationAttributes(request);
}
 
開發者ID:RBGKew,項目名稱:powop,代碼行數:23,代碼來源:RestSavedRequestAwareAuthenticationSuccessHandler.java

示例9: handle

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
/**
 * First check for a <code>SavedRequest</code> and if none exists continue
 * as per {@link AbstractAuthenticationTargetUrlRequestHandler}.
 */
protected void handle(HttpServletRequest request,
        HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException {
    SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(
            request, response);
    String targetUrl = savedRequest.getRedirectUrl();
    System.out.println("requested url: " + targetUrl);

    if (targetUrl == null) {
        targetUrl = determineTargetUrl(request, response);
    }

    if (response.isCommitted()) {
        logger.debug("Response has already been committed. Unable to redirect to "
                + targetUrl);
        return;
    }

    getRedirectStrategy().sendRedirect(request, response, targetUrl);
}
 
開發者ID:OneDecision,項目名稱:one-decision,代碼行數:25,代碼來源:RedirectingAuthenticationSuccessHandler.java

示例10: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
		HttpServletResponse response, Authentication authentication)
		throws IOException, ServletException {

	String userId = request.getParameter("employeeId");
	if (userId != null) {
		response.sendRedirect(request.getContextPath() + "/emp/myview/"
				+ userId);
	} else {
		SavedRequest savedRequest = new HttpSessionRequestCache()
				.getRequest(request, response);
		if (savedRequest != null) {
			response.sendRedirect(savedRequest.getRedirectUrl());
		} else {
			response.sendRedirect(request.getContextPath() + "/");
		}
	}
}
 
開發者ID:devintqa,項目名稱:pms,代碼行數:20,代碼來源:AuthenticationHandler.java

示例11: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
	createNewSession(request, response);
	SavedRequest savedRequest = requestCache.getRequest(request, response);
	if (savedRequest == null) {
		super.onAuthenticationSuccess(request, response, authentication);
		return;
	}
	String targetUrlParameter = getTargetUrlParameter();
	if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
		requestCache.removeRequest(request, response);
		super.onAuthenticationSuccess(request, response, authentication);
		return;
	}
	clearAuthenticationAttributes(request);
	String targetUrl = appendToken(savedRequest.getRedirectUrl(), request);
	logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
	getRedirectStrategy().sendRedirect(request, response, targetUrl);
}
 
開發者ID:xiaolongzuo,項目名稱:zxl,代碼行數:20,代碼來源:SavedRequestAwareAuthenticationSuccessHandler.java

示例12: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
        HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    SavedRequest savedRequest = requestCache.getRequest(request, response);

    if (savedRequest == null) {
        clearAuthenticationAttributes(request);
        return;
    }
    String targetUrlParam = getTargetUrlParameter();
    if (isAlwaysUseDefaultTargetUrl()
            || (targetUrlParam != null && StringUtils.hasText(request
                    .getParameter(targetUrlParam)))) {
        requestCache.removeRequest(request, response);
        clearAuthenticationAttributes(request);
        return;
    }
    clearAuthenticationAttributes(request);
}
 
開發者ID:OADA,項目名稱:oada-ref-impl-java,代碼行數:21,代碼來源:RestAuthenticationSuccessHandler.java

示例13: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {

 	SavedRequest savedRequest = 
 		    new HttpSessionRequestCache().getRequest(request, response);
 	
    if (savedRequest == null) {
          return;
     }
    HttpSession session = request.getSession();
    session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);

     
     // Use the DefaultSavedRequest URL
     String targetUrl = savedRequest.getRedirectUrl();
     logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
     response.sendRedirect(targetUrl);
 }
 
開發者ID:eteration,項目名稱:glassmaker,代碼行數:18,代碼來源:OAuth2AuthenticationFilter.java

示例14: testRedirectToSavedRequest

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
@Test
public void testRedirectToSavedRequest() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response, null);
    SavedRequest savedRequest = mock(SavedRequest.class);

    when(savedRequest.getRedirectUrl()).thenReturn(SAVED_REQUEST_URL);
    when(requestCache.getRequest(request, response)).thenReturn(savedRequest);

    handler.handle(context, mock(Authentication.class));

    assertEquals(SAVED_REQUEST_URL, response.getRedirectedUrl());
    assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
    assertTrue(response.isCommitted());
}
 
開發者ID:craftercms,項目名稱:profile,代碼行數:17,代碼來源:LoginSuccessHandleImplTest.java

示例15: onAuthenticationSuccess

import org.springframework.security.web.savedrequest.SavedRequest; //導入依賴的package包/類
@Override
public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws ServletException, IOException {
    final SavedRequest savedRequest = requestCache.getRequest(request, response);

    if (savedRequest == null) {
        clearAuthenticationAttributes(request);
        return;
    }
    final String targetUrlParameter = getTargetUrlParameter();
    if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
        requestCache.removeRequest(request, response);
        clearAuthenticationAttributes(request);
        return;
    }

    clearAuthenticationAttributes(request);

    // Use the DefaultSavedRequest URL
    // final String targetUrl = savedRequest.getRedirectUrl();
    // logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
    // getRedirectStrategy().sendRedirect(request, response, targetUrl);
}
 
開發者ID:kiranreddykasa,項目名稱:springrest-angularjs,代碼行數:23,代碼來源:MySavedRequestAwareAuthenticationSuccessHandler.java


注:本文中的org.springframework.security.web.savedrequest.SavedRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。