Remove methods for SSO
MODIFY
src/app/components/admin/create-developer/create-developer.component.spec.ts
src/app/components/admin/create-developer/create-developer.component.spec.ts
@@ -76,7 +76,6 @@ describe('CreateDeveloperComponent', () => {
const router = jasmine.createSpy('router');
const developerDataCache = jasmine.createSpyObj('developerDataCache', ['load', 'developers']);
- developerDataCache.developers = [{id: 'alice', name: 'Alice', clients: [{clientId: 'Support-Customer', organizationId: 'Production'}]}];
const toasterService = jasmine.createSpyObj('toasterService', ['pop']);
const loadingSpinnerService = jasmine.createSpyObj('loadingSpinnerService', ['startWaiting', 'stopWaiting']);
@@ -113,7 +112,14 @@ describe('CreateDeveloperComponent', () => {
expect(component).toBeTruthy();
});
+ it('checkDeveloperNotExistsListIsUndefined', () => {
+ developerDataCache.developers = undefined;
+ expect(component.checkDeveloperNotExists('admin')).toBeTruthy();
+ });
+
it('checkDeveloperNotExists', () => {
+ developerDataCache.developers = [{id: 'alice', name: 'Alice', clients: [{clientId: 'Support-Customer', organizationId: 'Production'}]}];
+
expect(developerDataCache.developers).not.toBe(null);
expect(developerDataCache.developers).not.toBe(undefined);
// expects true for undefined input to hide the notification in the UI
@@ -122,6 +128,11 @@ describe('CreateDeveloperComponent', () => {
expect(component.checkDeveloperNotExists('Bob')).toBeTruthy();
});
+ it('checkUserExistsInKeycloakListIsUndefined', () => {
+ component.keycloakUsers = undefined;
+ expect(component.checkUserExistsInKeycloak('admin')).toBeFalsy();
+ });
+
it('checkUserExistsInKeycloak', () => {
component.keycloakUsers = keycloakUsers;
expect(component.checkUserExistsInKeycloak(undefined)).toBeFalsy();

MODIFY
src/app/components/admin/create-developer/create-developer.component.ts
src/app/components/admin/create-developer/create-developer.component.ts
@@ -86,7 +86,7 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
developerToCreate.clients.push(new ClientMappingImpl(client.clientId, client.organizationId));
});
- this.adminService.createNewDeveloper(developerToCreate, keycloakUser.id)
+ this.adminService.createNewDeveloper(developerToCreate)
.subscribe(createdDeveloper => {
this.userFormGroup.reset();
this.clientMapping.reset();
@@ -114,9 +114,8 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
* @param username the developer username
*/
checkDeveloperNotExists(username: string) {
- if (username && username.length !== 0) {
- return this.developerDataCache.developers
- && this.developerDataCache.developers.find((d) => d.id.toLowerCase() === username.toLowerCase()) === undefined;
+ if (this.developerDataCache.developers && username && username.length !== 0) {
+ return this.developerDataCache.developers.find((d) => d.id.toLowerCase() === username.toLowerCase()) === undefined;
} else {
return true;
}
@@ -127,7 +126,11 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
* @param username the developer username
*/
checkUserExistsInKeycloak(username: string) {
+ if (this.keycloakUsers && username && username.length !== 0) {
return this.keycloakUsers.find((u) => u.username.toLowerCase() === username) !== undefined;
+ } else {
+ return false;
+ }
}
/**
@@ -135,7 +138,9 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
* @param usernameInput the entered username
*/
private filterKeycloakUser(usernameInput: string) {
+ if (usernameInput && usernameInput.length !== 0) {
this.filteredKeycloakUsers = this.keycloakUsers
.filter((u) => this.checkDeveloperNotExists(u.username) && u.username.toLowerCase().includes(usernameInput.toLowerCase()));
}
}
+}

MODIFY
src/app/components/admin/services/admin.service.ts
src/app/components/admin/services/admin.service.ts
@@ -48,28 +48,12 @@ export class AdminService {
/**
* Create new developer
* @param developer the developer to create
- * @param keycloakUserId the id of the keycloak user
*/
- public createNewDeveloper(developer: Developer, keycloakUserId: string) {
+ public createNewDeveloper(developer: Developer): Observable<Developer> {
// observer insert developer to API-Mgmt
// response has developer object
const url = this.apiMgmtUiRestUrl + '/developers';
- const insertToApiMgmt = this.http.post(url, developer) as Observable<Developer>;
- // observer to add keycloak user to developer portal group
- const addDevPortalGroupToUser = this.keycloak.addDevPortalGroupToUser(keycloakUserId);
-
- // 1. insert developer to API-Mgmt
- return insertToApiMgmt.pipe(mergeMap(insertedDeveloper => {
- // 2. add devPortal group and add client role to keycloak user
- return addDevPortalGroupToUser
- .pipe(map(() => insertedDeveloper));
- }), catchError((err, caught) => {
- // rollback keycloak user if developer cannot created at API-Mgmt
- // we just remove the group mapping
- // TODO REMOVE THIS COMFORT FEATURE IN FUTURE
- this.keycloak.removeDevPortalGroupFromUser(keycloakUserId).subscribe();
- throw err;
- }));
+ return this.http.post(url, developer) as Observable<Developer>;
}
/**

MODIFY
src/app/components/admin/services/keycloak-interaction.service.ts
src/app/components/admin/services/keycloak-interaction.service.ts
@@ -12,8 +12,6 @@ export class KeycloakInteractionService {
private kcAdminClient: KcAdminClient;
- private keycloakGroupUsers = 'API-Mgmt-Devportal-Users';
-
/**
* Constructor of Keycloak Interaction Service
* @param keycloak the keycloak service
@@ -39,14 +37,6 @@ export class KeycloakInteractionService {
});
}
- /**
- * Get API-Mgmt-Devportal-Users Group
- */
- private getDevPortalUserGroup() {
- return from(this.kcAdminClient.groups.find({search: this.keycloakGroupUsers}))
- .pipe(map(groups => groups.length > 0 ? groups[0] : undefined));
- }
-
/**
* Get all keycloak users
* Max value: https://www.keycloak.org/docs-api/9.0/rest-api/index.html#_users_resource
@@ -54,40 +44,4 @@ export class KeycloakInteractionService {
public getAllUsers() {
return from(this.kcAdminClient.users.find({max: (Math.pow(2, 31) - 1)}));
}
-
- /**
- * Remove Group Mapping from user
- * @param userUUID user UUID
- * @param groupUUID group UUID
- */
- private removeGroupMapping(userUUID: string, groupUUID: string) {
- return from(this.kcAdminClient.users.delFromGroup({
- id: userUUID,
- groupId: groupUUID
- }));
- }
-
- /**
- * Add User to API-Mgmt-Devportal-Users group
- * @param userId the user id
- */
- public addDevPortalGroupToUser(userId: string) {
- return this.getDevPortalUserGroup().pipe(mergeMap(devPortalUserGroup => this.kcAdminClient.users.addToGroup({
- id: userId,
- groupId: devPortalUserGroup.id
- })));
- }
-
- // TODO REMOVE
- /**
- * Remove User from API-Mgmt-Devportal-Users group
- * @param userId the user id
- */
- public removeDevPortalGroupFromUser(userId: string) {
- return this.getDevPortalUserGroup()
- .pipe(mergeMap(devPortalUserGroup => this.removeGroupMapping(userId, devPortalUserGroup.id)))
- // removeGroupMapping returns GroupRepresentation which is not needed
- // and should be skipped because of typing errors of method this.deleteUser:
- .pipe(map((groups) => {}));
- }
}

GW-416: Remove methods for SSO