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


Java DefaultRedirectStrategy類代碼示例

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


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

示例1: onAuthenticationFailure

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authenticationException) throws IOException, ServletException {
    saveException(request, authenticationException);
    String url = failureUrlMap.get(authenticationException.getClass().getName());
    if (url != null) {
        if (authenticationException instanceof UserAccountTemporarilyLockedException) {
            url += "&lockedTimeout="
                    + ((UserAccountTemporarilyLockedException) authenticationException)
                            .getLockedTimeout().getTime();
        }
        if (authenticationException instanceof UserAccountException) {
            url += "&username="
                    + ((UserAccountException) authenticationException).getUsername();
        }
        ControllerHelper.sendInternalRedirect(request, response, appendTargetUrl(url, request));
        return;
    }

    String failureUrl = authenticationFailureUrl;
    String redirectUrl = ControllerHelper.renderAbsoluteUrl(request, null, failureUrl, false,
            false, false);
    new DefaultRedirectStrategy().sendRedirect(request, response,
            appendTargetUrl(redirectUrl, request));
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:29,代碼來源:CommunoteAuthenticationFailureHandler.java

示例2: CommunoteLogoutFilter

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
/**
 * Instantiates a new logout filter.
 *
 * @param logoutSuccessUrl
 *            the logout success url
 * @param handlers
 *            the handlers
 */
public CommunoteLogoutFilter(final String logoutSuccessUrl, LogoutHandler[] handlers) {
    super(new SimpleUrlLogoutSuccessHandler() {
        {
            setDefaultTargetUrl(logoutSuccessUrl);
            setRedirectStrategy(new DefaultRedirectStrategy() {
                @Override
                public void sendRedirect(HttpServletRequest request,
                        HttpServletResponse response, String url) throws java.io.IOException {
                    if (url.startsWith("http://") || url.startsWith("https://")) {
                        throw new IllegalArgumentException(
                                "could not add client id to this uri: '" + url + "'");
                    }
                    // reset session values
                    SessionHandler.instance().resetOverriddenCurrentUserLocale(request);
                    ControllerHelper.sendInternalRedirect(request, response, url);
                };
            });
        }
    }, handlers);
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:29,代碼來源:CommunoteLogoutFilter.java

示例3: commence

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
@Override
  public void commence(HttpServletRequest request, HttpServletResponse response,
      AuthenticationException authException) throws IOException, ServletException {

//    if (LOG.isDebugEnabled()) {
//      LOG.debug("Redirigiendo a pantalla de login: " + LOGIN_FORM_URL);
//    }

    ContentNegotiationStrategy negotiationStrategy = new HeaderContentNegotiationStrategy();
    MediaTypeRequestMatcher matcher =
        new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_HTML);
    matcher.setUseEquals(false);

    if (matcher.matches(request)) {
      DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
      redirectStrategy.setContextRelative(false);
      redirectStrategy.sendRedirect(request, response, LOGIN_FORM_URL);
    } else {
      response.sendError(HttpServletResponse.SC_FORBIDDEN);
    }
  }
 
開發者ID:DISID,項目名稱:springlets,代碼行數:22,代碼來源:SpringletsSecurityWebAuthenticationEntryPoint.java

示例4: handle

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
    AccessDeniedException accessDeniedException) throws IOException, ServletException {

  ContentNegotiationStrategy negotiationStrategy = new HeaderContentNegotiationStrategy();
  MediaTypeRequestMatcher matcher =
      new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_HTML);
  matcher.setUseEquals(false);

  if (matcher.matches(request)) {
    DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
    redirectStrategy.setContextRelative(false);
    redirectStrategy.sendRedirect(request, response, "/errores/403");
  } else {
    response.sendError(HttpServletResponse.SC_FORBIDDEN);

  }

}
 
開發者ID:DISID,項目名稱:springlets,代碼行數:20,代碼來源:SpringletsSecurityWebAccessDeniedHandlerImpl.java

示例5: onAuthenticationSuccess

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

    userService.login(
            user.getSsn(),
            user.getFirstNames(),
            user.getLastName(),
            user.isFinnishCitizen(),
            new LocalizedString(user.getMunicipalityNameFi(), user.getMunicipalityNameSv()),
            request, response
    );

    new DefaultRedirectStrategy()
            .sendRedirect(request, response, baseUri + TargetStoringFilter.popCookieTarget(request, response));
}
 
