提交 408a2942 编写于 作者: 智布道's avatar 智布道 👁

💩 Writing bad code that needs to be improved.

上级 560b754c
package com.fujieid.jap.core;
import com.alibaba.fastjson.JSONObject;
import com.fujieid.jap.core.exception.JapUserException;
/**
......@@ -13,27 +14,34 @@ import com.fujieid.jap.core.exception.JapUserException;
public interface JapUserService {
/**
* Get user info by userid.
* Get user info by username.
* <p>
* It is suitable for the {@code jap-simple} module
*
* @param userId User id of the business system
* @param username username of the business system
* @return JapUser
*/
default JapUser getById(String userId) {
throw new JapUserException("JapUserService#getById(String) must be overridden by subclass");
default JapUser getByName(String username) {
throw new JapUserException("JapUserService#getByName(String) must be overridden by subclass");
}
/**
* Get user info by username.
* Verify that the password entered by the user matches
* <p>
* It is suitable for the {@code jap-simple} module
*
* @param username username of the business system
* @return JapUser
* @param password The password in the HTML-based login form
* @param user User information that is queried by the user name in the HTML form
* @return {@code boolean} When true is returned, the password matches, otherwise the password is wrong
*/
default JapUser getByName(String username) {
throw new JapUserException("JapUserService#getByName(String) must be overridden by subclass");
default boolean validPassword(String password, JapUser user) {
throw new JapUserException("JapUserService#validPassword(String, JapUser) must be overridden by subclass");
}
/**
* Get user information in the current system by social platform and social user id
* <p>
* It is suitable for the {@code jap-social} module
*
* @param platform social platform,refer to {@code me.zhyd.oauth.config.AuthSource#getName()}
* @param uid social user id
......@@ -44,24 +52,27 @@ public interface JapUserService {
}
/**
* Verify that the password entered by the user matches
* Save the social login user information to the database and return JapUser
* <p>
* It is suitable for the {@code jap-social} module
*
* @param password The password in the HTML-based login form
* @param user User information that is queried by the user name in the HTML form
* @return {@code boolean} When true is returned, the password matches, otherwise the password is wrong
* @param userInfo User information obtained through justauth third-party login, type {@code me.zhyd.oauth.model.AuthUser}
* @return When saving successfully, return {@code JapUser}, otherwise return {@code null}
*/
default boolean validPassword(String password, JapUser user) {
throw new JapUserException("JapUserService#validPassword(String, JapUser) must be overridden by subclass");
default JapUser createAndGetSocialUser(Object userInfo) {
throw new JapUserException("JapUserService#createSocialUser(AuthUser) must be overridden by subclass");
}
/**
* Save the social login user information to the database and return JapUser
* Save the oauth login user information to the database and return JapUser
* <p>
* It is suitable for the {@code jap-oauth2} module
*
* @param authUser User information obtained through justauth third-party login, type {@code me.zhyd.oauth.model.AuthUser}
* @param userInfo The basic user information returned by the OAuth platform
* @return When saving successfully, return {@code JapUser}, otherwise return {@code null}
*/
default JapUser createAndGetSocialUser(Object authUser) {
throw new JapUserException("JapUserService#createSocialUser(String) must be overridden by subclass");
default JapUser createAndGetOauth2User(JSONObject userInfo) {
throw new JapUserException("JapUserService#createAndGetOauth2User(JSONObject) must be overridden by subclass");
}
}
......@@ -65,6 +65,19 @@ public abstract class AbstractJapStrategy implements JapStrategy {
return false;
}
protected void loginSuccess(JapUser japUser, HttpServletRequest request, HttpServletResponse response) {
if (japConfig.isSession()) {
HttpSession session = request.getSession();
japUser.setPassword(null);
session.setAttribute(JapConst.SESSION_USER_KEY, japUser);
}
try {
response.sendRedirect(japConfig.getSuccessRedirect());
} catch (IOException e) {
throw new JapException("JAP failed to redirect via HttpServletResponse.", e);
}
}
/**
* Verify that the AuthenticateConfig is of the specified class type
*
......
......@@ -2,6 +2,7 @@ package com.fujieid.jap.social;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.fujieid.jap.core.*;
import com.fujieid.jap.core.exception.JapException;
......@@ -124,16 +125,7 @@ public class SocialStrategy extends AbstractJapStrategy {
}
}
if (japConfig.isSession()) {
HttpSession session = request.getSession();
japUser.setPassword(null);
session.setAttribute(JapConst.SESSION_USER_KEY, japUser);
}
try {
response.sendRedirect(japConfig.getSuccessRedirect());
} catch (IOException e) {
throw new JapException("JAP failed to redirect via HttpServletResponse.", e);
}
this.loginSuccess(japUser, request, response);
}
/**
......@@ -155,7 +147,7 @@ public class SocialStrategy extends AbstractJapStrategy {
} else if (source.equals(AuthDefaultSource.HUAWEI.name())) {
code = authCallback.getAuthorization_code();
}
return !StringUtils.isEmpty(code);
return !StrUtil.isEmpty(code);
}
/**
......
......@@ -54,6 +54,7 @@
<guava.version>RELEASE</guava.version>
<javax.servlet.version>4.0.1</javax.servlet.version>
<justauth.version>1.15.9</justauth.version>
<jose4j.version>0.7.1</jose4j.version>
</properties>
<dependencies>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册