package com.uas.platform.home.web.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.uas.account.entity.UserView;
import com.uas.platform.home.core.support.SystemSession;
import com.uas.platform.home.core.util.FastjsonUtils;
import com.uas.sso.SSOHelper;
import com.uas.sso.SSOToken;
import com.uas.sso.web.spring.AbstractSSOInterceptor;

public class SSOInterceptor extends AbstractSSOInterceptor {

	@Override
	protected boolean onAuthenticateFailed(HttpServletRequest request, HttpServletResponse response) {
		// 没登录也继续
		return true;
	}

	@Override
	protected void onAuthenticateSuccess(HttpServletRequest request, HttpServletResponse response) {
		SSOToken token = SSOHelper.attrToken(request);
		if (token.getData() != null)
			SystemSession.setUser(FastjsonUtils.fromJson(token.getData(), UserView.class));
		else
			SystemSession.clear();
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		super.afterCompletion(request, response, handler, ex);
		SystemSession.clear();
	}

}
