mirror of https://gitee.com/stylefeng/roses
【8.0.2】【auth】简化登录逻辑
parent
8e6c0a19cb
commit
af454893ad
|
@ -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.
|
||||
*
|
||||
* Guns采用APACHE 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);
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
* sso服务端还是客户端(传server或者client)
|
||||
*/
|
||||
private String ssoClientType = SsoClientTypeEnum.client.name();
|
||||
|
||||
/**
|
||||
* 是否开启,true-开启单点,false-关闭单点
|
||||
*/
|
||||
private Boolean openFlag;
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* Guns采用APACHE 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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue