//package com.lutao.cloud.auth.sso.config;
//
//import cn.hutool.core.net.URLDecoder;
//import cn.hutool.core.util.CharsetUtil;
//import cn.hutool.json.JSONObject;
//import cn.hutool.json.XML;
//import com.alibaba.cloud.commons.io.IOUtils;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.lutao.cloud.auth.service.CloudTokenDealServiceImpl;
//import com.lutao.cloud.common.core.util.StringUtil;
//import lombok.Setter;
//import lombok.SneakyThrows;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.MediaType;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
//import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.PrintWriter;
//import java.nio.charset.StandardCharsets;
//
///**
// * 登出filter
// */
//@Slf4j
//public class SSOLogoutFilter extends AbstractAuthenticationProcessingFilter {
//	@Setter
//	private ObjectMapper objectMapper;
//
//	@Setter
//	private CloudTokenDealServiceImpl dealService;
//
//	public SSOLogoutFilter() {
//		super(new AntPathRequestMatcher("/sso/logout"));
//	}
//
//	@Override
//	@SneakyThrows
//	public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) {
//		String ticket = request.getParameter("ticket");
//		log.info("sso/logout:{}", ticket);
//
//		String body = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
//		if (StringUtil.isNotBlank(body)) {
//			String urlDecodeRet = URLDecoder.decode(body, StandardCharsets.UTF_8);
//			log.info("urlDecodeRet:{}", urlDecodeRet);
//			JSONObject jsonObject = XML.toJSONObject(urlDecodeRet.replaceAll(": ",":"));
//			ticket = jsonObject.getJSONObject("samlp:LogoutRequest").getStr("samlp:SessionIndex");
//		}
//
//		String authHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
//
//		response.setCharacterEncoding(CharsetUtil.UTF_8);
//		response.setContentType(MediaType.APPLICATION_JSON_VALUE);
//		PrintWriter printWriter = response.getWriter();
//		printWriter.append(objectMapper.writeValueAsString(dealService.removeSSOToken(ticket, authHeader)));
//
//		return null;
//	}
//}