開發者ID:solita,項目名稱:kansalaisaloite,代碼行數:17,代碼來源:SessionStoringAuthenticationSuccessHandler.java

示例6: onLogoutSuccess

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    String targetUri = TargetStoringFilter.popCookieTarget(request, response);

    // The first idea was to redirect the user to the previous page after logout.
    // But the problem are pages that are not visible for unauthenticated users. The user would end up to 403 page after logout.
    // Best solution would be just be to redirect user to frontpage if the default target page would give 403,
    // but unfortunately there is no time for that now so let's just get the user to localized frontpage after logout.

    // Redirect to default logout page that's responsible for setting the logout success message
    String localizedFrontPageUri =
            targetUri.startsWith(Urls.FRONT_SV) ? Urls.LOGOUT_SV : Urls.LOGOUT_FI;

    new DefaultRedirectStrategy()
            .sendRedirect(request, response, baseUri + localizedFrontPageUri);

}
 
開發者ID:solita,項目名稱:kansalaisaloite,代碼行數:18,代碼來源:SuccessfulLogoutRedirectHandler.java

示例7: onAuthenticationFailure

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
@Override
   public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
	if(exception instanceof UsernameNotFoundException
		&& exception.getAuthentication() instanceof OpenIDAuthenticationToken
           && ((OpenIDAuthenticationToken)exception.getAuthentication()).getStatus().equals(OpenIDAuthenticationStatus.SUCCESS)) {
		
		OpenIDAuthenticationToken token = (OpenIDAuthenticationToken)exception.getAuthentication();
		String url = token.getIdentityUrl();
		User user = createTemporaryUser(token, url);
		request.getSession(true).setAttribute(ModelKeys.NEW_USER, user);

		DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
		log.info("Redirecting to new user account creation page");
		super.setRedirectStrategy(redirectStrategy);
		redirectStrategy.sendRedirect(request, response, "/"+ViewNames.CREATE_ACCOUNT_PAGE);
		return;
	} else {
		super.onAuthenticationFailure(request, response, exception);
	}
}
 
開發者ID:apache,項目名稱:rave,代碼行數:21,代碼來源:OpenIDAuthenticationFailureHandler.java

示例8: configure

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
@Override
protected void configure(HttpSecurity http) throws Exception {
    SimpleUrlAuthenticationSuccessHandler simpleUrlAuthenticationSuccessHandler = new SimpleUrlAuthenticationSuccessHandler("/");
    simpleUrlAuthenticationSuccessHandler.setUseReferer(false);
    simpleUrlAuthenticationSuccessHandler.setTargetUrlParameter("url");
    DefaultRedirectStrategy defaultRedirectStrategy = new DefaultRedirectStrategy();

    simpleUrlAuthenticationSuccessHandler.setRedirectStrategy(defaultRedirectStrategy);

    SimpleUrlLogoutSuccessHandler simpleUrlLogoutSuccessHandler = new SimpleUrlLogoutSuccessHandler();
    simpleUrlLogoutSuccessHandler.setUseReferer(true);

    // @formatter:off
    http
        .authorizeRequests()
            .antMatchers(ckfinder.getServlet().getPath()).hasAnyRole("ADMIN")
            .and()
        .csrf()
            .disable()
        .exceptionHandling()
            .authenticationEntryPoint(authenticationEntryPoint())
            .and()
        .formLogin()
            .loginPage("/login")
            .usernameParameter("user_id1")
            .passwordParameter("password1")
            .successHandler(simpleUrlAuthenticationSuccessHandler)
            .failureHandler(failureHandler())
            .permitAll()
            .and()
        .headers()
            .cacheControl().disable()
            .httpStrictTransportSecurity().disable()
            .frameOptions().sameOrigin()
            .and()
        .logout()
            .logoutUrl("/logout.html")
            .logoutSuccessHandler(simpleUrlLogoutSuccessHandler)
            .permitAll()
            .and()
        .rememberMe()
            .rememberMeParameter("rememberMe")
            .tokenRepository(persistentTokenRepository)
            .and()
        .requestCache()
            .requestCache(new NullRequestCache())
            .and()
        .servletApi();
    // @formatter:on
}
 
開發者ID:zjnu-acm,項目名稱:judge,代碼行數:51,代碼來源:SecurityConfiguration.java

