forked from github/dataease
feat(X-Pack): 新增oauth2认证 #11745
This commit is contained in:
parent
55cdd79314
commit
f0ea38dc71
@ -3,12 +3,20 @@ import router from '@/router'
|
||||
import { usePermissionStoreWithOut } from '@/store/modules/permission'
|
||||
import { interactiveStoreWithOut } from '@/store/modules/interactive'
|
||||
import { useCache } from '@/hooks/web/useCache'
|
||||
import request from '@/config/axios'
|
||||
|
||||
const { wsCache } = useCache()
|
||||
const permissionStore = usePermissionStoreWithOut()
|
||||
const userStore = useUserStoreWithOut()
|
||||
const interactiveStore = interactiveStoreWithOut()
|
||||
|
||||
export const logoutHandler = (justClean?: boolean) => {
|
||||
const idToken = wsCache.get('oauth2-id-token')
|
||||
if (idToken) {
|
||||
request.get({ url: `/oauth2/logout/${idToken}` }).finally(() => {
|
||||
wsCache.delete('oauth2-id-token')
|
||||
})
|
||||
}
|
||||
userStore.clear()
|
||||
userStore.$reset()
|
||||
permissionStore.clear()
|
||||
|
@ -16,7 +16,7 @@ import { XpackComponent } from '@/components/plugin'
|
||||
import { logoutHandler } from '@/utils/logout'
|
||||
import DeImage from '@/assets/login-desc-de.png'
|
||||
import elementResizeDetectorMaker from 'element-resize-detector'
|
||||
import { checkPlatform, cleanPlatformFlag } from '@/utils/utils'
|
||||
import { checkPlatform, cleanPlatformFlag, getQueryString } from '@/utils/utils'
|
||||
import xss from 'xss'
|
||||
const { wsCache } = useCache()
|
||||
const appStore = useAppStoreWithOut()
|
||||
@ -253,6 +253,8 @@ onMounted(async () => {
|
||||
} else {
|
||||
preheat.value = false
|
||||
}
|
||||
} else if (getQueryString('state')?.includes('de-oauth2-')) {
|
||||
preheat.value = true
|
||||
}
|
||||
if (localStorage.getItem('DE-GATEWAY-FLAG')) {
|
||||
const msg = localStorage.getItem('DE-GATEWAY-FLAG')
|
||||
|
@ -34,6 +34,9 @@ public interface XpackAuthenticationApi {
|
||||
@PostMapping("/save/ldap")
|
||||
String saveLdap(@RequestBody XpackLdapVO editor);
|
||||
|
||||
@PostMapping("/save/oauth2")
|
||||
String saveOauth2(@RequestBody XpackOauth2VO editor);
|
||||
|
||||
|
||||
@GetMapping("/info/oidc")
|
||||
XpackOidcVO oidcInfo();
|
||||
@ -44,6 +47,9 @@ public interface XpackAuthenticationApi {
|
||||
@GetMapping("/info/ldap")
|
||||
XpackLdapVO ldapInfo();
|
||||
|
||||
@GetMapping("/info/oauth2")
|
||||
XpackOauth2VO oauth2Info();
|
||||
|
||||
|
||||
@PostMapping("/validate/oidc")
|
||||
String validateOidc(@RequestBody XpackOidcVO editor);
|
||||
@ -54,10 +60,14 @@ public interface XpackAuthenticationApi {
|
||||
@PostMapping("/validate/ldap")
|
||||
String validateLdap(@RequestBody XpackLdapVO editor);
|
||||
|
||||
@PostMapping("/validate/oauth2")
|
||||
String validateOauth2(@RequestBody XpackOauth2VO editor);
|
||||
|
||||
@PostMapping("/validateId/{id}")
|
||||
String validate(@PathVariable("id") Long id);
|
||||
|
||||
@Operation(summary = "查询状态")
|
||||
@GetMapping("/status")
|
||||
List<XpackAuthenticationStatusVO> status();
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package io.dataease.api.xpack.settings;
|
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.dataease.api.xpack.settings.request.XpackOauth2TokenRequest;
|
||||
import io.dataease.api.xpack.settings.vo.XpackOauthAuthVO;
|
||||
import io.dataease.api.xpack.settings.vo.XpackOauthTokenVO;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@Tag(name = "Oauth2认证")
|
||||
@ApiSupport(order = 899)
|
||||
public interface XpackOauth2Api {
|
||||
|
||||
@GetMapping("/auth")
|
||||
XpackOauthAuthVO auth();
|
||||
|
||||
@PostMapping("/token")
|
||||
XpackOauthTokenVO oauth2Token(@RequestBody XpackOauth2TokenRequest request);
|
||||
|
||||
@GetMapping("/logout/{idToken}")
|
||||
void logout(@PathVariable("idToken") String idToken);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.dataease.api.xpack.settings.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class XpackOauth2TokenRequest implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 489213446985742448L;
|
||||
|
||||
private String code;
|
||||
|
||||
private String state;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.dataease.api.xpack.settings.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class XpackOauth2VO implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 2395518228048236146L;
|
||||
|
||||
private String clientId;
|
||||
|
||||
private String clientSecret;
|
||||
|
||||
private String authEndpoint;
|
||||
|
||||
private String tokenEndpoint;
|
||||
|
||||
private String userInfoEndpoint;
|
||||
|
||||
private String logoutEndpoint;
|
||||
|
||||
private String scope;
|
||||
|
||||
private String mapping;
|
||||
|
||||
private String redirectUri;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package io.dataease.api.xpack.settings.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class XpackOauthAuthVO implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -3658093847024323465L;
|
||||
|
||||
private String state;
|
||||
|
||||
private String clientId;
|
||||
|
||||
private String redirectUri;
|
||||
|
||||
private String authEndpoint;
|
||||
|
||||
private String scope;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.dataease.api.xpack.settings.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class XpackOauthTokenVO implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -3594367641594329352L;
|
||||
|
||||
private String token;
|
||||
|
||||
private String idToken;
|
||||
}
|
@ -68,6 +68,7 @@ public class WhitelistUtils {
|
||||
|| StringUtils.startsWithAny(requestURI, "/geo/")
|
||||
|| StringUtils.startsWithAny(requestURI, "/websocket")
|
||||
|| StringUtils.startsWithAny(requestURI, "/map/")
|
||||
|| StringUtils.startsWithAny(requestURI, "/oauth2/")
|
||||
|| StringUtils.startsWithAny(requestURI, "/typeface/download")
|
||||
|| StringUtils.startsWithAny(requestURI, "/typeface/defaultFont")
|
||||
|| StringUtils.startsWithAny(requestURI, "/typeface/listFont")
|
||||
|
Loading…
Reference in New Issue
Block a user