Java Code Examples for org.springframework.security.web.savedrequest.RequestCache

The following examples show how to use org.springframework.security.web.savedrequest.RequestCache. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 登陆成功,返回Token 装配此bean不支持授权码模式
 * 
 * @return
 */
@Bean
public AuthenticationSuccessHandler loginSuccessHandler() {
	return new SavedRequestAwareAuthenticationSuccessHandler() {

		private RequestCache requestCache = new HttpSessionRequestCache();

		@Override
		public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
				Authentication authentication) throws IOException, ServletException {

			super.onAuthenticationSuccess(request, response, authentication);
			return;

		}
	};
}
 
Example 2
Source Project: jeesupport   Source File: WebSecurityConfig.java    License: MIT License 6 votes vote down vote up
/**
 * 登陆成功后的处理
 *
 * @return
 */
@Bean
public AuthenticationSuccessHandler successHandler(){
    return new AuthenticationSuccessHandler(){
        @Override
        public void onAuthenticationSuccess( HttpServletRequest _request, HttpServletResponse _response, Authentication _auth ) throws IOException, ServletException{
            log.debug( "--登陆成功" );

            _request.getSession().setAttribute( ISupportEL.Session_User_EL, _auth.getPrincipal() );
            sessionRegistry().registerNewSession( _request.getSession().getId(), _auth.getPrincipal() );

            RequestCache requestCache = new HttpSessionRequestCache();

            SavedRequest savedRequest = requestCache.getRequest( _request, _response );
            String       url          = null;
            if( savedRequest != null ) url = savedRequest.getRedirectUrl();
            log.debug( "--登陆后转向:" + url );

            if( url == null ) redirectStrategy().sendRedirect( _request, _response, "/" );
            else _response.sendRedirect( url );
        }
    };
}
 
Example 3
Source Project: promregator   Source File: SecurityConfig.java    License: Apache License 2.0 4 votes vote down vote up
private RequestCache newHttpSessionRequestCache() {
	HttpSessionRequestCache httpSessionRequestCache = new HttpSessionRequestCache();
	httpSessionRequestCache.setCreateSessionAllowed(false);
	return httpSessionRequestCache;
}
 
Example 4
public RequestCache getRequestCache() {
	return requestCache;
}
 
Example 5
public void setRequestCache(RequestCache requestCache) {
	this.requestCache = requestCache;
}
 
Example 6
public void setRequestCache(RequestCache requestCache) {
    this.requestCache = requestCache;
}
 
Example 7
public void setRequestCache(RequestCache requestCache) {
    this.requestCache = requestCache;
}
 
Example 8
Source Project: MaxKey   Source File: RealAuthenticationFailureHandler.java    License: Apache License 2.0 4 votes vote down vote up
public RealAuthenticationFailureHandler(RequestCache requestCache) {
	super();
	this.requestCache = requestCache;
}
 
Example 9
Source Project: MaxKey   Source File: PermissionAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, 
        HttpServletResponse response, Object handler)
        throws Exception {
    _logger.trace("PermissionAdapter preHandle");
    //save  first protected url 
    SavedRequest  firstSavedRequest = (SavedRequest)WebContext.getAttribute(WebConstants.FIRST_SAVED_REQUEST_PARAMETER);
    // 判断用户是否登录, 判断用户和角色,判断用户是否登录用户
    if  (WebContext.getAuthentication() == null 
            || WebContext.getAuthentication().getAuthorities() == null) {
        //保存未认证的请求信息
        if(firstSavedRequest==null){
            RequestCache requestCache = new HttpSessionRequestCache();
            requestCache.saveRequest(request, response);
            SavedRequest  savedRequest =requestCache.getRequest(request, response);
            if(savedRequest!=null){
                _logger.debug("first request parameter  savedRequest "+savedRequest.getRedirectUrl());
                WebContext.setAttribute(WebConstants.FIRST_SAVED_REQUEST_PARAMETER, savedRequest);
                savedRequestSuccessHandler.setRequestCache(requestCache);
            }
        }
        
        _logger.trace("No Authentication ... forward to /login");
        RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
        dispatcher.forward(request, response);
        return false;
    }
    
    //认证完成,跳转到未认证请求
    if(firstSavedRequest!=null) {
        savedRequestSuccessHandler.onAuthenticationSuccess(request, response, WebContext.getAuthentication());
        WebContext.removeAttribute(WebConstants.FIRST_SAVED_REQUEST_PARAMETER);
    }

    boolean hasAccess = true;

    /*
     * boolean preHandler = super.preHandle(request, response, handler);
     * 
     * if(preHandler) { preHandler = false;
     * 
     * 
     * if(!preHandler){//无权限转向
     * log.debug("You do not have permission to access "+accessUrl);
     * RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
     * dispatcher.forward(request, response); return false; } }
     */
    return hasAccess;
}
 
Example 10
public void setRequestCache(RequestCache requestCache) {
    this.requestCache = requestCache;
}
 
Example 11
public void setRequestCache(RequestCache requestCache) {
	this.requestCache = requestCache;
}
 
Example 12
Source Project: lolibox   Source File: SimpleSignInAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Inject
public SimpleSignInAdapter(RequestCache requestCache) {
    this.requestCache = requestCache;
}
 
Example 13
Source Project: cxf-fediz   Source File: STSUPAuthenticationProvider.java    License: Apache License 2.0 4 votes vote down vote up
public void setRequestCache(RequestCache requestCache) {
    this.requestCache = requestCache;
}
 
Example 14
public void setRequestCache(final RequestCache requestCache) {
    this.requestCache = requestCache;
}
 
Example 15
public void setRequestCache(final RequestCache requestCache) {
    this.requestCache = requestCache;
}
 
Example 16
public void setRequestCache(final RequestCache requestCache) {
    this.requestCache = requestCache;
}
 
Example 17
public void setRequestCache(final RequestCache requestCache) {
    this.requestCache = requestCache;
}
 
Example 18
public void setRequestCache(final RequestCache requestCache) {
    this.requestCache = requestCache;
}