【7.2.2】【auth】完善单点过程

pull/29/head
fengshuonan 2022-05-16 19:06:47 +08:00
parent 86e62908c4
commit 4ab39a7f69
7 changed files with 158 additions and 24 deletions

View File

@ -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.
*
* 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
* @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);
}

View File

@ -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.
*
* 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.enums;
/**
*
*
* @author fengshuonan
* @date 2022/5/16 16:48
*/
public enum SsoClientTypeEnum {
client, server
}

View File

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

View File

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

View File

@ -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 {
/**
* ssoserverclient
*/
private String ssoClientType = SsoClientTypeEnum.client.name();
/**
* true-false-
*/
private Boolean openFlag;
}

View File

@ -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. 获取用户密码的加密值和用户的状态

View File

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