This controller finishes the login process for an indirect client.
+ *
+ * @author Jerome Leleu
+ * @since 1.0.0
+ */
+@Controller
+public class CallbackController {
+
+ private CallbackLogic
-
-
org.mitre.dsmiley.httpproxysmiley-http-proxy-servlet
diff --git a/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java b/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
index 1b018c4268..aad88ac830 100644
--- a/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
+++ b/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
@@ -22,14 +22,12 @@
import org.dinky.data.constant.BaseConstant;
import org.dinky.interceptor.LocaleChangeInterceptor;
import org.dinky.interceptor.TenantInterceptor;
+import org.dinky.sso.web.SecurityInterceptor;
import java.util.Locale;
-import org.dinky.sso.web.SecurityInterceptor;
import org.pac4j.core.config.Config;
-
import org.pac4j.core.http.adapter.JEEHttpActionAdapter;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@@ -39,7 +37,7 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
- import cn.dev33.satoken.exception.StopMatchException;
+import cn.dev33.satoken.exception.StopMatchException;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
@@ -53,6 +51,7 @@
public class AppConfig implements WebMvcConfigurer {
@Autowired
private Config config;
+
@Value("${sso.enabled:false}")
private boolean ssoEnabled;
/**
@@ -97,7 +96,7 @@ public void addInterceptors(InterceptorRegistry registry) {
}))
.addPathPatterns("/api/**", "/openapi/**")
.excludePathPatterns("/api/login", "/api/ldap/ldapEnableStatus", "/download/**", "/druid/**");
- if (ssoEnabled){
+ if (ssoEnabled) {
registry.addInterceptor(buildInterceptor("GitHubClient")).addPathPatterns("/sso/*");
}
registry.addInterceptor(new TenantInterceptor())
@@ -122,6 +121,7 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/api/git/**")
.addPathPatterns("/api/jar/*");
}
+
private SecurityInterceptor buildInterceptor(final String client) {
return new SecurityInterceptor(config, client, JEEHttpActionAdapter.INSTANCE);
}
diff --git a/dinky-admin/src/main/java/org/dinky/controller/SsoCpntroller.java b/dinky-admin/src/main/java/org/dinky/controller/SsoCpntroller.java
index d07a53a8f5..bbd15714e9 100644
--- a/dinky-admin/src/main/java/org/dinky/controller/SsoCpntroller.java
+++ b/dinky-admin/src/main/java/org/dinky/controller/SsoCpntroller.java
@@ -1,6 +1,24 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.controller;
-import lombok.NoArgsConstructor;
import org.dinky.data.dto.LoginDTO;
import org.dinky.data.dto.UserDTO;
import org.dinky.data.enums.Status;
@@ -8,9 +26,12 @@
import org.dinky.data.result.Result;
import org.dinky.service.UserService;
import org.dinky.sso.web.LogoutController;
-import org.pac4j.core.config.Config;
+import java.util.List;
+import javax.annotation.PostConstruct;
+
+import org.pac4j.core.config.Config;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
@@ -20,9 +41,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
-import javax.annotation.PostConstruct;
-import java.util.List;
-
+import lombok.NoArgsConstructor;
/**
* @author 杨泽翰
@@ -34,21 +53,24 @@ public class SsoCpntroller {
@Value("${sso.enabled:false}")
private Boolean ssoEnabled;
-
-
@Value("${sso.centralLogout.defaultUrl:#{null}}")
private String defaultUrl;
@Value("${sso.centralLogout.logoutUrlPattern:#{null}}")
private String logoutUrlPattern;
+
@Value("${pac4j.properties.principalNameAttribute:#{null}}")
private String principalNameAttribute;
+
@Autowired
private Config config;
+
@Autowired
private JEEContext webContext;
+
@Autowired
private ProfileManager profileManager;
+
private LogoutController logoutController;
@Autowired
@@ -65,24 +87,24 @@ protected void afterPropertiesSet() {
logoutController.setDestroySession(true);
}
- @GetMapping ("/sso/token")
+ @GetMapping("/sso/token")
public Result token() throws AuthException {
- if (!ssoEnabled){
+ if (!ssoEnabled) {
return Result.failed(Status.SINGLE_LOGIN_DISABLED);
}
List all = profileManager.getAll(true);
String username = all.get(0).getAttribute(principalNameAttribute).toString();
- if (username == null){
+ if (username == null) {
throw new AuthException(Status.NOT_MATCHED_PRINCIPAL_NAME_ATTRIBUTE);
}
LoginDTO loginDTO = new LoginDTO();
loginDTO.setUsername(username);
loginDTO.setSsoLogin(true);
- return userService.loginUser(loginDTO);
+ return userService.loginUser(loginDTO);
}
- @GetMapping ("/sso/logout")
+
+ @GetMapping("/sso/logout")
public void logout() {
logoutController.logout(webContext.getNativeRequest(), webContext.getNativeResponse());
}
-
}
diff --git a/dinky-admin/src/main/java/org/dinky/data/dto/LoginDTO.java b/dinky-admin/src/main/java/org/dinky/data/dto/LoginDTO.java
index b73820f117..2470bb1ca9 100644
--- a/dinky-admin/src/main/java/org/dinky/data/dto/LoginDTO.java
+++ b/dinky-admin/src/main/java/org/dinky/data/dto/LoginDTO.java
@@ -19,11 +19,12 @@
package org.dinky.data.dto;
+import org.dinky.data.enums.UserType;
+
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
-import org.dinky.data.enums.UserType;
/**
* LoginUTO
@@ -49,14 +50,12 @@ public class LoginDTO {
@ApiModelProperty(value = "ldapLogin", required = true, example = "false", dataType = "Boolean")
private boolean ldapLogin;
+
@ApiModelProperty(value = "ssoLogin", required = true, example = "false", dataType = "Boolean")
private boolean ssoLogin;
-
public UserType getLoginType() {
-
- return isLdapLogin()? UserType.LDAP:UserType.SSO;
-
+ return isLdapLogin() ? UserType.LDAP : UserType.SSO;
}
}
diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java
index 06a61d78d5..46dc3e416c 100644
--- a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java
+++ b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java
@@ -180,7 +180,7 @@ public Result loginUser(LoginDTO loginDTO) {
try {
- switch (loginDTO.getLoginType()){
+ switch (loginDTO.getLoginType()) {
case LDAP:
user = ldapLogin(loginDTO);
break;
@@ -242,8 +242,7 @@ private User ssoLogin(LoginDTO loginDTO) throws AuthException {
userIds.add(userForm.getId());
tenantService.assignUserToTenant(new AssignUserToTenantDTO(tenant.getId(), userIds));
return userForm;
- }
- else{
+ } else {
if (user.getUserType() != UserType.SSO.getCode()) {
throw new AuthException(Status.USER_TYPE_ERROR);
}
diff --git a/dinky-admin/src/main/java/org/dinky/sso/annotation/AnnotationConfig.java b/dinky-admin/src/main/java/org/dinky/sso/annotation/AnnotationConfig.java
index 7920246080..ec4d2dafdf 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/annotation/AnnotationConfig.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/annotation/AnnotationConfig.java
@@ -1,8 +1,27 @@
-package org.dinky.sso.annotation;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+package org.dinky.sso.annotation;
import org.dinky.sso.annotation.ui.UIAnnotationAspect;
import org.dinky.sso.annotation.ws.WSAnnotationAspect;
+
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
diff --git a/dinky-admin/src/main/java/org/dinky/sso/annotation/CommonAspect.java b/dinky-admin/src/main/java/org/dinky/sso/annotation/CommonAspect.java
index 5ce7a47d0b..9a2021a937 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/annotation/CommonAspect.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/annotation/CommonAspect.java
@@ -1,5 +1,26 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.annotation;
+import java.util.List;
+
import org.pac4j.core.authorization.authorizer.IsAuthenticatedAuthorizer;
import org.pac4j.core.authorization.authorizer.RequireAllRolesAuthorizer;
import org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer;
@@ -11,8 +32,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.List;
-
/**
* Common aspect behaviors.
*
diff --git a/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/RequireAllRoles.java b/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/RequireAllRoles.java
index e91e688ae9..66c0104cb8 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/RequireAllRoles.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/RequireAllRoles.java
@@ -1,3 +1,22 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.annotation.ui;
import java.lang.annotation.ElementType;
diff --git a/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/RequireAnyRole.java b/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/RequireAnyRole.java
index 2103bcc133..9eb0119a22 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/RequireAnyRole.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/RequireAnyRole.java
@@ -1,3 +1,22 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.annotation.ui;
import java.lang.annotation.ElementType;
diff --git a/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/UIAnnotationAspect.java b/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/UIAnnotationAspect.java
index 2024f06d3d..6278ea60be 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/UIAnnotationAspect.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/annotation/ui/UIAnnotationAspect.java
@@ -1,8 +1,28 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.annotation.ui;
+import org.dinky.sso.annotation.CommonAspect;
+
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
-import org.dinky.sso.annotation.CommonAspect;
/**
* The aspect to define the web applications annotations.
diff --git a/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/RequireAllRoles.java b/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/RequireAllRoles.java
index 07ebfe693d..7b7c4c349b 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/RequireAllRoles.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/RequireAllRoles.java
@@ -1,3 +1,22 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.annotation.ws;
import java.lang.annotation.ElementType;
diff --git a/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/RequireAnyRole.java b/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/RequireAnyRole.java
index f67b8ac320..2e2862714a 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/RequireAnyRole.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/RequireAnyRole.java
@@ -1,3 +1,22 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.annotation.ws;
import java.lang.annotation.ElementType;
diff --git a/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/WSAnnotationAspect.java b/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/WSAnnotationAspect.java
index 27d3d51b0b..5112a82e8a 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/WSAnnotationAspect.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/annotation/ws/WSAnnotationAspect.java
@@ -1,8 +1,28 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.annotation.ws;
+import org.dinky.sso.annotation.CommonAspect;
+
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
-import org.dinky.sso.annotation.CommonAspect;
/**
* The aspect to define the web services annotations.
diff --git a/dinky-admin/src/main/java/org/dinky/sso/component/ComponentConfig.java b/dinky-admin/src/main/java/org/dinky/sso/component/ComponentConfig.java
index b4b7a89a3d..2ce6477fe4 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/component/ComponentConfig.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/component/ComponentConfig.java
@@ -1,5 +1,27 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.component;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.pac4j.core.config.Config;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.session.JEESessionStore;
@@ -11,9 +33,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.annotation.RequestScope;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
/**
* The configuration of the pac4j components.
*
diff --git a/dinky-admin/src/main/java/org/dinky/sso/web/CallbackController.java b/dinky-admin/src/main/java/org/dinky/sso/web/CallbackController.java
index 40c134e4bd..2e15d3d813 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/web/CallbackController.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/web/CallbackController.java
@@ -1,5 +1,27 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.web;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.pac4j.core.config.Config;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.JEEContextFactory;
@@ -16,9 +38,6 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
/**
*
This controller finishes the login process for an indirect client.
*
@@ -52,17 +71,27 @@ public class CallbackController {
public void callback(final HttpServletRequest request, final HttpServletResponse response) {
final SessionStore bestSessionStore = FindBest.sessionStore(null, config, JEESessionStore.INSTANCE);
- final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
- final CallbackLogic bestLogic = FindBest.callbackLogic(callbackLogic, config, DefaultCallbackLogic.INSTANCE);
+ final HttpActionAdapter bestAdapter =
+ FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
+ final CallbackLogic bestLogic =
+ FindBest.callbackLogic(callbackLogic, config, DefaultCallbackLogic.INSTANCE);
final JEEContext context = (JEEContext) FindBest.webContextFactory(null, config, JEEContextFactory.INSTANCE)
.newContext(request, response, bestSessionStore);
- bestLogic.perform(context, config, bestAdapter, this.defaultUrl, this.saveInSession, this.multiProfile,
- this.renewSession, this.defaultClient);
+ bestLogic.perform(
+ context,
+ config,
+ bestAdapter,
+ this.defaultUrl,
+ this.saveInSession,
+ this.multiProfile,
+ this.renewSession,
+ this.defaultClient);
}
@RequestMapping("${pac4j.callback.path/{cn}:/callback/{cn}}")
- public void callbackWithClientName(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("cn") final String cn) {
+ public void callbackWithClientName(
+ final HttpServletRequest request, final HttpServletResponse response, @PathVariable("cn") final String cn) {
callback(request, response);
}
diff --git a/dinky-admin/src/main/java/org/dinky/sso/web/LogoutController.java b/dinky-admin/src/main/java/org/dinky/sso/web/LogoutController.java
index 09f0aa0a17..93e69b7ca8 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/web/LogoutController.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/web/LogoutController.java
@@ -1,6 +1,27 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.web;
-import lombok.Data;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.pac4j.core.config.Config;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.JEEContextFactory;
@@ -16,8 +37,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import lombok.Data;
/**
*
This controller handles the (application + identity provider) logout process.
@@ -53,14 +73,21 @@ public class LogoutController {
public void logout(final HttpServletRequest request, final HttpServletResponse response) {
final SessionStore bestSessionStore = FindBest.sessionStore(null, config, JEESessionStore.INSTANCE);
- final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
- final LogoutLogic bestLogic = FindBest.logoutLogic(logoutLogic, config, DefaultLogoutLogic.INSTANCE);
+ final HttpActionAdapter bestAdapter =
+ FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
+ final LogoutLogic bestLogic =
+ FindBest.logoutLogic(logoutLogic, config, DefaultLogoutLogic.INSTANCE);
final JEEContext context = (JEEContext) FindBest.webContextFactory(null, config, JEEContextFactory.INSTANCE)
.newContext(request, response, bestSessionStore);
- bestLogic.perform(context, config, bestAdapter, this.defaultUrl, this.logoutUrlPattern,
- this.localLogout, this.destroySession, this.centralLogout);
+ bestLogic.perform(
+ context,
+ config,
+ bestAdapter,
+ this.defaultUrl,
+ this.logoutUrlPattern,
+ this.localLogout,
+ this.destroySession,
+ this.centralLogout);
}
-
-
}
diff --git a/dinky-admin/src/main/java/org/dinky/sso/web/SecurityInterceptor.java b/dinky-admin/src/main/java/org/dinky/sso/web/SecurityInterceptor.java
index 933c96d8ab..5ca6cdbd3a 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/web/SecurityInterceptor.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/web/SecurityInterceptor.java
@@ -1,5 +1,29 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
package org.dinky.sso.web;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.pac4j.core.authorization.authorizer.Authorizer;
import org.pac4j.core.config.Config;
import org.pac4j.core.context.JEEContext;
@@ -14,10 +38,6 @@
import org.pac4j.core.util.FindBest;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.concurrent.atomic.AtomicInteger;
-
/**
*
This interceptor protects an url.
*
@@ -67,12 +87,14 @@ public SecurityInterceptor(final Config config, final String clients, final Auth
this.authorizers = addAuthorizers(config, authorizers);
}
- public SecurityInterceptor(final Config config, final String clients, final String authorizers, final String matchers) {
+ public SecurityInterceptor(
+ final Config config, final String clients, final String authorizers, final String matchers) {
this(config, clients, authorizers);
this.matchers = matchers;
}
- public SecurityInterceptor(final Config config, final String clients, final Authorizer[] authorizers, final Matcher[] matchers) {
+ public SecurityInterceptor(
+ final Config config, final String clients, final Authorizer[] authorizers, final Matcher[] matchers) {
this(config, clients, addAuthorizers(config, authorizers));
this.matchers = addMatchers(config, matchers);
}
@@ -111,12 +133,22 @@ private static String addMatchers(final Config config, final Matcher[] matchers)
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
final SessionStore bestSessionStore = FindBest.sessionStore(null, config, JEESessionStore.INSTANCE);
- final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(httpActionAdapter, config, JEEHttpActionAdapter.INSTANCE);
- final SecurityLogic bestLogic = FindBest.securityLogic(securityLogic, config, DefaultSecurityLogic.INSTANCE);
+ final HttpActionAdapter bestAdapter =
+ FindBest.httpActionAdapter(httpActionAdapter, config, JEEHttpActionAdapter.INSTANCE);
+ final SecurityLogic bestLogic =
+ FindBest.securityLogic(securityLogic, config, DefaultSecurityLogic.INSTANCE);
final JEEContext context = (JEEContext) FindBest.webContextFactory(null, config, JEEContextFactory.INSTANCE)
.newContext(request, response, bestSessionStore);
- final Object result = bestLogic.perform(context, config, (ctx, profiles, parameters) -> true, bestAdapter, clients, authorizers, matchers, multiProfile);
+ final Object result = bestLogic.perform(
+ context,
+ config,
+ (ctx, profiles, parameters) -> true,
+ bestAdapter,
+ clients,
+ authorizers,
+ matchers,
+ multiProfile);
if (result == null) {
return false;
}
diff --git a/dinky-admin/src/main/resources/application-mysql.yml b/dinky-admin/src/main/resources/application-mysql.yml
index 6c71564216..ff7894eba4 100644
--- a/dinky-admin/src/main/resources/application-mysql.yml
+++ b/dinky-admin/src/main/resources/application-mysql.yml
@@ -17,7 +17,7 @@
spring:
datasource:
- url: jdbc:mysql://${MYSQL_ADDR:127.0.0.1:3306}/${MYSQL_DATABASE:dinky}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
- username: ${MYSQL_USERNAME:dinky}
- password: ${MYSQL_PASSWORD:dinky}
+ url: jdbc:mysql://${MYSQL_ADDR:127.0.0.1:3306}/${MYSQL_DATABASE:dinky2}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
+ username: ${MYSQL_USERNAME:root}
+ password: ${MYSQL_PASSWORD:yang19980712}
driver-class-name: com.mysql.cj.jdbc.Driver
diff --git a/dinky-admin/src/main/resources/application.yml b/dinky-admin/src/main/resources/application.yml
index d97c22e383..534c059b8e 100644
--- a/dinky-admin/src/main/resources/application.yml
+++ b/dinky-admin/src/main/resources/application.yml
@@ -148,7 +148,7 @@ crypto:
#################################################################################################################
#see https://github.com/pac4j/spring-webmvc-pac4j-boot-demo/blob/master/src/main/resources/application.properties
sso:
- enabled: false #enable sso
+ enabled: true #enable sso
logout:
destroySession: true
defaultUrl: /?defaulturlafterlogout
@@ -166,6 +166,8 @@ pac4j:
# https://github.com/pac4j/pac4j/blob/master/documentation/docs/config-module.md
properties:
principalNameAttribute: login #Authenticate user principal
- github.id: #Authentication client id
- github.secret: #Authentication client secret
+ github.id: 66cf7e8845a0ab15c8af
+ github.secret: a9ab402d124eeb9f994bf0a4bfa26527317eada7
+ # Optional, change by authentication client
+ # Please replace and fill in your client config below when enabled SSO
diff --git a/dinky-common/src/main/java/org/dinky/data/enums/Status.java b/dinky-common/src/main/java/org/dinky/data/enums/Status.java
index d3cbfa91a0..b35ce1caa2 100644
--- a/dinky-common/src/main/java/org/dinky/data/enums/Status.java
+++ b/dinky-common/src/main/java/org/dinky/data/enums/Status.java
@@ -255,7 +255,7 @@ public enum Status {
* SSO About *
*/
USER_TYPE_ERROR(22001, "sso.user.type.error"),
- NOT_MATCHED_PRINCIPAL_NAME_ATTRIBUTE(22002,"sso.user.type.error" ),
+ NOT_MATCHED_PRINCIPAL_NAME_ATTRIBUTE(22002, "sso.user.type.error"),
SINGLE_LOGIN_DISABLED(22003, "sso.not.enabled"),
/**
From db9cbb7def09b77c685fe68cfe66d40ba093394e Mon Sep 17 00:00:00 2001
From: yangzehan <627617031@qq.com>
Date: Tue, 9 Apr 2024 20:48:48 +0800
Subject: [PATCH 05/21] Delete redundant files, fix the SSO client, specify the
client name, and get it from the configuration instead
---
dinky-admin/src/main/java/org/dinky/configure/AppConfig.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java b/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
index aad88ac830..5cf5cf2c92 100644
--- a/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
+++ b/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
@@ -19,6 +19,7 @@
package org.dinky.configure;
+import lombok.extern.slf4j.Slf4j;
import org.dinky.data.constant.BaseConstant;
import org.dinky.interceptor.LocaleChangeInterceptor;
import org.dinky.interceptor.TenantInterceptor;
@@ -48,6 +49,7 @@
* @since 2021/11/28 19:35
*/
@Configuration
+@Slf4j
public class AppConfig implements WebMvcConfigurer {
@Autowired
private Config config;
@@ -97,7 +99,8 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/api/**", "/openapi/**")
.excludePathPatterns("/api/login", "/api/ldap/ldapEnableStatus", "/download/**", "/druid/**");
if (ssoEnabled) {
- registry.addInterceptor(buildInterceptor("GitHubClient")).addPathPatterns("/sso/*");
+ log.info("Load{}",config.getClients().getClients().get(0).getName());
+ registry.addInterceptor(buildInterceptor(config.getClients().getClients().get(0).getName())).addPathPatterns("/sso/*");
}
registry.addInterceptor(new TenantInterceptor())
.addPathPatterns("/api/**")
From 43e685dff9a9a6112d5355084ae42332cb562613 Mon Sep 17 00:00:00 2001
From: yangzehan <627617031@qq.com>
Date: Tue, 9 Apr 2024 20:52:29 +0800
Subject: [PATCH 06/21] =?UTF-8?q?mvn=20spotless=EF=BC=9Aapply?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/java/org/dinky/configure/AppConfig.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java b/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
index 5cf5cf2c92..a007aae58d 100644
--- a/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
+++ b/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
@@ -19,7 +19,6 @@
package org.dinky.configure;
-import lombok.extern.slf4j.Slf4j;
import org.dinky.data.constant.BaseConstant;
import org.dinky.interceptor.LocaleChangeInterceptor;
import org.dinky.interceptor.TenantInterceptor;
@@ -42,6 +41,7 @@
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
+import lombok.extern.slf4j.Slf4j;
/**
* AppConfiguration
@@ -99,8 +99,10 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/api/**", "/openapi/**")
.excludePathPatterns("/api/login", "/api/ldap/ldapEnableStatus", "/download/**", "/druid/**");
if (ssoEnabled) {
- log.info("Load{}",config.getClients().getClients().get(0).getName());
- registry.addInterceptor(buildInterceptor(config.getClients().getClients().get(0).getName())).addPathPatterns("/sso/*");
+ log.info("Load{}", config.getClients().getClients().get(0).getName());
+ registry.addInterceptor(buildInterceptor(
+ config.getClients().getClients().get(0).getName()))
+ .addPathPatterns("/sso/*");
}
registry.addInterceptor(new TenantInterceptor())
.addPathPatterns("/api/**")
From 59a1cef88062f7fa1ea350da3893f3b9de6acf66 Mon Sep 17 00:00:00 2001
From: yangzehan <627617031@qq.com>
Date: Tue, 9 Apr 2024 20:56:54 +0800
Subject: [PATCH 07/21] rollback
---
dinky-admin/src/main/resources/application-mysql.yml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/dinky-admin/src/main/resources/application-mysql.yml b/dinky-admin/src/main/resources/application-mysql.yml
index ff7894eba4..d0ac8fda40 100644
--- a/dinky-admin/src/main/resources/application-mysql.yml
+++ b/dinky-admin/src/main/resources/application-mysql.yml
@@ -17,7 +17,7 @@
spring:
datasource:
- url: jdbc:mysql://${MYSQL_ADDR:127.0.0.1:3306}/${MYSQL_DATABASE:dinky2}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
- username: ${MYSQL_USERNAME:root}
- password: ${MYSQL_PASSWORD:yang19980712}
- driver-class-name: com.mysql.cj.jdbc.Driver
+ url: jdbc:mysql://${MYSQL_ADDR:127.0.0.1:3306}/${MYSQL_DATABASE:dinky}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
+ username: ${MYSQL_USERNAME:dinky}
+ password: ${MYSQL_PASSWORD:dinky}
+ driver-class-name: com.mysql.cj.jdbc.Driver
\ No newline at end of file
From 4aeb724dcd2ba646a6f2a29f95568363a364ca27 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=B3=BD=E7=BF=B0?= <627617031@qq.com>
Date: Wed, 10 Apr 2024 09:28:38 +0800
Subject: [PATCH 08/21] Remove basic connection information
---
dinky-admin/src/main/resources/application.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dinky-admin/src/main/resources/application.yml b/dinky-admin/src/main/resources/application.yml
index 534c059b8e..13ae83cd35 100644
--- a/dinky-admin/src/main/resources/application.yml
+++ b/dinky-admin/src/main/resources/application.yml
@@ -166,8 +166,8 @@ pac4j:
# https://github.com/pac4j/pac4j/blob/master/documentation/docs/config-module.md
properties:
principalNameAttribute: login #Authenticate user principal
- github.id: 66cf7e8845a0ab15c8af
- github.secret: a9ab402d124eeb9f994bf0a4bfa26527317eada7
+ github.id:
+ github.secret:
# Optional, change by authentication client
# Please replace and fill in your client config below when enabled SSO
From afc9277bc26c2967fc157cc39ca391150e1ea199 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=B3=BD=E7=BF=B0?= <627617031@qq.com>
Date: Fri, 12 Apr 2024 11:01:16 +0800
Subject: [PATCH 09/21] Improve logic and add front-end code
---
.../java/org/dinky/configure/AppConfig.java | 6 ++--
.../org/dinky/controller/SsoCpntroller.java | 30 +++++++++++++++---
.../java/org/dinky/data/dto/LoginDTO.java | 8 ++++-
.../org/dinky/sso/web/CallbackController.java | 2 +-
.../src/main/resources/application.yml | 3 +-
dinky-web/src/locales/en-US/pages.ts | 1 +
dinky-web/src/locales/zh-CN/pages.ts | 1 +
.../src/pages/Other/Login/LoginForm/index.tsx | 19 ++++++++++--
dinky-web/src/pages/Other/Login/index.tsx | 31 ++++++++++++++++++-
dinky-web/src/services/BusinessCrud.ts | 14 +++++++++
dinky-web/src/services/endpoints.tsx | 4 +++
11 files changed, 105 insertions(+), 14 deletions(-)
diff --git a/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java b/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
index a007aae58d..3485ad0ef3 100644
--- a/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
+++ b/dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
@@ -97,16 +97,16 @@ public void addInterceptors(InterceptorRegistry registry) {
}
}))
.addPathPatterns("/api/**", "/openapi/**")
- .excludePathPatterns("/api/login", "/api/ldap/ldapEnableStatus", "/download/**", "/druid/**");
+ .excludePathPatterns("/api/sso/ssoEnableStatus","/api/login", "/api/ldap/ldapEnableStatus", "/download/**", "/druid/**");
if (ssoEnabled) {
log.info("Load{}", config.getClients().getClients().get(0).getName());
registry.addInterceptor(buildInterceptor(
config.getClients().getClients().get(0).getName()))
- .addPathPatterns("/sso/*");
+ .addPathPatterns("/api/sso/login").addPathPatterns("/api/sso/token");
}
registry.addInterceptor(new TenantInterceptor())
.addPathPatterns("/api/**")
- .excludePathPatterns("/api/login", "/api/ldap/ldapEnableStatus")
+ .excludePathPatterns("/api/sso/ssoEnableStatus","/api/login", "/api/ldap/ldapEnableStatus")
.addPathPatterns("/api/alertGroup/**")
.addPathPatterns("/api/alertHistory/**")
.addPathPatterns("/api/alertInstance/**")
diff --git a/dinky-admin/src/main/java/org/dinky/controller/SsoCpntroller.java b/dinky-admin/src/main/java/org/dinky/controller/SsoCpntroller.java
index bbd15714e9..927c13e829 100644
--- a/dinky-admin/src/main/java/org/dinky/controller/SsoCpntroller.java
+++ b/dinky-admin/src/main/java/org/dinky/controller/SsoCpntroller.java
@@ -19,6 +19,8 @@
package org.dinky.controller;
+import cn.dev33.satoken.annotation.SaIgnore;
+import io.swagger.annotations.ApiOperation;
import org.dinky.data.dto.LoginDTO;
import org.dinky.data.dto.UserDTO;
import org.dinky.data.enums.Status;
@@ -39,17 +41,24 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.NoArgsConstructor;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.view.RedirectView;
/**
* @author 杨泽翰
*/
@RestController
@NoArgsConstructor
+@RequestMapping("/api/sso")
@ConfigurationProperties(prefix = "pac4j")
public class SsoCpntroller {
+ @Value("${sso.baseUrl:localhost:8000}")
+ private String baseUrl;
@Value("${sso.enabled:false}")
private Boolean ssoEnabled;
@@ -87,8 +96,8 @@ protected void afterPropertiesSet() {
logoutController.setDestroySession(true);
}
- @GetMapping("/sso/token")
- public Result token() throws AuthException {
+ @GetMapping("/token")
+ public Result ssoToken() throws AuthException {
if (!ssoEnabled) {
return Result.failed(Status.SINGLE_LOGIN_DISABLED);
}
@@ -103,8 +112,21 @@ public Result token() throws AuthException {
return userService.loginUser(loginDTO);
}
- @GetMapping("/sso/logout")
- public void logout() {
+ @GetMapping("/login")
+ public ModelAndView ssoLogin() {
+ RedirectView redirectView = new RedirectView("http://"+baseUrl+"/#/user/login?from=sso");
+ return new ModelAndView(redirectView);
+ }
+
+ @GetMapping("/logout")
+ public void ssoLogout() {
logoutController.logout(webContext.getNativeRequest(), webContext.getNativeResponse());
}
+
+ @GetMapping("/ssoEnableStatus")
+ @SaIgnore
+ @ApiOperation("Get SSO enable status")
+ public Result ssoStatus() {
+ return Result.succeed(ssoEnabled);
+ }
}
diff --git a/dinky-admin/src/main/java/org/dinky/data/dto/LoginDTO.java b/dinky-admin/src/main/java/org/dinky/data/dto/LoginDTO.java
index 2470bb1ca9..5e5525b5d0 100644
--- a/dinky-admin/src/main/java/org/dinky/data/dto/LoginDTO.java
+++ b/dinky-admin/src/main/java/org/dinky/data/dto/LoginDTO.java
@@ -55,7 +55,13 @@ public class LoginDTO {
private boolean ssoLogin;
public UserType getLoginType() {
+ if (isLdapLogin()){
+ return UserType.LDAP;
+ }
+ if (isSsoLogin()){
+ return UserType.SSO;
+ }
- return isLdapLogin() ? UserType.LDAP : UserType.SSO;
+ return UserType.LOCAL;
}
}
diff --git a/dinky-admin/src/main/java/org/dinky/sso/web/CallbackController.java b/dinky-admin/src/main/java/org/dinky/sso/web/CallbackController.java
index 2e15d3d813..9a8a6cf10f 100644
--- a/dinky-admin/src/main/java/org/dinky/sso/web/CallbackController.java
+++ b/dinky-admin/src/main/java/org/dinky/sso/web/CallbackController.java
@@ -49,7 +49,7 @@ public class CallbackController {
private CallbackLogic callbackLogic;
- @Value("${pac4j.callback.defaultUrl:#{null}}")
+ @Value("${pac4j.callback.defaultUrl:api/sso/login}")
private String defaultUrl;
@Value("${pac4j.callback.multiProfile:#{null}}")
diff --git a/dinky-admin/src/main/resources/application.yml b/dinky-admin/src/main/resources/application.yml
index 13ae83cd35..baa4243e57 100644
--- a/dinky-admin/src/main/resources/application.yml
+++ b/dinky-admin/src/main/resources/application.yml
@@ -16,7 +16,7 @@ spring:
# If you use pgsql database, please configure pgsql database connection information in application-pgsql.yml
# If you use the h2 database, please configure the h2 database connection information in application-h2.yml,
# note: the h2 database is only for experience use, and the related data that has been created cannot be migrated, please use it with caution
- active: ${DB_ACTIVE:h2} #[h2,mysql,pgsql]
+ active: ${DB_ACTIVE:mysql} #[h2,mysql,pgsql]
include: jmx
lifecycle:
timeout-per-shutdown-phase: 30s
@@ -155,6 +155,7 @@ sso:
centralLogout:
defaultUrl: http://localhost:8888/?defaulturlafterlogoutafteridp
logoutUrlPattern: http://localhost:8888/.*
+ baseUrl: localhost:8000
#################################################################################################################
################################################# pac4j Config ####################################################
diff --git a/dinky-web/src/locales/en-US/pages.ts b/dinky-web/src/locales/en-US/pages.ts
index 34cc0375b1..74b00fd07b 100644
--- a/dinky-web/src/locales/en-US/pages.ts
+++ b/dinky-web/src/locales/en-US/pages.ts
@@ -292,6 +292,7 @@ export default {
'login.chooseTenantFailed': 'Tenant selection failed, please check. . . ',
'login.chooseTenantSuccess': '{msg}, Use [ {tenantCode} ] to enter the system, loading. . .',
'login.ldapLogin': 'LDAP Login',
+ 'login.ssoLogin': 'SSO Login',
'login.notbindtenant': 'You have not bound a tenant, please contact the administrator',
'login.password.placeholder': 'Password',
'login.password.required': 'Please input your password!',
diff --git a/dinky-web/src/locales/zh-CN/pages.ts b/dinky-web/src/locales/zh-CN/pages.ts
index 07769d9f6f..9423832d26 100644
--- a/dinky-web/src/locales/zh-CN/pages.ts
+++ b/dinky-web/src/locales/zh-CN/pages.ts
@@ -280,6 +280,7 @@ export default {
'login.chooseTenantFailed': '租户选择失败,请检查...',
'login.chooseTenantSuccess': '{msg},使用【 {tenantCode} 】进入系统,加载中...',
'login.ldapLogin': 'LDAP登录',
+ 'login.ssoLogin': 'SSO 登录',
'login.notbindtenant': '您还没有绑定租户,请联系管理员',
'login.password.placeholder': '密码',
'login.password.required': '密码是必填项!',
diff --git a/dinky-web/src/pages/Other/Login/LoginForm/index.tsx b/dinky-web/src/pages/Other/Login/LoginForm/index.tsx
index 54b1dd887b..ec7e5792fd 100644
--- a/dinky-web/src/pages/Other/Login/LoginForm/index.tsx
+++ b/dinky-web/src/pages/Other/Login/LoginForm/index.tsx
@@ -40,8 +40,15 @@ const LoginForm: React.FC = (props) => {
const [submitting, setSubmitting] = useState(false);
const [ldapEnabled, setLdapEnabled] = useState(false);
+ const [ssoEnabled, setSsoEnabled] = useState(false);
useEffect(() => {
+ getData(API_CONSTANTS.GET_SSO_ENABLE).then(
+ (res) => {
+ setSsoEnabled(res.data);
+ },
+ (err) => console.error(err)
+ );
getData(API_CONSTANTS.GET_LDAP_ENABLE).then(
(res) => {
setLdapEnabled(res.data);
@@ -95,9 +102,14 @@ const LoginForm: React.FC = (props) => {
{l('login.rememberMe')}