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


Java RedirectStrategy類代碼示例

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


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

示例1: init

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
/**
 * Initialize the Singleton Session Cache.
 */
@PostConstruct
public synchronized void init() {
    // ************************************
    // Initialization
    log.info("AuthenticationFilter starting to Initialize.");
    // *********************************************
    // Create a blank redirect strategy
    // to prevent Spring automatically
    // returning page content in the output stream.
    SavedRequestAwareAuthenticationSuccessHandler srh = new SavedRequestAwareAuthenticationSuccessHandler();
    this.setAuthenticationSuccessHandler(srh);
    srh.setRedirectStrategy(new RedirectStrategy() {
        @Override
        public void sendRedirect(HttpServletRequest httpservletrequest,
                                 HttpServletResponse httpservletresponse, String s) throws IOException {
            //do nothing, no redirect
        }
    });
    // ***************************************
    // Proceed with additional Initialization
    log.info("AuthenticationFilter has been Initialized");
}
 
開發者ID:jaschenk,項目名稱:jeffaschenk-commons,代碼行數:26,代碼來源:AuthenticationFilter.java

示例2: testNoRedirect

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
@Test
public void testNoRedirect() throws IOException, ServletException {
	final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
	Mockito.when(request.getServletPath()).thenReturn("/somethingelse");
	final RedirectStrategy strategy = Mockito.mock(RedirectStrategy.class);
	entryPoint.setRedirectStrategy(strategy);
	entryPoint.commence(request, null, null);
	Mockito.verify(strategy, Mockito.atLeastOnce()).sendRedirect(request, null, "");
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:10,代碼來源:RedirectAuthenticationEntryPointTest.java

示例3: onAuthenticationFailure

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
/**
     * 打印必要的錯誤信息後,繼續執行。spring security 出現如下異常,控製台不打印信息,無法指定發生了哪種類型的錯誤
     *
     * @param request
     * @param response
     * @param exception
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        log.error("spring security Authentication Fail : {}", exception.getMessage());
        // spring security 不打印異常信息,無法定位錯誤,這裏打印出來
        // 不打印,通過 下麵的  sendRedirect 傳遞信息
        // exception.printStackTrace();

        RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
        redirectStrategy.sendRedirect(request, response, "/myerror?error=" + exception.getMessage());
        setDefaultFailureUrl("/myerror?error" + exception.getMessage());
        // setRedirectStrategy(redirectStrategy);

//        //根據錯誤情況,做不同的處理
//        //也可以設置  setDefaultFailureUrl("/url3"); 進行跳轉
//        if (exception.getClass().isAssignableFrom(UsernameNotFoundException.class)) {
//            log.info("用戶名沒找到");
//            // setDefaultFailureUrl("/url3");
//        } else if (exception.getClass().isAssignableFrom(DisabledException.class)) {
//            log.info("用戶無效");
//            // setDefaultFailureUrl("/url3");
//        } else if (exception.getClass().isAssignableFrom(BadCredentialsException.class)) {
//            log.info("用戶無效或被鎖定");
//            // setDefaultFailureUrl("/url1");
//        } else if (exception.getClass().isAssignableFrom(SessionAuthenticationException.class)) {
//            log.info("登錄會話過多");
//            exception.printStackTrace();
//             setDefaultFailureUrl("/url3");
//        } else if (exception.getClass().isAssignableFrom(InvalidCookieException.class)) {
//            log.info("RememberMe 異常 ,cookies 失效或格式不對");
//        }

        //繼續按照默認的流程執行,根據錯誤情況,進行跳轉
        // super.onAuthenticationFailure(request, response, exception);
    }
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:44,代碼來源:CustomAuthenticationFailureHandler.java

示例4: setRedirectStrategy

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
@Override
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    if (!RecaptchaAwareRedirectStrategy.class.isAssignableFrom(redirectStrategy.getClass())) {
        throw new IllegalArgumentException("Invalid redirect strategy. Redirect strategy must be an instance of " + RecaptchaAwareRedirectStrategy.class.getName() + " but is " + redirectStrategy);
    }
    super.setRedirectStrategy(redirectStrategy);
}
 
開發者ID:mkopylec,項目名稱:recaptcha-spring-boot-starter,代碼行數:8,代碼來源:LoginFailuresCountingHandler.java

示例5: testAuthenticationSuccess

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
/**
 * test determineTargetUrl
 */
@Test
public void testAuthenticationSuccess() throws Exception {

	UserAuthorizationSuccessfulAuthenticationHandler handler = new UserAuthorizationSuccessfulAuthenticationHandler();
	HttpServletRequest request = mock(HttpServletRequest.class);
	HttpServletResponse response = mock(HttpServletResponse.class);
	RedirectStrategy redirectStrategy = mock(RedirectStrategy.class);
	handler.setRedirectStrategy(redirectStrategy);

	when(request.getAttribute(UserAuthorizationProcessingFilter.CALLBACK_ATTRIBUTE)).thenReturn(
			"http://my.host.com/my/context");
	when(request.getAttribute(UserAuthorizationProcessingFilter.VERIFIER_ATTRIBUTE)).thenReturn("myver");
	when(request.getParameter("requestToken")).thenReturn("mytok");


	handler.onAuthenticationSuccess(request, response, null);

	verify(redirectStrategy).sendRedirect(request, response,
			"http://my.host.com/my/context?oauth_token=mytok&oauth_verifier=myver");

	handler = new UserAuthorizationSuccessfulAuthenticationHandler();
	handler.setRedirectStrategy(redirectStrategy);

	when(request.getAttribute(UserAuthorizationProcessingFilter.CALLBACK_ATTRIBUTE)).thenReturn(
			"http://my.hosting.com/my/context?with=some&query=parameter");
	when(request.getAttribute(UserAuthorizationProcessingFilter.VERIFIER_ATTRIBUTE)).thenReturn("myvera");
	when(request.getParameter("requestToken")).thenReturn("mytoka");

	handler.onAuthenticationSuccess(request, response, null);

	verify(redirectStrategy).sendRedirect(request, response,
			"http://my.hosting.com/my/context?with=some&query=parameter&oauth_token=mytoka&oauth_verifier=myvera");
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:37,代碼來源:UserAuthorizationSuccessfulAuthenticationHandlerTests.java

示例6: shouldRedirectToDefaultTargetUrlWhenNoOpenIdRequestGiven

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
@Test
public void shouldRedirectToDefaultTargetUrlWhenNoOpenIdRequestGiven() throws Exception {
    OpenIdAuthenticationSuccessHandler handler = new OpenIdAuthenticationSuccessHandler(openIdManagerMock);
    RedirectStrategy strategyMock = Mockito.mock(RedirectStrategy.class);
    handler.setDefaultTargetUrl("/loginFailed.html");
    handler.setRedirectStrategy(strategyMock);
    when(openIdManagerMock.isOpenIdRequest(requestMock)).thenReturn(false);

    handler.onAuthenticationSuccess(requestMock, responseMock, authenticationMock);

    verify(strategyMock, times(1)).sendRedirect(requestMock, responseMock, "/loginFailed.html");
}
 
開發者ID:patka,項目名稱:cognitor,代碼行數:13,代碼來源:OpenIdAuthenticationSuccessHandlerTest.java

示例7: TwoFactorAuthenticationFilter

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
public TwoFactorAuthenticationFilter(AuthenticationSettings authenticationSettings,
		TwoFactorAuthenticationService twoFactorAuthenticationService, RedirectStrategy redirectStrategy,
		UserAccountService userAccountService)
{
	this.authenticationSettings = requireNonNull(authenticationSettings);
	this.twoFactorAuthenticationService = requireNonNull(twoFactorAuthenticationService);
	this.redirectStrategy = requireNonNull(redirectStrategy);
	this.userAccountService = requireNonNull(userAccountService);
}
 
開發者ID:molgenis,項目名稱:molgenis,代碼行數:10,代碼來源:TwoFactorAuthenticationFilter.java

示例8: AccountController

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
public AccountController(AccountService accountService, CaptchaService captchaService,
		RedirectStrategy redirectStrategy, AuthenticationSettings authenticationSettings, UserFactory userFactory)
{
	this.accountService = requireNonNull(accountService);
	this.captchaService = requireNonNull(captchaService);
	this.redirectStrategy = requireNonNull(redirectStrategy);
	this.authenticationSettings = requireNonNull(authenticationSettings);
	this.userFactory = requireNonNull(userFactory);
}
 
開發者ID:molgenis,項目名稱:molgenis,代碼行數:10,代碼來源:AccountController.java

示例9: setRedirectStrategy

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
 
開發者ID:Recks11,項目名稱:theLXGweb,代碼行數:4,代碼來源:UrlAuthenticationSuccessHandler.java

示例10: getRedirectStrategy

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
 
開發者ID:Recks11,項目名稱:theLXGweb,代碼行數:4,代碼來源:UrlAuthenticationSuccessHandler.java

示例11: getRedirectStrategy

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
protected RedirectStrategy getRedirectStrategy() {
    return this.redirectStrategy;
}
 
開發者ID:luotuo,項目名稱:springboot-security-wechat,代碼行數:4,代碼來源:MySimpleUrlAuthenticationFailureHandler.java

示例12: setRedirectStrategy

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
	this.redirectStrategy = redirectStrategy;
}
 
開發者ID:edylle,項目名稱:pathological-reports,代碼行數:4,代碼來源:CustomAuthenticationSuccessHandler.java

示例13: getRedirectStrategy

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
protected RedirectStrategy getRedirectStrategy() {
	return redirectStrategy;
}
 
開發者ID:edylle,項目名稱:pathological-reports,代碼行數:4,代碼來源:CustomAuthenticationSuccessHandler.java

示例14: setRedirectStrategy

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
/**
 * Allows overriding of the behaviour when redirecting to a target URL.
 */
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
 
開發者ID:qinjr,項目名稱:TeamNote,代碼行數:7,代碼來源:CustomSimpleUrlAuthenticationSuccessHandler.java

示例15: failureHandler

import org.springframework.security.web.RedirectStrategy; //導入依賴的package包/類
private AuthenticationFailureHandler failureHandler() {
    final String defaultFailureUrl = "/login?error";
    RedirectStrategy redirectStrategy = new FailureRedirectStrategy();
    return (request, response, exception) -> redirectStrategy.sendRedirect(request, response, defaultFailureUrl);
}
 
開發者ID:zjnu-acm,項目名稱:judge,代碼行數:6,代碼來源:SecurityConfiguration.java


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