Files
tiesheng-springboot/springboot-login/src/main/java/com/tiesheng/login/service/TsLoginConfigurer.java
2024-12-08 11:53:11 +08:00

80 lines
1.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}