Commit bcb3b51f by chenzx

修改接口请求放回的数据

parent a0282805
......@@ -61,6 +61,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http.csrf().disable();
}
public static String baseUrl="http://cas.zua.edu.cn/oauth2.0/authorize?response_type=code&client_id=tVnAsJna9Y&redirect_uri=http://10.60.60.127:8091/api/auth/sso";
// 获取 code : http://cas.zua.edu.cn/oauth2.0/authorize?response_type=cod e&client_id=clientId&redirect_uri=ssoUrl 认证成功之后会跳转到 redirect_uri ,并且连接后面会带着code参数。
@Bean
public AbstractAuthenticationProcessingFilter authenticationFilter() throws Exception {
......@@ -71,7 +72,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
//回调到这里获取用户的code
String code = httpServletRequest.getParameter("code");
if(null == code){
httpServletResponse.sendRedirect("/refuse?code=401");
httpServletResponse.sendRedirect(baseUrl);
return null;
}
//获取 accessToken
......@@ -83,30 +84,25 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
map.put("redirect_uri",ssoUrl);
map.put("code",code);
System.out.println("param:--------->"+map.toString());
JSONObject jsonObject = null;
String accessToken="";
try{
jsonObject = JSONObject.fromObject(HttpClientUtil.doPost("http://cas.zua.edu.cn/oauth2.0/accessToken",map));
accessToken =HttpClientUtil.doPost("http://cas.zua.edu.cn/oauth2.0/accessToken",map);
}catch (Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}
String accessToken="";
if(null != jsonObject){
if(null != accessToken){
//返回内容 access_token=AT-1-vDqPefqwHJl39iUtsAh19oI1vwAIQn6k&expires_in=28800
System.out.println("request return:--------->"+jsonObject.toString());
accessToken=jsonObject.get("accessToken").toString();
System.out.println("request return:--------->"+accessToken);
}else{
System.out.println("jsonObject is null");
System.out.println("accessToken is null");
}
if (!StringUtils.isEmpty(accessToken)){
httpServletResponse.sendRedirect("/refuse?code=402");
if (StringUtils.isEmpty(accessToken)){
httpServletResponse.sendRedirect(baseUrl);
return null;
}
//根据token获取用户信息
Map map2=new HashMap();
map2.put("access_token=","authorization_code");
JSONObject object = JSONObject.fromObject(HttpClientUtil.doGet("http://cas.zua.edu.cn/oauth2.0/profile",map));
JSONObject object = JSONObject.fromObject(HttpClientUtil.doGet("http://cas.zua.edu.cn/oauth2.0/profile?"+accessToken));
//返回内容 { "attributes" : { "changeCodeStatus" : "1", "credentialType" : "UsernamePasswordCredential", "id" : "1676604", "nickName" : "张凤元", "organizationId" : "104001000", "realName" : "张凤元", <真实姓名> "sex" : "0", <性别> "userNumber" : "003213" <学号/工号> },"id" : "003213" }
String loginName=object.get("id").toString();
if(!checkToken(loginName)){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment