| 
					
				 | 
			
			
				@@ -1,35 +1,47 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.ym.mec.auth.web.controller; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.auth.api.entity.SysUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.auth.service.SysUserService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.common.controller.BaseController; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.common.entity.HttpResponseResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.common.entity.ImResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.common.entity.ImUserModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.common.security.AuthUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.common.security.SecurityUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.im.ImFeignService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.Api; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.ApiImplicitParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.ApiImplicitParams; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.ApiOperation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Base64; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Collection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.http.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.http.HttpEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.http.HttpHeaders; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.http.HttpMethod; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.http.MediaType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.http.ResponseEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.security.oauth2.common.OAuth2AccessToken; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.security.oauth2.provider.token.DefaultTokenServices; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.security.oauth2.provider.token.TokenStore; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.util.LinkedMultiValueMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.util.MultiValueMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.bind.annotation.GetMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.web.bind.annotation.PathVariable; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.bind.annotation.PostMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.web.bind.annotation.RequestHeader; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.bind.annotation.RestController; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.client.RestTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Base64; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.auth.api.entity.SysUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.auth.service.SysUserService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.common.controller.BaseController; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.common.entity.HttpResponseResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.common.entity.ImResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.common.entity.ImUserModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.common.security.AuthUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.common.security.SecurityConstants; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.common.security.SecurityUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.im.ImFeignService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @RestController 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Api(tags = "认证服务") 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -37,6 +49,9 @@ public class TokenController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	private DefaultTokenServices tokenService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private TokenStore tokenStore; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	private RestTemplate restTemplate; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -122,7 +137,9 @@ public class TokenController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@PostMapping(value = "exit",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@ApiOperation(value = "退出登录") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	public HttpResponseResult logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION) String authHeader) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public HttpResponseResult<String> logout(HttpServletRequest request) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		String authHeader = request.getHeader(HttpHeaders.AUTHORIZATION); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if (StringUtils.isBlank(authHeader)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return failed("退出失败,token 为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -134,4 +151,29 @@ public class TokenController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return succeed("退出成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@PostMapping(value = "exit/{clientId}/{phone}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@ApiOperation(value = "指定用户退出登录") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public HttpResponseResult<String> exitByPhone(@PathVariable("clientId") String clientId, @PathVariable("phone") String phone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Collection<OAuth2AccessToken> list = tokenStore.findTokensByClientIdAndUserName(clientId, SecurityConstants.PHONE_PRINCIPAL_PREFIX + phone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (list == null || list.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			list = tokenStore.findTokensByClientIdAndUserName(clientId, SecurityConstants.USERNAME_PRINCIPAL_PREFIX + phone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			list.addAll(tokenStore.findTokensByClientIdAndUserName(clientId, SecurityConstants.USERNAME_PRINCIPAL_PREFIX + phone)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (list != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			for (OAuth2AccessToken accessToken : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (accessToken != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if (accessToken.getRefreshToken() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						tokenStore.removeRefreshToken(accessToken.getRefreshToken()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					tokenStore.removeAccessToken(accessToken); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return succeed("退出成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |