Update invitation changes based on review and revert deleted test from OrganizationMembertest
Signed-off-by: Alice W <105500542+alice-wondered@users.noreply.github.com>
This commit is contained in:
parent
7553679116
commit
d1549a021e
6 changed files with 101 additions and 5 deletions
|
@ -18,7 +18,6 @@
|
||||||
package org.keycloak.authentication;
|
package org.keycloak.authentication;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
import org.keycloak.authentication.actiontoken.inviteorg.InviteOrgActionToken;
|
|
||||||
import org.keycloak.http.HttpRequest;
|
import org.keycloak.http.HttpRequest;
|
||||||
import org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator;
|
import org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator;
|
||||||
import org.keycloak.authentication.authenticators.client.ClientAuthUtil;
|
import org.keycloak.authentication.authenticators.client.ClientAuthUtil;
|
||||||
|
@ -104,7 +103,6 @@ public class AuthenticationProcessor {
|
||||||
protected String flowPath;
|
protected String flowPath;
|
||||||
|
|
||||||
|
|
||||||
protected String orgToken;
|
|
||||||
protected boolean browserFlow;
|
protected boolean browserFlow;
|
||||||
protected BruteForceProtector protector;
|
protected BruteForceProtector protector;
|
||||||
protected Runnable afterResetListener;
|
protected Runnable afterResetListener;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2017 Red Hat, Inc. and/or its affiliates
|
* Copyright 2024 Red Hat, Inc. and/or its affiliates
|
||||||
* and other contributors as indicated by the @author tags.
|
* and other contributors as indicated by the @author tags.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2017 Red Hat, Inc. and/or its affiliates
|
* Copyright 2024 Red Hat, Inc. and/or its affiliates
|
||||||
* and other contributors as indicated by the @author tags.
|
* and other contributors as indicated by the @author tags.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
|
@ -60,7 +60,6 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
|
||||||
protected FreeMarkerProvider freeMarker;
|
protected FreeMarkerProvider freeMarker;
|
||||||
protected RealmModel realm;
|
protected RealmModel realm;
|
||||||
protected UserModel user;
|
protected UserModel user;
|
||||||
protected String userEmail;
|
|
||||||
protected final Map<String, Object> attributes = new HashMap<>();
|
protected final Map<String, Object> attributes = new HashMap<>();
|
||||||
|
|
||||||
public FreeMarkerEmailTemplateProvider(KeycloakSession session) {
|
public FreeMarkerEmailTemplateProvider(KeycloakSession session) {
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2024 Red Hat, Inc. and/or its affiliates
|
||||||
|
* and other contributors as indicated by the @author tags.
|
||||||
|
*
|
||||||
|
* 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.keycloak.organization.admin.resource;
|
package org.keycloak.organization.admin.resource;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -33,6 +33,7 @@ import static org.keycloak.models.OrganizationModel.ORGANIZATION_ATTRIBUTE;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jakarta.ws.rs.BadRequestException;
|
import jakarta.ws.rs.BadRequestException;
|
||||||
import jakarta.ws.rs.NotFoundException;
|
import jakarta.ws.rs.NotFoundException;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
@ -295,4 +296,86 @@ public class OrganizationMemberTest extends AbstractOrganizationTest {
|
||||||
assertFalse(testRealm().groups().groups().stream().anyMatch(group -> group.getName().startsWith("kc.org.")));
|
assertFalse(testRealm().groups().groups().stream().anyMatch(group -> group.getName().startsWith("kc.org.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchMembers() {
|
||||||
|
|
||||||
|
// create test users, ordered by username (e-mail).
|
||||||
|
OrganizationResource organization = testRealm().organizations().get(createOrganization().getId());
|
||||||
|
List<UserRepresentation> expected = new ArrayList<>();
|
||||||
|
expected.add(addMember(organization, "batwoman@neworg.org", "Katherine", "Kane"));
|
||||||
|
expected.add(addMember(organization, "brucewayne@neworg.org", "Bruce", "Wayne"));
|
||||||
|
expected.add(addMember(organization, "harveydent@neworg.org", "Harvey", "Dent"));
|
||||||
|
expected.add(addMember(organization, "marthaw@neworg.org", "Martha", "Wayne"));
|
||||||
|
expected.add(addMember(organization, "thejoker@neworg.org", "Jack", "White"));
|
||||||
|
|
||||||
|
// exact search - username/e-mail, first name, last name.
|
||||||
|
List<UserRepresentation> existing = organization.members().search("brucewayne@neworg.org", true, null, null);
|
||||||
|
assertThat(existing, hasSize(1));
|
||||||
|
assertThat(existing.get(0).getUsername(), is(equalTo("brucewayne@neworg.org")));
|
||||||
|
assertThat(existing.get(0).getEmail(), is(equalTo("brucewayne@neworg.org")));
|
||||||
|
assertThat(existing.get(0).getFirstName(), is(equalTo("Bruce")));
|
||||||
|
assertThat(existing.get(0).getLastName(), is(equalTo("Wayne")));
|
||||||
|
|
||||||
|
existing = organization.members().search("Harvey", true, null, null);
|
||||||
|
assertThat(existing, hasSize(1));
|
||||||
|
assertThat(existing.get(0).getUsername(), is(equalTo("harveydent@neworg.org")));
|
||||||
|
assertThat(existing.get(0).getEmail(), is(equalTo("harveydent@neworg.org")));
|
||||||
|
assertThat(existing.get(0).getFirstName(), is(equalTo("Harvey")));
|
||||||
|
assertThat(existing.get(0).getLastName(), is(equalTo("Dent")));
|
||||||
|
|
||||||
|
existing = organization.members().search("Wayne", true, null, null);
|
||||||
|
assertThat(existing, hasSize(2));
|
||||||
|
assertThat(existing.get(0).getUsername(), is(equalTo("brucewayne@neworg.org")));
|
||||||
|
assertThat(existing.get(1).getUsername(), is(equalTo("marthaw@neworg.org")));
|
||||||
|
|
||||||
|
existing = organization.members().search("Gordon", true, null, null);
|
||||||
|
assertThat(existing, is(empty()));
|
||||||
|
|
||||||
|
// partial search - partial e-mail should match all users.
|
||||||
|
existing = organization.members().search("neworg", false, null, null);
|
||||||
|
assertThat(existing, hasSize(5));
|
||||||
|
for (int i = 0; i < 5; i++) { // returned entries should also be ordered.
|
||||||
|
assertThat(expected.get(i).getId(), is(equalTo(expected.get(i).getId())));
|
||||||
|
assertThat(expected.get(i).getUsername(), is(equalTo(expected.get(i).getUsername())));
|
||||||
|
assertThat(expected.get(i).getEmail(), is(equalTo(expected.get(i).getEmail())));
|
||||||
|
assertThat(expected.get(i).getFirstName(), is(equalTo(expected.get(i).getFirstName())));
|
||||||
|
assertThat(expected.get(i).getLastName(), is(equalTo(expected.get(i).getLastName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
// partial search using 'th' search string - should match 'Katherine' by name, 'Jack' by username/e-mail
|
||||||
|
// and 'Martha' either by username or first name.
|
||||||
|
existing = organization.members().search("th", false, null, null);
|
||||||
|
assertThat(existing, hasSize(3));
|
||||||
|
assertThat(existing.get(0).getUsername(), is(equalTo("batwoman@neworg.org")));
|
||||||
|
assertThat(existing.get(0).getFirstName(), is(equalTo("Katherine")));
|
||||||
|
assertThat(existing.get(1).getUsername(), is(equalTo("marthaw@neworg.org")));
|
||||||
|
assertThat(existing.get(1).getFirstName(), is(equalTo("Martha")));
|
||||||
|
assertThat(existing.get(2).getUsername(), is(equalTo("thejoker@neworg.org")));
|
||||||
|
assertThat(existing.get(2).getFirstName(), is(equalTo("Jack")));
|
||||||
|
|
||||||
|
// partial search using 'way' - should match both 'Bruce' (either by username or last name) and 'Martha' by last name.
|
||||||
|
existing = organization.members().search("way", false, null, null);
|
||||||
|
assertThat(existing, hasSize(2));
|
||||||
|
assertThat(existing.get(0).getUsername(), is(equalTo("brucewayne@neworg.org")));
|
||||||
|
assertThat(existing.get(0).getFirstName(), is(equalTo("Bruce")));
|
||||||
|
assertThat(existing.get(1).getUsername(), is(equalTo("marthaw@neworg.org")));
|
||||||
|
assertThat(existing.get(1).getFirstName(), is(equalTo("Martha")));
|
||||||
|
|
||||||
|
// partial search using with no match - e.g. 'nonexistent'.
|
||||||
|
existing = organization.members().search("nonexistent", false, null, null);
|
||||||
|
assertThat(existing, is(empty()));
|
||||||
|
|
||||||
|
// paginated search - try to fetch 3 users per page.
|
||||||
|
existing = organization.members().search("", false, 0, 3);
|
||||||
|
assertThat(existing, hasSize(3));
|
||||||
|
assertThat(existing.get(0).getUsername(), is(equalTo("batwoman@neworg.org")));
|
||||||
|
assertThat(existing.get(1).getUsername(), is(equalTo("brucewayne@neworg.org")));
|
||||||
|
assertThat(existing.get(2).getUsername(), is(equalTo("harveydent@neworg.org")));
|
||||||
|
|
||||||
|
existing = organization.members().search("", false, 3, 3);
|
||||||
|
assertThat(existing, hasSize(2));
|
||||||
|
assertThat(existing.get(0).getUsername(), is(equalTo("marthaw@neworg.org")));
|
||||||
|
assertThat(existing.get(1).getUsername(), is(equalTo("thejoker@neworg.org")));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue