-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* AAE-19797 add user types to UserSearchParams * AAE-19797 added UserType enum * AAE-19797 KeycloakManagementService implementation to retrieve service accounts * AAE-19797 Param validation, exception handling and controller IT * AAE-19797 fix sonar issues * AAE-19797 fix test * AAE-19797 suppress assert warning
- Loading branch information
Showing
9 changed files
with
250 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
.../test/java/org/activiti/cloud/services/identity/keycloak/KeycloakManagementServiceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2017-2020 Alfresco Software, Ltd. | ||
* | ||
* Licensed 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.activiti.cloud.services.identity.keycloak; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import org.activiti.cloud.identity.UserSearchParams; | ||
import org.activiti.cloud.identity.UserTypeSearchParam; | ||
import org.activiti.cloud.identity.model.User; | ||
import org.activiti.cloud.services.test.containers.KeycloakContainerApplicationInitializer; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
@SpringBootTest( | ||
classes = { KeycloakClientApplication.class }, | ||
properties = { | ||
"keycloak.realm=activiti", | ||
"keycloak.use-resource-role-mappings=false", | ||
"identity.client.cache.cacheExpireAfterWrite=PT5s", | ||
} | ||
) | ||
@ContextConfiguration(initializers = { KeycloakContainerApplicationInitializer.class }) | ||
class KeycloakManagementServiceIT { | ||
|
||
@Autowired | ||
private KeycloakManagementService keycloakManagementService; | ||
|
||
@Test | ||
void should_Not_RetrieveServiceAccounts_WhenUserTypeSearchParamIsInteractive() { | ||
UserSearchParams searchParams = new UserSearchParams(); | ||
searchParams.setSearch(""); | ||
searchParams.setType(UserTypeSearchParam.INTERACTIVE); | ||
|
||
List<User> users = keycloakManagementService.findUsers(searchParams); | ||
|
||
assertThat(users).isNotEmpty(); | ||
assertThat(users).noneMatch(user -> user.getUsername().startsWith("service-account")); | ||
} | ||
|
||
@Test | ||
void should_Not_RetrieveServiceAccounts_WhenUserTypeSearchParamIsNull() { | ||
UserSearchParams searchParams = new UserSearchParams(); | ||
searchParams.setSearch(""); | ||
|
||
assertThat(searchParams.getType()).isNull(); | ||
|
||
List<User> users = keycloakManagementService.findUsers(searchParams); | ||
|
||
assertThat(users).isNotEmpty(); | ||
assertThat(users).noneMatch(user -> user.getUsername().startsWith("service-account")); | ||
} | ||
|
||
@Test | ||
void should_RetrieveUsersAndServiceAccounts_WhenUserTypeSearchParamIsAll() { | ||
UserSearchParams searchParams = new UserSearchParams(); | ||
searchParams.setSearch(""); | ||
searchParams.setType(UserTypeSearchParam.INTERACTIVE); | ||
|
||
List<User> justUsers = keycloakManagementService.findUsers(searchParams); | ||
|
||
searchParams.setType(UserTypeSearchParam.ALL); | ||
List<User> usersAndServiceAccounts = keycloakManagementService.findUsers(searchParams); | ||
|
||
assertThat(usersAndServiceAccounts.size()).isGreaterThan(justUsers.size()); | ||
assertThat(usersAndServiceAccounts) | ||
.allMatch(element -> element.getUsername().startsWith("service-account") ^ justUsers.contains(element)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...rvices-common-security/src/main/java/org/activiti/cloud/identity/UserTypeSearchParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2017-2020 Alfresco Software, Ltd. | ||
* | ||
* Licensed 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.activiti.cloud.identity; | ||
|
||
import java.util.Arrays; | ||
import org.activiti.cloud.identity.exceptions.IdentityInvalidUserTypeException; | ||
|
||
public enum UserTypeSearchParam { | ||
ALL, | ||
INTERACTIVE; | ||
|
||
public static UserTypeSearchParam convertFromStringOrThrow(String stringValue) { | ||
return Arrays | ||
.stream(UserTypeSearchParam.values()) | ||
.filter(ut -> ut.name().equals(stringValue)) | ||
.findAny() | ||
.orElseThrow(() -> new IdentityInvalidUserTypeException(stringValue)); | ||
} | ||
} |
Oops, something went wrong.