示例9: onAuthenticationFailure

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的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

示例10: handle

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
@Override
public void handle(
        HttpServletRequest request,
        HttpServletResponse response,
        AccessDeniedException accessDeniedException
) throws IOException, ServletException {

    if (accessDeniedException instanceof InvalidCsrfTokenException ||
            accessDeniedException instanceof MissingCsrfTokenException) {

        new DefaultRedirectStrategy().sendRedirect(request, response, "/editar/autenticar?sessao");
    }

    super.handle(request, response, accessDeniedException);
}
 
開發者ID:servicosgovbr,項目名稱:editor-de-servicos,代碼行數:16,代碼來源:CustomAccessDeniedHandler.java

示例11: redirectToSuccess

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
private void redirectToSuccess(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
    OpenIDAuthenticationToken openIDAuthentication = getOpenIdAuthenticationToken(exception);
    addOpenIdAttributesToSession(request, openIDAuthentication);
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(openIDAuthentication);
    HttpSession session = request.getSession(true);
    session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
    redirectStrategy.sendRedirect(request, response, "/");
}
 
開發者ID:dice-group,項目名稱:QRTool,代碼行數:12,代碼來源:OpenIdAuthenticationFailureHandler.java

示例12: onAuthenticationFailure

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {

    String targetUri = TargetStoringFilter.popCookieTarget(request, response);

    // Strip get parameters from redirect on failure to prevent re-login-loop
    // when users cancels login on eg. voting

    // IDP Currently does not tell us if the user has cancelled the authentication or there were failures during it.
    // Currently we just have to trust that IDP shows some nice error for the user if the authentication fails,
    // because we do not have any way to tell if the authentication was failed or cancelled.

    log.warn("Login failed / cancelled", exception);

    String path = new URL(baseUrl + targetUri).getPath();

    new DefaultRedirectStrategy()
            .sendRedirect(request, response, baseUrl + path);

}
 
開發者ID:solita,項目名稱:kansalaisaloite,代碼行數:21,代碼來源:RedirectingAuthenticationFailureHandler.java

示例13: onAuthenticationFailure

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
@Override
public void onAuthenticationFailure( HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception ) throws ServletException, IOException {

    String ajaxLoginTrue = request.getParameter( "ajaxLoginTrue" );

    if ( ajaxLoginTrue != null && ajaxLoginTrue.equals( "true" ) ) {

        JSONUtil jsonUtil = new JSONUtil( request, response );
        String jsonText = null;

        this.setRedirectStrategy( new RedirectStrategy() {

            @Override
            public void sendRedirect( HttpServletRequest re, HttpServletResponse res, String s ) {
                // do nothing, no redirect to make it work with extjs

            }
        } );

        super.onAuthenticationFailure( request, response, exception );
        JSONObject json = new JSONObject();
        json.put( "success", false );

        if ( exception.getClass().isAssignableFrom( BadCredentialsException.class ) ) {
            json.put( "message", "<strong>Warning!</strong> Login email/password incorrect." );
        } else if ( exception.getClass().isAssignableFrom( LockedException.class ) ) {
            json.put( "message",
                    "Your account has not been activated, please click the confirmation link that was e-mailed to you upon registration." );
        } else {
            json.put( "message", "Login Failed" );
        }
        jsonText = json.toString();
        jsonUtil.writeToResponse( jsonText );

    }

    else {

        this.setRedirectStrategy( new DefaultRedirectStrategy() );

        super.onAuthenticationFailure( request, response, exception );

    }

}
 
開發者ID:PavlidisLab,項目名稱:modinvreg,代碼行數:47,代碼來源:AjaxAuthenticationFailureHandler.java

示例14: UserAuthorizationSuccessfulAuthenticationHandler

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
public UserAuthorizationSuccessfulAuthenticationHandler() {
  super();
  setRedirectStrategy(new org.springframework.security.web.DefaultRedirectStrategy());
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:5,代碼來源:UserAuthorizationSuccessfulAuthenticationHandler.java

示例15: redirectStrategy

import org.springframework.security.web.DefaultRedirectStrategy; //導入依賴的package包/類
@Bean
public RedirectStrategy redirectStrategy()
{
	return new DefaultRedirectStrategy();
}
 
開發者ID:molgenis,項目名稱:molgenis,代碼行數:6,代碼來源:MolgenisWebAppSecurityConfig.java


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