mirror of https://gitee.com/stylefeng/roses
【7.2.2】【auth】完善单点过程
parent
86e62908c4
commit
4ab39a7f69
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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
|
||||
* @date 2022/5/16 16:53
|
||||
*/
|
||||
public interface SsoServerApi {
|
||||
|
||||
/**
|
||||
* 校验账号密码是否正确,创建sso登录编码
|
||||
*
|
||||
* @param ssoLoginCodeRequest 账号和密码
|
||||
* @return ssoLoginCode,用在单点登录
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/27 17:26
|
||||
*/
|
||||
String createSsoLoginCode(SsoLoginCodeRequest ssoLoginCodeRequest);
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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.enums;
|
||||
|
||||
/**
|
||||
* 单点登录客户端
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/5/16 16:48
|
||||
*/
|
||||
public enum SsoClientTypeEnum {
|
||||
|
||||
client, server
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.auth.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* SSO的配置
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/5/25 22:28
|
||||
*/
|
||||
@Data
|
||||
public class SsoProperties {
|
||||
|
||||
/**
|
||||
* 是否开启,true-开启单点,false-关闭单点
|
||||
*/
|
||||
private Boolean openFlag;
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package cn.stylefeng.roses.kernel.auth.api.pojo.sso;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* 单点登录,获取ssoLoginCode的请求参数封装
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/27 16:55
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SsoLoginCodeRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@NotBlank(message = "账号不能为空")
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 用户密码
|
||||
*/
|
||||
@NotBlank(message = "用户密码不能为空")
|
||||
private String password;
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package cn.stylefeng.roses.kernel.auth.api.pojo.sso;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.enums.SsoClientTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* SSO的配置
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/5/25 22:28
|
||||
*/
|
||||
@Data
|
||||
public class SsoProperties {
|
||||
|
||||
/**
|
||||
* sso服务端还是客户端(传server或者client)
|
||||
*/
|
||||
private String ssoClientType = SsoClientTypeEnum.client.name();
|
||||
|
||||
/**
|
||||
* 是否开启,true-开启单点,false-关闭单点
|
||||
*/
|
||||
private Boolean openFlag;
|
||||
|
||||
}
|
|
@ -36,20 +36,23 @@ import cn.hutool.http.HttpRequest;
|
|||
import cn.hutool.http.HttpResponse;
|
||||
import cn.stylefeng.roses.kernel.auth.api.AuthServiceApi;
|
||||
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.constants.AuthConstants;
|
||||
import cn.stylefeng.roses.kernel.auth.api.constants.LoginCacheConstants;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
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;
|
||||
import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.password.PasswordTransferEncryptApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.SsoProperties;
|
||||
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.auth.LoginWithTokenRequest;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
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.jwt.JwtTokenOperator;
|
||||
|
@ -320,9 +323,19 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
|
||||
// 4. 如果开启了单点登录,并且CaToken没有值,走单点登录,获取loginCode
|
||||
if (ssoProperties.getOpenFlag() && StrUtil.isEmpty(caToken)) {
|
||||
// 调用单点的接口获取loginCode,远程接口校验用户级密码正确性。
|
||||
String remoteLoginCode = getRemoteLoginCode(loginRequest);
|
||||
return new LoginResponse(remoteLoginCode);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 获取用户密码的加密值和用户的状态
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.auth.starter;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.SsoProperties;
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue