Commit e841f10b49982c68b40635db1e2df4938091184a
1 parent
12e2d2ef
Added 'enabled' field to ClientRegistration
Showing
10 changed files
with
38 additions
and
18 deletions
... | ... | @@ -18,6 +18,7 @@ DROP TABLE IF EXISTS oauth2_client_registration; |
18 | 18 | |
19 | 19 | CREATE TABLE IF NOT EXISTS oauth2_client_registration ( |
20 | 20 | id uuid NOT NULL CONSTRAINT oauth2_client_registration_pkey PRIMARY KEY, |
21 | + enabled boolean, | |
21 | 22 | created_time bigint NOT NULL, |
22 | 23 | additional_info varchar, |
23 | 24 | domain_name varchar(255), | ... | ... |
... | ... | @@ -34,6 +34,7 @@ import java.util.List; |
34 | 34 | @NoArgsConstructor |
35 | 35 | public class OAuth2ClientRegistration extends SearchTextBasedWithAdditionalInfo<OAuth2ClientRegistrationId> implements HasName { |
36 | 36 | |
37 | + private boolean enabled; | |
37 | 38 | private String domainName; |
38 | 39 | private String redirectUriTemplate; |
39 | 40 | private OAuth2MapperConfig mapperConfig; |
... | ... | @@ -51,6 +52,7 @@ public class OAuth2ClientRegistration extends SearchTextBasedWithAdditionalInfo< |
51 | 52 | |
52 | 53 | public OAuth2ClientRegistration(OAuth2ClientRegistration clientRegistration) { |
53 | 54 | super(clientRegistration); |
55 | + this.enabled = clientRegistration.enabled; | |
54 | 56 | this.domainName = clientRegistration.domainName; |
55 | 57 | this.redirectUriTemplate = clientRegistration.redirectUriTemplate; |
56 | 58 | this.mapperConfig = clientRegistration.mapperConfig; | ... | ... |
... | ... | @@ -358,6 +358,7 @@ public class ModelConstants { |
358 | 358 | * OAuth2 client registration constants. |
359 | 359 | */ |
360 | 360 | public static final String OAUTH2_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; |
361 | + public static final String OAUTH2_ENABLED_PROPERTY = "enabled"; | |
361 | 362 | public static final String OAUTH2_CLIENT_REGISTRATION_COLUMN_FAMILY_NAME = "oauth2_client_registration"; |
362 | 363 | public static final String OAUTH2_CLIENT_REGISTRATION_TEMPLATE_COLUMN_FAMILY_NAME = "oauth2_client_registration_template"; |
363 | 364 | public static final String OAUTH2_TEMPLATE_PROVIDER_ID_PROPERTY = "provider_id"; | ... | ... |
... | ... | @@ -38,6 +38,8 @@ import java.util.UUID; |
38 | 38 | @Table(name = ModelConstants.OAUTH2_CLIENT_REGISTRATION_COLUMN_FAMILY_NAME) |
39 | 39 | public class OAuth2ClientRegistrationEntity extends BaseSqlEntity<OAuth2ClientRegistration> { |
40 | 40 | |
41 | + @Column(name = ModelConstants.OAUTH2_ENABLED_PROPERTY) | |
42 | + private Boolean enabled; | |
41 | 43 | @Column(name = ModelConstants.OAUTH2_DOMAIN_NAME_PROPERTY) |
42 | 44 | private String domainName; |
43 | 45 | @Column(name = ModelConstants.OAUTH2_CLIENT_ID_PROPERTY) |
... | ... | @@ -109,6 +111,7 @@ public class OAuth2ClientRegistrationEntity extends BaseSqlEntity<OAuth2ClientRe |
109 | 111 | if (clientRegistration.getId() != null) { |
110 | 112 | this.setUuid(clientRegistration.getId().getId()); |
111 | 113 | } |
114 | + this.enabled = clientRegistration.isEnabled(); | |
112 | 115 | this.domainName = clientRegistration.getDomainName(); |
113 | 116 | this.createdTime = clientRegistration.getCreatedTime(); |
114 | 117 | this.clientId = clientRegistration.getClientId(); |
... | ... | @@ -154,6 +157,7 @@ public class OAuth2ClientRegistrationEntity extends BaseSqlEntity<OAuth2ClientRe |
154 | 157 | public OAuth2ClientRegistration toData() { |
155 | 158 | OAuth2ClientRegistration clientRegistration = new OAuth2ClientRegistration(); |
156 | 159 | clientRegistration.setId(new OAuth2ClientRegistrationId(id)); |
160 | + clientRegistration.setEnabled(enabled); | |
157 | 161 | clientRegistration.setCreatedTime(createdTime); |
158 | 162 | clientRegistration.setDomainName(domainName); |
159 | 163 | clientRegistration.setAdditionalInfo(additionalInfo); | ... | ... |
... | ... | @@ -48,6 +48,7 @@ public class OAuth2ServiceImpl extends AbstractEntityService implements OAuth2Se |
48 | 48 | log.trace("Executing getOAuth2Clients [{}]", domainName); |
49 | 49 | validateString(domainName, INCORRECT_DOMAIN_NAME + domainName); |
50 | 50 | return clientRegistrationDao.findByDomainName(domainName).stream() |
51 | + .filter(OAuth2ClientRegistration::isEnabled) | |
51 | 52 | .map(OAuth2Utils::toClientInfo) |
52 | 53 | .collect(Collectors.toList()); |
53 | 54 | } | ... | ... |
... | ... | @@ -37,15 +37,19 @@ public class OAuth2Utils { |
37 | 37 | public static List<OAuth2ClientRegistration> toClientRegistrations(OAuth2ClientsParams oAuth2Params) { |
38 | 38 | return oAuth2Params.getOAuth2DomainDtos().stream() |
39 | 39 | .flatMap(domainParams -> domainParams.getClientRegistrations().stream() |
40 | - .map(clientRegistrationDto -> OAuth2Utils.toClientRegistration(domainParams.getDomainName(), | |
41 | - domainParams.getRedirectUriTemplate(), clientRegistrationDto) | |
40 | + .map(clientRegistrationDto -> OAuth2Utils.toClientRegistration(oAuth2Params.isEnabled(), | |
41 | + domainParams.getDomainName(), | |
42 | + domainParams.getRedirectUriTemplate(), | |
43 | + clientRegistrationDto) | |
42 | 44 | )) |
43 | 45 | .collect(Collectors.toList()); |
44 | 46 | } |
45 | 47 | |
46 | 48 | public static OAuth2ClientsParams toOAuth2Params(List<OAuth2ClientRegistration> clientRegistrations) { |
47 | 49 | Map<String, OAuth2ClientsDomainParams> domainParamsMap = new HashMap<>(); |
50 | + boolean enabled = true; | |
48 | 51 | for (OAuth2ClientRegistration clientRegistration : clientRegistrations) { |
52 | + enabled = clientRegistration.isEnabled(); | |
49 | 53 | String domainName = clientRegistration.getDomainName(); |
50 | 54 | OAuth2ClientsDomainParams domainParams = domainParamsMap.computeIfAbsent(domainName, |
51 | 55 | key -> new OAuth2ClientsDomainParams(domainName, clientRegistration.getRedirectUriTemplate(), new ArrayList<>()) |
... | ... | @@ -53,7 +57,7 @@ public class OAuth2Utils { |
53 | 57 | domainParams.getClientRegistrations() |
54 | 58 | .add(toClientRegistrationDto(clientRegistration)); |
55 | 59 | } |
56 | - return new OAuth2ClientsParams(new ArrayList<>(domainParamsMap.values())); | |
60 | + return new OAuth2ClientsParams(enabled, new ArrayList<>(domainParamsMap.values())); | |
57 | 61 | } |
58 | 62 | |
59 | 63 | public static ClientRegistrationDto toClientRegistrationDto(OAuth2ClientRegistration oAuth2ClientRegistration) { |
... | ... | @@ -76,10 +80,12 @@ public class OAuth2Utils { |
76 | 80 | .build(); |
77 | 81 | } |
78 | 82 | |
79 | - public static OAuth2ClientRegistration toClientRegistration(String domainName, String redirectUriTemplate, | |
83 | + private static OAuth2ClientRegistration toClientRegistration(boolean enabled, String domainName, | |
84 | + String redirectUriTemplate, | |
80 | 85 | ClientRegistrationDto clientRegistrationDto) { |
81 | 86 | OAuth2ClientRegistration clientRegistration = new OAuth2ClientRegistration(); |
82 | 87 | clientRegistration.setId(clientRegistrationDto.getId()); |
88 | + clientRegistration.setEnabled(enabled); | |
83 | 89 | clientRegistration.setCreatedTime(clientRegistrationDto.getCreatedTime()); |
84 | 90 | clientRegistration.setDomainName(domainName); |
85 | 91 | clientRegistration.setRedirectUriTemplate(redirectUriTemplate); | ... | ... |
... | ... | @@ -293,6 +293,7 @@ CREATE TABLE IF NOT EXISTS ts_kv_dictionary ( |
293 | 293 | |
294 | 294 | CREATE TABLE IF NOT EXISTS oauth2_client_registration ( |
295 | 295 | id uuid NOT NULL CONSTRAINT oauth2_client_registration_pkey PRIMARY KEY, |
296 | + enabled boolean, | |
296 | 297 | created_time bigint NOT NULL, |
297 | 298 | additional_info varchar, |
298 | 299 | domain_name varchar(255), | ... | ... |
... | ... | @@ -318,6 +318,7 @@ CREATE TABLE IF NOT EXISTS ts_kv_dictionary |
318 | 318 | |
319 | 319 | CREATE TABLE IF NOT EXISTS oauth2_client_registration ( |
320 | 320 | id uuid NOT NULL CONSTRAINT oauth2_client_registration_pkey PRIMARY KEY, |
321 | + enabled boolean, | |
321 | 322 | created_time bigint NOT NULL, |
322 | 323 | additional_info varchar, |
323 | 324 | domain_name varchar(255), | ... | ... |
... | ... | @@ -86,7 +86,9 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest { |
86 | 86 | public void testGetOAuth2Clients() { |
87 | 87 | String testDomainName = "test_domain"; |
88 | 88 | OAuth2ClientRegistration first = validClientRegistration(testDomainName); |
89 | + first.setEnabled(true); | |
89 | 90 | OAuth2ClientRegistration second = validClientRegistration(testDomainName); |
91 | + second.setEnabled(true); | |
90 | 92 | |
91 | 93 | oAuth2Service.saveOAuth2Params(OAuth2Utils.toOAuth2Params(Collections.singletonList(first))); |
92 | 94 | oAuth2Service.saveOAuth2Params(OAuth2Utils.toOAuth2Params(Collections.singletonList(second))); |
... | ... | @@ -153,7 +155,7 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest { |
153 | 155 | } |
154 | 156 | |
155 | 157 | private OAuth2ClientRegistration validClientRegistration() { |
156 | - return validClientRegistration("domainName"); | |
158 | + return validClientRegistration(UUID.randomUUID().toString()); | |
157 | 159 | } |
158 | 160 | |
159 | 161 | private OAuth2ClientRegistration validClientRegistration(String domainName) { |
... | ... | @@ -166,23 +168,23 @@ public class BaseOAuth2ServiceTest extends AbstractServiceTest { |
166 | 168 | .type(MapperType.CUSTOM) |
167 | 169 | .custom( |
168 | 170 | OAuth2CustomMapperConfig.builder() |
169 | - .url("localhost:8082") | |
171 | + .url("UUID.randomUUID().toString()") | |
170 | 172 | .build() |
171 | 173 | ) |
172 | 174 | .build() |
173 | 175 | ); |
174 | - clientRegistration.setClientId("clientId"); | |
175 | - clientRegistration.setClientSecret("clientSecret"); | |
176 | - clientRegistration.setAuthorizationUri("authorizationUri"); | |
177 | - clientRegistration.setAccessTokenUri("tokenUri"); | |
178 | - clientRegistration.setRedirectUriTemplate("redirectUriTemplate"); | |
179 | - clientRegistration.setScope(Arrays.asList("scope1", "scope2")); | |
180 | - clientRegistration.setUserInfoUri("userInfoUri"); | |
181 | - clientRegistration.setUserNameAttributeName("userNameAttributeName"); | |
182 | - clientRegistration.setJwkSetUri("jwkSetUri"); | |
183 | - clientRegistration.setClientAuthenticationMethod("clientAuthenticationMethod"); | |
184 | - clientRegistration.setLoginButtonLabel("loginButtonLabel"); | |
185 | - clientRegistration.setLoginButtonIcon("loginButtonIcon"); | |
176 | + clientRegistration.setClientId(UUID.randomUUID().toString()); | |
177 | + clientRegistration.setClientSecret(UUID.randomUUID().toString()); | |
178 | + clientRegistration.setAuthorizationUri(UUID.randomUUID().toString()); | |
179 | + clientRegistration.setAccessTokenUri(UUID.randomUUID().toString()); | |
180 | + clientRegistration.setRedirectUriTemplate(UUID.randomUUID().toString()); | |
181 | + clientRegistration.setScope(Arrays.asList(UUID.randomUUID().toString(), UUID.randomUUID().toString())); | |
182 | + clientRegistration.setUserInfoUri(UUID.randomUUID().toString()); | |
183 | + clientRegistration.setUserNameAttributeName(UUID.randomUUID().toString()); | |
184 | + clientRegistration.setJwkSetUri(UUID.randomUUID().toString()); | |
185 | + clientRegistration.setClientAuthenticationMethod(UUID.randomUUID().toString()); | |
186 | + clientRegistration.setLoginButtonLabel(UUID.randomUUID().toString()); | |
187 | + clientRegistration.setLoginButtonIcon(UUID.randomUUID().toString()); | |
186 | 188 | clientRegistration.setAdditionalInfo(mapper.createObjectNode().put(UUID.randomUUID().toString(), UUID.randomUUID().toString())); |
187 | 189 | return clientRegistration; |
188 | 190 | } | ... | ... |