80 lines
1.8 KiB
Java
80 lines
1.8 KiB
Java
package com.tiesheng.login.service;
|
||
|
||
import cn.hutool.core.util.StrUtil;
|
||
import com.tiesheng.login.pojos.RequestUserInfo;
|
||
import com.tiesheng.login.pojos.dao.CorePlatformUnique;
|
||
import com.tiesheng.util.ServletKit;
|
||
import com.tiesheng.util.config.TsTokenConfig;
|
||
import com.tiesheng.util.pojos.TokenBean;
|
||
import com.tiesheng.util.service.TsCacheService;
|
||
import org.springframework.context.annotation.Configuration;
|
||
|
||
import javax.servlet.http.HttpServletResponse;
|
||
|
||
/**
|
||
* @author hao
|
||
*/
|
||
@Configuration
|
||
public interface TsLoginConfigurer {
|
||
|
||
/**
|
||
* 执行登录
|
||
*
|
||
* @return
|
||
*/
|
||
TokenBean login(CorePlatformUnique platformUnique);
|
||
|
||
|
||
/**
|
||
* 授权登录回调
|
||
*
|
||
* @param bean
|
||
*/
|
||
void redirect(TokenBean bean, String to, String extra, HttpServletResponse response);
|
||
|
||
|
||
/**
|
||
* 登录失败的时候
|
||
*/
|
||
default void onLoginError(String to, HttpServletResponse response) {
|
||
ServletKit.write(response, "404", "text");
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取当前用户的信息
|
||
*
|
||
* @param tokenBean
|
||
* @return
|
||
*/
|
||
default RequestUserInfo getCachedUserInfo(TokenBean tokenBean, boolean force) {
|
||
String key = StrUtil.format(TsTokenConfig.CACHE_REQUEST_LOGIN_KEY, tokenBean.getId());
|
||
RequestUserInfo obj = TsCacheService.of().getObj(key, RequestUserInfo.class, -1);
|
||
if (obj == null || force) {
|
||
obj = getCurrentUserName(tokenBean);
|
||
}
|
||
if (obj != null) {
|
||
TsCacheService.of().putObj(key, obj, 30 * 60);
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
/**
|
||
* 获取当前用户的姓名
|
||
*
|
||
* @return
|
||
*/
|
||
RequestUserInfo getCurrentUserName(TokenBean userId);
|
||
|
||
|
||
/**
|
||
* 获取登录失败的次数,默认5次
|
||
*
|
||
* @return
|
||
*/
|
||
default int getLoginErrorTimes() {
|
||
return 0;
|
||
}
|
||
|
||
}
|