authorizeVerify.jsp
2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<%@ page import="com.api.integration.web.OAuth2ServerAction" %>
<%@ page import="com.api.login.util.LoginUtil" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.UUID" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
/**
* OAuth2服务相关
* 注意: 仅供集成组测试使用
*/
String requestMethod = Util.null2String(request.getMethod());
if(requestMethod.equalsIgnoreCase("GET")){
%>
<script language="javascript">
alert("非法登录方式");
window.close();
</script>
<%
return;
}
String weaverssoservice=Util.null2String(request.getParameter("weaverssoservice"));
String appid=Util.null2String(request.getParameter("appid"));
String redirect_uri = Util.null2String(request.getParameter("redirect_uri"));
String loginfile = Util.null2String(request.getParameter("loginfile")) ;
String logintype = Util.null2String(request.getParameter("logintype")) ;
String loginid = Util.null2String(request.getParameter("loginid")) ;
String forwardpage = Util.null2String(request.getParameter("forwardpage")) ;
String userpassword = Util.null2String(request.getParameter("userpassword"));
String message = Util.null2String(request.getParameter("message"));
String isIE = Util.null2String(request.getParameter("isie"));
LoginUtil loginUtil = new LoginUtil();
String[] strings = loginUtil.checkLogin(application, request, response);
if (strings != null && strings.length >= 5) {
if ("true".equalsIgnoreCase(strings[0])) {
//认证成功
// String s = JSON.toJSONString(strings);
// out.print(s);
User user= (User) request.getSession(true).getAttribute("weaver_user@bean");
//1,生成临时码
String oauth2_token = new OAuth2ServerAction().getInnerAccessToken(user.getUID()+"");
ServletContext ctx = session.getServletContext();
String oauth2_code = UUID.randomUUID().toString();
ctx.setAttribute(request.getSession(true).getId() + "_oauth2_code", oauth2_code);
ctx.setAttribute(oauth2_code, oauth2_token);
//2,cookie里存access_token
Cookie cookie = new Cookie("oauth2_token", oauth2_token);
cookie.setPath("/");
cookie.setMaxAge(-1);
response.addCookie(cookie);
response.sendRedirect(redirect_uri+(redirect_uri.indexOf("?")>0?"&":"?")+"code="+oauth2_code);
return;
} else {
response.sendRedirect("/login/authorize.jsp?err_msg="+URLEncoder.encode(strings[2],"UTF-8")+"&redirect_uri=" + URLEncoder.encode(redirect_uri, "UTF-8"));
return;
}
}
%>