Java 类org.springframework.security.web.RedirectStrategy 实例源码

项目:jeffaschenk-commons    文件:AuthenticationFilter.java   
/**
 * 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");
}
项目:bootstrap    文件:RedirectAuthenticationEntryPointTest.java   
@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, "");
}
项目:spring-boot    文件:CustomAuthenticationFailureHandler.java   
/**
     * 打印必要的错误信息后,继续执行。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);
    }
项目:recaptcha-spring-boot-starter    文件:LoginFailuresCountingHandler.java   
@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);
}
项目:oauth-client-master    文件:UserAuthorizationSuccessfulAuthenticationHandlerTests.java   
/**
 * 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");
}
项目:cognitor    文件:OpenIdAuthenticationSuccessHandlerTest.java   
@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");
}
项目:molgenis    文件:TwoFactorAuthenticationFilter.java   
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);
}
项目:molgenis    文件:AccountController.java   
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);
}
项目:theLXGweb    文件:UrlAuthenticationSuccessHandler.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:theLXGweb    文件:UrlAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:springboot-security-wechat    文件:MySimpleUrlAuthenticationFailureHandler.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:springboot-security-wechat    文件:MySimpleUrlAuthenticationFailureHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return this.redirectStrategy;
}
项目:pathological-reports    文件:CustomAuthenticationSuccessHandler.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:pathological-reports    文件:CustomAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:TeamNote    文件:CustomSimpleUrlAuthenticationSuccessHandler.java   
/**
 * Allows overriding of the behaviour when redirecting to a target URL.
 */
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:TeamNote    文件:CustomSimpleUrlAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:InfoSys-1D    文件:ProfChoperAuthSuccessHandler.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:InfoSys-1D    文件:ProfChoperAuthSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:hockey-game    文件:CustomAuthenticationSuccessHandler.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:hockey-game    文件:CustomAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:judge    文件:SecurityConfiguration.java   
private AuthenticationFailureHandler failureHandler() {
    final String defaultFailureUrl = "/login?error";
    RedirectStrategy redirectStrategy = new FailureRedirectStrategy();
    return (request, response, exception) -> redirectStrategy.sendRedirect(request, response, defaultFailureUrl);
}
项目:SpringMvcBlog    文件:CustomSuccessHandler.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:SpringMvcBlog    文件:CustomSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:webpedidos    文件:JsfLoginUrlAuthenticationEntryPoint.java   
public RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:webpedidos    文件:JsfLoginUrlAuthenticationEntryPoint.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:graviteeio-access-management    文件:ClientAwareAuthenticationFailureHandler.java   
/**
 * Allows overriding of the behaviour when redirecting to a target URL.
 */
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:graviteeio-access-management    文件:ClientAwareAuthenticationFailureHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:spring-boot    文件:CustomAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:spring-boot    文件:CustomAuthenticationSuccessHandler.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:spring-boot    文件:MySimpleUrlAuthenticationSuccessHandler.java   
public void setRedirectStrategy(final RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:spring-boot    文件:MySimpleUrlAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:nikita-noark5-core    文件:AppAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:nikita-noark5-core    文件:AppAuthenticationSuccessHandler.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:spring-security-registration    文件:MySimpleUrlAuthenticationSuccessHandler.java   
public void setRedirectStrategy(final RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:spring-security-registration    文件:MySimpleUrlAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:spring-security-registration    文件:MyCustomLoginAuthenticationSuccessHandler.java   
public void setRedirectStrategy(final RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:spring-security-registration    文件:MyCustomLoginAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:abixen-platform    文件:PlatformAuthenticationSuccessHandler.java   
public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
    this.redirectStrategy = redirectStrategy;
}
项目:abixen-platform    文件:PlatformAuthenticationSuccessHandler.java   
protected RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}
项目:metaworks_framework    文件:BroadleafAuthenticationFailureRedirectStrategy.java   
public RedirectStrategy getRedirectStrategy() {
    return redirectStrategy;
}