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) {
|
protected Meta newMetaLocation(EntityOnRemoteScimId externalId) {
|
||||||
Meta meta = new Meta();
|
Meta meta = new Meta();
|
||||||
try {
|
URI uri = getUri(type, externalId);
|
||||||
URI uri = new URI("%ss/%s".formatted(type, externalId.asString()));
|
meta.setLocation(uri.toString());
|
||||||
meta.setLocation(uri.toString());
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
LOGGER.warn(e);
|
|
||||||
}
|
|
||||||
return meta;
|
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() {
|
protected KeycloakDao getKeycloakDao() {
|
||||||
return new KeycloakDao(getKeycloakSession());
|
return new KeycloakDao(getKeycloakSession());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.keycloak.models.UserModel;
|
||||||
import sh.libre.scim.jpa.ScimResource;
|
import sh.libre.scim.jpa.ScimResource;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -94,13 +93,8 @@ public class GroupScimService extends AbstractScimService<GroupModel, Group> {
|
||||||
EntityOnRemoteScimId externalIdAsEntityOnRemoteScimId = groupMemberMapping.getExternalIdAsEntityOnRemoteScimId();
|
EntityOnRemoteScimId externalIdAsEntityOnRemoteScimId = groupMemberMapping.getExternalIdAsEntityOnRemoteScimId();
|
||||||
logger.debugf("found mapping for group member %s as %s", member, externalIdAsEntityOnRemoteScimId);
|
logger.debugf("found mapping for group member %s as %s", member, externalIdAsEntityOnRemoteScimId);
|
||||||
groupMember.setValue(externalIdAsEntityOnRemoteScimId.asString());
|
groupMember.setValue(externalIdAsEntityOnRemoteScimId.asString());
|
||||||
try {
|
URI ref = getUri(ScimResourceType.USER, externalIdAsEntityOnRemoteScimId);
|
||||||
String refString = String.format("Users/%s", externalIdAsEntityOnRemoteScimId.asString());
|
groupMember.setRef(ref.toString());
|
||||||
URI ref = new URI(refString);
|
|
||||||
groupMember.setRef(ref.toString());
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
logger.warnf("bad ref uri for member " + member);
|
|
||||||
}
|
|
||||||
group.addMember(groupMember);
|
group.addMember(groupMember);
|
||||||
} else {
|
} else {
|
||||||
logger.warnf("member %s not found for group %s", member, groupModel.getId());
|
logger.warnf("member %s not found for group %s", member, groupModel.getId());
|
||||||
|
|
Loading…
Reference in a new issue