Commit 5f58f6e4 by 吴博

1002766 add cookie check

parent 175146f1
...@@ -8,7 +8,7 @@ import java.io.IOException; ...@@ -8,7 +8,7 @@ import java.io.IOException;
* @创建时间:2016年5月27日,下午2:12:12 * @创建时间:2016年5月27日,下午2:12:12
* @版本:1.0 * @版本:1.0
*/ */
public class PermissionException extends IOException{ public class PermissionException extends RuntimeException{
private static final long serialVersionUID = 1336555490029071770L; private static final long serialVersionUID = 1336555490029071770L;
/** /**
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
*/ */
package com.pcloud.common.utils.cookie; package com.pcloud.common.utils.cookie;
import com.pcloud.common.permission.PermissionException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.HashMap; import java.util.HashMap;
...@@ -157,7 +158,8 @@ public class Cookie { ...@@ -157,7 +158,8 @@ public class Cookie {
String[] user = userInfoArry[i].split("="); String[] user = userInfoArry[i].split("=");
String wechatUserId = user[user.length - 1]; String wechatUserId = user[user.length - 1];
userInfos.put("wechatUserId", StringUtil.isEmpty(wechatUserId) || "undefined".equalsIgnoreCase(wechatUserId) userInfos.put("wechatUserId", StringUtil.isEmpty(wechatUserId) || "undefined".equalsIgnoreCase(wechatUserId)
|| "null".equalsIgnoreCase(wechatUserId) ? null : NumberUtil.toLong(wechatUserId)); || "null".equalsIgnoreCase(wechatUserId) || Cookie._WECHAT_USER_ID.equalsIgnoreCase(wechatUserId) ? null :
NumberUtil.toLong(wechatUserId));
} }
if (userInfoArry[i].contains("partyId")) { if (userInfoArry[i].contains("partyId")) {
String[] party = userInfoArry[i].split("="); String[] party = userInfoArry[i].split("=");
...@@ -266,6 +268,9 @@ public class Cookie { ...@@ -266,6 +268,9 @@ public class Cookie {
|| "null".equalsIgnoreCase(userLabel) ? null : userLabel); || "null".equalsIgnoreCase(userLabel) ? null : userLabel);
} }
} }
if (!userInfos.containsKey(Cookie._WECHAT_USER_ID) || null == userInfos.get(Cookie._WECHAT_USER_ID) || StringUtil.isEmpty(userInfos.get(Cookie._WECHAT_USER_ID).toString())){
throw PermissionException.PERMISSION_USER_NOT_LOGIN;
}
return userInfos; return userInfos;
} }
...@@ -278,6 +283,9 @@ public class Cookie { ...@@ -278,6 +283,9 @@ public class Cookie {
*/ */
public static Long getId(String userInfo, String type) throws BizException { public static Long getId(String userInfo, String type) throws BizException {
String value = getString(userInfo, type); String value = getString(userInfo, type);
if (Cookie._WECHAT_USER_ID.equalsIgnoreCase(type) && StringUtil.isEmpty(value)){
throw PermissionException.PERMISSION_USER_NOT_LOGIN;
}
return StringUtil.isEmpty(value) || "undefined".equalsIgnoreCase(value) || "null".equalsIgnoreCase(value) ? null : NumberUtil.toLong(value); return StringUtil.isEmpty(value) || "undefined".equalsIgnoreCase(value) || "null".equalsIgnoreCase(value) ? null : NumberUtil.toLong(value);
} }
...@@ -308,7 +316,7 @@ public class Cookie { ...@@ -308,7 +316,7 @@ public class Cookie {
if (userInfoArry[i].contains(type)) { if (userInfoArry[i].contains(type)) {
String[] ids = userInfoArry[i].split("="); String[] ids = userInfoArry[i].split("=");
String id = ids[ids.length - 1]; String id = ids[ids.length - 1];
return StringUtil.isEmpty(id) || "undefined".equalsIgnoreCase(id) || "null".equalsIgnoreCase(id) ? null : id; return StringUtil.isEmpty(id) || "undefined".equalsIgnoreCase(id) || "null".equalsIgnoreCase(id) || type.equalsIgnoreCase(id)? null : id;
} }
} }
return null; return null;
......
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