Factorize URI creations
This commit is contained in:
parent
ad60363cbd
commit
54a2f10114
2 changed files with 12 additions and 14 deletions
|
@ -207,15 +207,19 @@ public abstract class AbstractScimService<RMM extends RoleMapperModel, S extends
|
|||
|
||||
protected Meta newMetaLocation(EntityOnRemoteScimId externalId) {
|
||||
Meta meta = new Meta();
|
||||
try {
|
||||
URI uri = new URI("%ss/%s".formatted(type, externalId.asString()));
|
||||
meta.setLocation(uri.toString());
|
||||
} catch (URISyntaxException e) {
|
||||
LOGGER.warn(e);
|
||||
}
|
||||
URI uri = getUri(type, externalId);
|
||||
meta.setLocation(uri.toString());
|
||||
return meta;
|
||||
}
|
||||
|
||||
protected URI getUri(ScimResourceType type, EntityOnRemoteScimId externalId) {
|
||||
try {
|
||||
return new URI("%s/%s".formatted(type.getEndpoint(), externalId.asString()));
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalStateException("should never occur: can not format URI for type %s and id %s".formatted(type, externalId) , e);
|
||||
}
|
||||
}
|
||||
|
||||
protected KeycloakDao getKeycloakDao() {
|
||||
return new KeycloakDao(getKeycloakSession());
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.keycloak.models.UserModel;
|
|||
import sh.libre.scim.jpa.ScimResource;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
@ -94,13 +93,8 @@ public class GroupScimService extends AbstractScimService<GroupModel, Group> {
|
|||
EntityOnRemoteScimId externalIdAsEntityOnRemoteScimId = groupMemberMapping.getExternalIdAsEntityOnRemoteScimId();
|
||||
logger.debugf("found mapping for group member %s as %s", member, externalIdAsEntityOnRemoteScimId);
|
||||
groupMember.setValue(externalIdAsEntityOnRemoteScimId.asString());
|
||||
try {
|
||||
String refString = String.format("Users/%s", externalIdAsEntityOnRemoteScimId.asString());
|
||||
URI ref = new URI(refString);
|
||||
groupMember.setRef(ref.toString());
|
||||
} catch (URISyntaxException e) {
|
||||
logger.warnf("bad ref uri for member " + member);
|
||||
}
|
||||
URI ref = getUri(ScimResourceType.USER, externalIdAsEntityOnRemoteScimId);
|
||||
groupMember.setRef(ref.toString());
|
||||
group.addMember(groupMember);
|
||||
} else {
|
||||
logger.warnf("member %s not found for group %s", member, groupModel.getId());
|
||||
|
|
Loading…
Reference in a new issue