【8.0.2】【auth】简化登录逻辑

pull/57/head
fengshuonan 2023-11-06 18:55:22 +08:00
parent 8e6c0a19cb
commit af454893ad
4 changed files with 1 additions and 151 deletions

View File

@ -1,47 +0,0 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.auth.api;
import cn.stylefeng.roses.kernel.auth.api.pojo.sso.SsoLoginCodeRequest;
/**
* api
*
* @author fengshuonan
* @since 2022/5/16 16:53
*/
public interface SsoServerApi {
/**
* sso
*
* @param ssoLoginCodeRequest
* @return ssoLoginCode
* @author fengshuonan
* @since 2021/1/27 17:26
*/
String createSsoLoginCode(SsoLoginCodeRequest ssoLoginCodeRequest);
}

View File

@ -1,25 +0,0 @@
package cn.stylefeng.roses.kernel.auth.api.pojo.sso;
import cn.stylefeng.roses.kernel.auth.api.enums.SsoClientTypeEnum;
import lombok.Data;
/**
* SSO
*
* @author fengshuonan
* @since 2021/5/25 22:28
*/
@Data
public class SsoProperties {
/**
* ssoserverclient
*/
private String ssoClientType = SsoClientTypeEnum.client.name();
/**
* true-false-
*/
private Boolean openFlag;
}

View File

@ -6,12 +6,10 @@ import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.stylefeng.roses.kernel.auth.api.SessionManagerApi;
import cn.stylefeng.roses.kernel.auth.api.SsoServerApi;
import cn.stylefeng.roses.kernel.auth.api.TempSecretApi;
import cn.stylefeng.roses.kernel.auth.api.TenantCodeGetApi;
import cn.stylefeng.roses.kernel.auth.api.constants.AuthConstants;
import cn.stylefeng.roses.kernel.auth.api.context.AuthJwtContext;
import cn.stylefeng.roses.kernel.auth.api.enums.SsoClientTypeEnum;
import cn.stylefeng.roses.kernel.auth.api.exception.AuthException;
import cn.stylefeng.roses.kernel.auth.api.exception.enums.AuthExceptionEnum;
import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander;
@ -22,8 +20,6 @@ import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginRequest;
import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginResponse;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
import cn.stylefeng.roses.kernel.auth.api.pojo.payload.DefaultJwtPayload;
import cn.stylefeng.roses.kernel.auth.api.pojo.sso.SsoLoginCodeRequest;
import cn.stylefeng.roses.kernel.auth.api.pojo.sso.SsoProperties;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.demo.expander.DemoConfigExpander;
import cn.stylefeng.roses.kernel.log.api.LoginLogServiceApi;
@ -69,9 +65,6 @@ public class LoginService {
@Resource
private DragCaptchaApi dragCaptchaApi;
@Resource
private SsoProperties ssoProperties;
@Resource
private LoginLogServiceApi loginLogServiceApi;
@ -112,24 +105,7 @@ public class LoginService {
// 3. 解密密码的密文需要sys_config相关配置打开
decryptRequestPassword(loginRequest);
// 4. 如果开启了单点登录并且CaToken没有值走单点登录获取loginCode
if (ssoProperties.getOpenFlag() && StrUtil.isEmpty(caToken)) {
if (SsoClientTypeEnum.client.name().equals(ssoProperties.getSsoClientType())) {
// 调用单点的接口获取loginCode远程接口校验用户级密码正确性。
String remoteLoginCode = getRemoteLoginCode(loginRequest);
return new LoginResponse(remoteLoginCode);
} else {
// 如果当前系统是单点服务端
SsoServerApi ssoServerApi = SpringUtil.getBean(SsoServerApi.class);
SsoLoginCodeRequest ssoLoginCodeRequest = new SsoLoginCodeRequest();
ssoLoginCodeRequest.setAccount(loginRequest.getAccount());
ssoLoginCodeRequest.setPassword(loginRequest.getPassword());
String remoteLoginCode = ssoServerApi.createSsoLoginCode(ssoLoginCodeRequest);
return new LoginResponse(remoteLoginCode);
}
}
// 4.1 通过租户编码获取租户id如果租户参数没传则默认填充根租户的id
// 4. 通过租户编码获取租户id如果租户参数没传则默认填充根租户的id
String tenantCode = loginRequest.getTenantCode();
Long tenantId = tenantCodeGetApi.getTenantIdByCode(tenantCode);

View File

@ -1,54 +0,0 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.auth.starter;
import cn.stylefeng.roses.kernel.auth.api.pojo.sso.SsoProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
*
* @author fengshuonan
* @since 2021/5/25 22:29
*/
@Configuration
public class SsoAutoConfiguration {
/**
*
*
* @author fengshuonan
* @since 2021/5/25 22:29
*/
@Bean
@ConfigurationProperties(prefix = "sso")
public SsoProperties ssoProperties() {
return new SsoProperties();
}
}