Skip to content

Commit 9fe4604

Browse files
author
François
committed
Issues/300: Use Jackson to deserialize Roles[]
1 parent 997a7c4 commit 9fe4604

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

api/src/main/java/io/kafbat/ui/model/rbac/Subject.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
import static com.google.common.base.Preconditions.checkArgument;
44
import static com.google.common.base.Preconditions.checkNotNull;
55

6+
import com.fasterxml.jackson.annotation.JsonProperty;
67
import io.kafbat.ui.model.rbac.provider.Provider;
78
import java.util.Objects;
8-
import lombok.Data;
9+
import lombok.Builder;
10+
import lombok.Value;
11+
import lombok.extern.jackson.Jacksonized;
912

10-
@Data
13+
@Value
14+
@Jacksonized
15+
@Builder
1116
public class Subject {
1217

1318
Provider provider;
1419
String type;
1520
String value;
16-
boolean isRegex = false;
21+
boolean isRegex;
1722

1823
public void validate() {
1924
checkNotNull(type, "Subject type cannot be null");

api/src/test/java/io/kafbat/ui/config/RegexBasedProviderAuthorityExtractorTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import static org.mockito.Mockito.when;
88
import static org.springframework.security.oauth2.client.registration.ClientRegistration.withRegistrationId;
99

10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
12+
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
1013
import io.kafbat.ui.config.auth.OAuthProperties;
1114
import io.kafbat.ui.model.rbac.Role;
1215
import io.kafbat.ui.service.rbac.AccessControlService;
@@ -16,6 +19,7 @@
1619
import io.kafbat.ui.service.rbac.extractor.OauthAuthorityExtractor;
1720
import io.kafbat.ui.service.rbac.extractor.ProviderAuthorityExtractor;
1821
import io.kafbat.ui.util.AccessControlServiceMock;
22+
import java.io.IOException;
1923
import java.io.InputStream;
2024
import java.time.Instant;
2125
import java.time.temporal.ChronoUnit;
@@ -32,27 +36,25 @@
3236
import org.springframework.security.oauth2.core.OAuth2AccessToken;
3337
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
3438
import org.springframework.security.oauth2.core.user.OAuth2User;
35-
import org.yaml.snakeyaml.Yaml;
36-
import org.yaml.snakeyaml.introspector.BeanAccess;
3739

3840
public class RegexBasedProviderAuthorityExtractorTest {
3941

4042

4143
private final AccessControlService accessControlService = new AccessControlServiceMock().getMock();
42-
Yaml yaml;
4344
ProviderAuthorityExtractor extractor;
4445

4546
@BeforeEach
46-
void setUp() {
47-
yaml = new Yaml();
48-
yaml.setBeanAccess(BeanAccess.FIELD);
47+
void setUp() throws IOException {
48+
49+
YAMLMapper mapper = new YAMLMapper();
4950

5051
InputStream rolesFile = this.getClass()
5152
.getClassLoader()
5253
.getResourceAsStream("roles_definition.yaml");
5354

54-
Role[] roleArray = yaml.loadAs(rolesFile, Role[].class);
55-
when(accessControlService.getRoles()).thenReturn(List.of(roleArray));
55+
Role[] roles = mapper.readValue(rolesFile, Role[].class);
56+
57+
when(accessControlService.getRoles()).thenReturn(List.of(roles));
5658

5759
}
5860

0 commit comments

Comments
 (0)