7 changed files with 142 additions and 1 deletions
Binary file not shown.
Binary file not shown.
@ -1,3 +1,6 @@ |
|||||||
# open-JSD-8663 |
# open-JSD-8663 |
||||||
|
|
||||||
JSD-8663 开源任务材料 |
JSD-8663 平台登出web接口 开源任务材料\ |
||||||
|
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||||
|
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||||
|
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,20 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||||
|
<id>com.fr.plugin.xxxx.logout</id> |
||||||
|
<name><![CDATA[登出接口]]></name> |
||||||
|
<active>yes</active> |
||||||
|
<version>1.1</version> |
||||||
|
<env-version>10.0</env-version> |
||||||
|
<jartime>2018-07-31</jartime> |
||||||
|
<vendor>holger</vendor> |
||||||
|
<description><![CDATA[登出接口]]></description> |
||||||
|
<change-notes><![CDATA[ |
||||||
|
[2021-09-09]【1.0】初始化代码。<br/> |
||||||
|
[2021-09-09]【1.1】允许跨域。<br/> |
||||||
|
]]></change-notes> |
||||||
|
<!--注入外链--> |
||||||
|
<extra-decision> |
||||||
|
<HttpHandlerProvider class="com.fr.plugin.xxxx.logout.LogoutRequestHandlerBridge"/> |
||||||
|
<URLAliasProvider class="com.fr.plugin.xxxx.logout.LogoutRequestURLAliasBridge" /> |
||||||
|
</extra-decision> |
||||||
|
<function-recorder class="com.fr.plugin.xxxx.logout.LogoutRequestHandlerBridge"/> |
||||||
|
</plugin> |
@ -0,0 +1,20 @@ |
|||||||
|
package com.fr.plugin.xxxx.logout; |
||||||
|
|
||||||
|
import com.fr.decision.fun.HttpHandler; |
||||||
|
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||||
|
import com.fr.plugin.xxxx.logout.handler.LogoutHandler; |
||||||
|
import com.fr.plugin.transform.FunctionRecorder; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author fr.open |
||||||
|
* @Date 2021/9/9 |
||||||
|
* @Description |
||||||
|
**/ |
||||||
|
@FunctionRecorder |
||||||
|
public class LogoutRequestHandlerBridge extends AbstractHttpHandlerProvider { |
||||||
|
@Override |
||||||
|
public HttpHandler[] registerHandlers() { |
||||||
|
return new HttpHandler[]{new LogoutHandler()}; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package com.fr.plugin.xxxx.logout; |
||||||
|
|
||||||
|
import com.fr.decision.fun.impl.AbstractURLAliasProvider; |
||||||
|
import com.fr.decision.webservice.url.alias.URLAlias; |
||||||
|
import com.fr.decision.webservice.url.alias.URLAliasFactory; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author fr.open |
||||||
|
* @Date 2021/9/9 |
||||||
|
* @Description |
||||||
|
**/ |
||||||
|
public class LogoutRequestURLAliasBridge extends AbstractURLAliasProvider { |
||||||
|
|
||||||
|
@Override |
||||||
|
public URLAlias[] registerAlias() { |
||||||
|
return new URLAlias[]{URLAliasFactory.createPluginAlias("/quit", "/quit", true)}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,80 @@ |
|||||||
|
package com.fr.plugin.xxxx.logout.handler; |
||||||
|
|
||||||
|
import com.fr.decision.authority.data.User; |
||||||
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||||
|
import com.fr.decision.webservice.exception.login.LoginInfoNotAvailableException; |
||||||
|
import com.fr.decision.webservice.v10.login.kickout.KickOutConfig; |
||||||
|
import com.fr.decision.webservice.v10.login.kickout.KickOutUserEvent; |
||||||
|
import com.fr.decision.webservice.v10.system.SystemService; |
||||||
|
import com.fr.decision.webservice.v10.user.UserService; |
||||||
|
import com.fr.event.EventDispatcher; |
||||||
|
import com.fr.intelligence.IntelligenceRuntimeException; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.AssistUtils; |
||||||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||||
|
import com.fr.web.utils.WebUtils; |
||||||
|
import com.fr.decision.webservice.Response; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author fr.open |
||||||
|
* @Date 2021/9/9 |
||||||
|
* @Description |
||||||
|
**/ |
||||||
|
public class LogoutHandler extends BaseHttpHandler { |
||||||
|
@Override |
||||||
|
public RequestMethod getMethod() { |
||||||
|
return RequestMethod.GET; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getPath() { |
||||||
|
return "/quit"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isPublic() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||||
|
res.setHeader("Access-Control-Allow-Origin", req.getHeader("Origin")); |
||||||
|
res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); |
||||||
|
res.setHeader("Access-Control-Max-Age", "0"); |
||||||
|
res.setHeader("Access-Control-Allow-Headers", "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token,Access-Control-Allow-Headers"); |
||||||
|
res.setHeader("Access-Control-Allow-Credentials", "true");//这个是设置运行携带cookie
|
||||||
|
res.setHeader("XDomainRequestAllowed","1"); |
||||||
|
String username = WebUtils.getHTTPRequestParameter(req, "username"); |
||||||
|
Response response; |
||||||
|
User user = UserService.getInstance().getUserByUserName(username); |
||||||
|
if(user == null){ |
||||||
|
response = Response.error("user-not-exit","user-not-exit"); |
||||||
|
}else { |
||||||
|
kickOutAllOtherCurrentUsers(username,new LoginInfoNotAvailableException()); |
||||||
|
response = Response.success(); |
||||||
|
} |
||||||
|
WebUtils.printAsJSON(res, JSONObject.mapFrom(response)); |
||||||
|
} |
||||||
|
|
||||||
|
private void kickOutAllOtherCurrentUsers(String currentUserName, IntelligenceRuntimeException runtimeException) { |
||||||
|
try { |
||||||
|
Set<String> userNames = SystemService.getInstance().getSystemOnlineUserNames(); |
||||||
|
Iterator it = userNames.iterator(); |
||||||
|
|
||||||
|
while (it.hasNext()) { |
||||||
|
String userName = (String) it.next(); |
||||||
|
if (AssistUtils.equals(userName, currentUserName)) { |
||||||
|
EventDispatcher.fire(KickOutUserEvent.KickOutUser, new KickOutConfig(runtimeException, userName)); |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (Exception var6) { |
||||||
|
FineLoggerFactory.getLogger().error(var6.getMessage(), var6); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue