Skip to content

Commit

Permalink
refactor: auth provider sorting logic for better maintainability and …
Browse files Browse the repository at this point in the history
…clarity (#6846)

* refactor: auth provider sorting logic for better maintainability and clarity

* Refine UI

* chore: remove other auth type

* Remove other auth providers

---------

Co-authored-by: Ryan Wang <[email protected]>
  • Loading branch information
guqing and ruibaby authored Oct 14, 2024
1 parent 4059f15 commit 82498dc
Show file tree
Hide file tree
Showing 20 changed files with 411 additions and 255 deletions.
16 changes: 12 additions & 4 deletions api-docs/openapi/v3_0/aggregated.json
Original file line number Diff line number Diff line change
Expand Up @@ -16034,6 +16034,7 @@
},
"AuthProviderSpec": {
"required": [
"authType",
"authenticationUrl",
"displayName"
],
Expand Down Expand Up @@ -16072,10 +16073,6 @@
"method": {
"type": "string"
},
"priority": {
"type": "integer",
"format": "int32"
},
"rememberMeSupport": {
"type": "boolean"
},
Expand Down Expand Up @@ -18297,6 +18294,13 @@
],
"type": "object",
"properties": {
"authType": {
"type": "string",
"enum": [
"FORM",
"OAUTH2"
]
},
"authenticationUrl": {
"type": "string"
},
Expand Down Expand Up @@ -18324,6 +18328,10 @@
"name": {
"type": "string"
},
"priority": {
"type": "integer",
"format": "int32"
},
"privileged": {
"type": "boolean"
},
Expand Down
16 changes: 12 additions & 4 deletions api-docs/openapi/v3_0/apis_console.api_v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3568,6 +3568,7 @@
},
"AuthProviderSpec": {
"required": [
"authType",
"authenticationUrl",
"displayName"
],
Expand Down Expand Up @@ -3606,10 +3607,6 @@
"method": {
"type": "string"
},
"priority": {
"type": "integer",
"format": "int32"
},
"rememberMeSupport": {
"type": "boolean"
},
Expand Down Expand Up @@ -4435,6 +4432,13 @@
],
"type": "object",
"properties": {
"authType": {
"type": "string",
"enum": [
"FORM",
"OAUTH2"
]
},
"authenticationUrl": {
"type": "string"
},
Expand Down Expand Up @@ -4462,6 +4466,10 @@
"name": {
"type": "string"
},
"priority": {
"type": "integer",
"format": "int32"
},
"privileged": {
"type": "boolean"
},
Expand Down
5 changes: 1 addition & 4 deletions api-docs/openapi/v3_0/apis_extension.api_v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8666,6 +8666,7 @@
},
"AuthProviderSpec": {
"required": [
"authType",
"authenticationUrl",
"displayName"
],
Expand Down Expand Up @@ -8704,10 +8705,6 @@
"method": {
"type": "string"
},
"priority": {
"type": "integer",
"format": "int32"
},
"rememberMeSupport": {
"type": "boolean"
},
Expand Down
15 changes: 10 additions & 5 deletions api/src/main/java/run/halo/app/core/extension/AuthProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.springframework.lang.NonNull;
import run.halo.app.extension.AbstractExtension;
import run.halo.app.extension.GVK;

Expand Down Expand Up @@ -55,19 +57,23 @@ public static class AuthProviderSpec {
/**
* Auth type: form or oauth2.
*/
private AuthType authType;
@Getter(onMethod_ = @NonNull)
@Schema(requiredMode = REQUIRED)
private AuthType authType = AuthType.OAUTH2;

private String bindingUrl;

private String unbindUrl;

private int priority;

@Schema(requiredMode = NOT_REQUIRED)
private SettingRef settingRef;

@Schema(requiredMode = NOT_REQUIRED)
private ConfigMapRef configMapRef;

public void setAuthType(AuthType authType) {
this.authType = (authType == null ? AuthType.OAUTH2 : authType);
}
}

@Data
Expand All @@ -89,7 +95,6 @@ public static class ConfigMapRef {

public enum AuthType {
FORM,
OAUTH2,
;
OAUTH2
}
}
2 changes: 1 addition & 1 deletion api/src/main/java/run/halo/app/extension/Unstructured.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public MetadataOperator getMetadata() {
return new UnstructuredMetadata();
}

@EqualsAndHashCode(exclude = "version")
@EqualsAndHashCode(exclude = "tatersion")
class UnstructuredMetadata implements MetadataOperator {

@Override
Expand Down
13 changes: 11 additions & 2 deletions api/src/main/java/run/halo/app/infra/SystemSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.List;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.boot.convert.ApplicationConversionService;
import run.halo.app.extension.ConfigMap;
import run.halo.app.infra.utils.JsonUtils;
Expand Down Expand Up @@ -113,7 +114,15 @@ public static class Menu {
@Data
public static class AuthProvider {
public static final String GROUP = "authProvider";
private Set<String> enabled;
private List<AuthProviderState> states;
}

@Data
@Accessors(chain = true)
public static class AuthProviderState {
private String name;
private boolean enabled;
private int priority;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public interface AuthProviderService {

Mono<List<ListedAuthProvider>> listAll();

/**
* Return a list of enabled AuthProviders sorted by priority.
*/
Flux<AuthProvider> getEnabledProviders();

}
Loading

0 comments on commit 82498dc

Please sign in to comment.