claim support phase 2
This commit is contained in:
parent
8586a8d1a5
commit
2fb97f058b
9 changed files with 188 additions and 35 deletions
|
@ -0,0 +1,64 @@
|
|||
package org.keycloak.representations.idm;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class ProtocolClaimMappingRepresentation {
|
||||
protected String id;
|
||||
protected String protocolClaim;
|
||||
protected String protocol;
|
||||
protected String source;
|
||||
protected String sourceAttribute;
|
||||
protected boolean appliedByDefault;
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getProtocolClaim() {
|
||||
return protocolClaim;
|
||||
}
|
||||
|
||||
public void setProtocolClaim(String protocolClaim) {
|
||||
this.protocolClaim = protocolClaim;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public String getSourceAttribute() {
|
||||
return sourceAttribute;
|
||||
}
|
||||
|
||||
public void setSourceAttribute(String sourceAttribute) {
|
||||
this.sourceAttribute = sourceAttribute;
|
||||
}
|
||||
|
||||
public boolean isAppliedByDefault() {
|
||||
return appliedByDefault;
|
||||
}
|
||||
|
||||
public void setAppliedByDefault(boolean appliedByDefault) {
|
||||
this.appliedByDefault = appliedByDefault;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
}
|
|
@ -64,6 +64,7 @@ public class RealmRepresentation {
|
|||
protected List<String> eventsListeners;
|
||||
private List<IdentityProviderRepresentation> identityProviders;
|
||||
private List<ClaimTypeRepresentation> claimTypes;
|
||||
private List<ProtocolClaimMappingRepresentation> protocolClaimMappings;
|
||||
private Boolean identityFederationEnabled;
|
||||
|
||||
public String getId() {
|
||||
|
@ -490,4 +491,12 @@ public class RealmRepresentation {
|
|||
public void setClaimTypes(List<ClaimTypeRepresentation> claimTypes) {
|
||||
this.claimTypes = claimTypes;
|
||||
}
|
||||
|
||||
public List<ProtocolClaimMappingRepresentation> getProtocolClaimMappings() {
|
||||
return protocolClaimMappings;
|
||||
}
|
||||
|
||||
public void setProtocolClaimMappings(List<ProtocolClaimMappingRepresentation> protocolClaimMappings) {
|
||||
this.protocolClaimMappings = protocolClaimMappings;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class ClaimTypeModel {
|
|||
STRING
|
||||
}
|
||||
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final boolean builtIn;
|
||||
private final ValueType type;
|
||||
private String id;
|
||||
private String name;
|
||||
private boolean builtIn;
|
||||
private ValueType type;
|
||||
|
||||
public ClaimTypeModel(ClaimTypeModel copy) {
|
||||
this(copy.getId(), copy.getName(), copy.isBuiltIn(), copy.getType());
|
||||
|
@ -28,6 +28,9 @@ public class ClaimTypeModel {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public ClaimTypeModel() {
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -44,6 +47,22 @@ public class ClaimTypeModel {
|
|||
return type;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setBuiltIn(boolean builtIn) {
|
||||
this.builtIn = builtIn;
|
||||
}
|
||||
|
||||
public void setType(ValueType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -225,14 +225,13 @@ public interface RealmModel extends RoleContainerModel {
|
|||
boolean isIdentityFederationEnabled();
|
||||
|
||||
Set<ClaimTypeModel> getClaimTypes();
|
||||
ClaimTypeModel addClaimType(String name, ClaimTypeModel.ValueType type, boolean builtIn);
|
||||
ClaimTypeModel addClaimType(ClaimTypeModel model);
|
||||
void removeClaimType(ClaimTypeModel claimType);
|
||||
ClaimTypeModel getClaimType(String name);
|
||||
void updateClaimType(ClaimTypeModel claimType);
|
||||
|
||||
Set<ProtocolClaimMappingModel> getProtocolClaimMappings();
|
||||
ProtocolClaimMappingModel addProtocolClaimMapping(String protocolClaim, String protocol, String sourceAttribute,
|
||||
ProtocolClaimMappingModel.Source source, boolean appliedByDefault);
|
||||
ProtocolClaimMappingModel addProtocolClaimMapping(ProtocolClaimMappingModel model);
|
||||
void removeProtocolClaimMapping(ProtocolClaimMappingModel mapping);
|
||||
void updateProtocolClaimMapping(ProtocolClaimMappingModel mapping);
|
||||
public ProtocolClaimMappingModel getProtocolClaimMappingById(String id);
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.keycloak.models.ClientSessionModel;
|
|||
import org.keycloak.models.FederatedIdentityModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.ProtocolClaimMappingModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
|
@ -22,6 +23,7 @@ import org.keycloak.representations.idm.CredentialRepresentation;
|
|||
import org.keycloak.representations.idm.FederatedIdentityRepresentation;
|
||||
import org.keycloak.representations.idm.IdentityProviderRepresentation;
|
||||
import org.keycloak.representations.idm.OAuthClientRepresentation;
|
||||
import org.keycloak.representations.idm.ProtocolClaimMappingRepresentation;
|
||||
import org.keycloak.representations.idm.RealmEventsConfigRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.RoleRepresentation;
|
||||
|
@ -155,6 +157,10 @@ public class ModelToRepresentation {
|
|||
rep.getClaimTypes().add(toRepresentation(claimType));
|
||||
}
|
||||
|
||||
for (ProtocolClaimMappingModel mapping : realm.getProtocolClaimMappings()) {
|
||||
rep.getProtocolClaimMappings().add(toRepresentation(mapping));
|
||||
}
|
||||
|
||||
return rep;
|
||||
}
|
||||
|
||||
|
@ -320,6 +326,17 @@ public class ModelToRepresentation {
|
|||
return providerRep;
|
||||
}
|
||||
|
||||
public static ProtocolClaimMappingRepresentation toRepresentation(ProtocolClaimMappingModel model) {
|
||||
ProtocolClaimMappingRepresentation rep = new ProtocolClaimMappingRepresentation();
|
||||
rep.setId(model.getId());
|
||||
rep.setProtocol(model.getProtocol());
|
||||
rep.setProtocolClaim(model.getProtocolClaim());
|
||||
rep.setSourceAttribute(model.getSourceAttribute());
|
||||
rep.setSource(model.getSource().name());
|
||||
rep.setAppliedByDefault(model.isAppliedByDefault());
|
||||
return rep;
|
||||
}
|
||||
|
||||
public static ClaimTypeRepresentation toRepresentation(ClaimTypeModel claimType) {
|
||||
ClaimTypeRepresentation rep = new ClaimTypeRepresentation();
|
||||
rep.setId(claimType.getId());
|
||||
|
|
|
@ -6,12 +6,14 @@ import org.keycloak.enums.SslRequired;
|
|||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.BrowserSecurityHeaders;
|
||||
import org.keycloak.models.ClaimMask;
|
||||
import org.keycloak.models.ClaimTypeModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.FederatedIdentityModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.ProtocolClaimMappingModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
|
@ -20,10 +22,12 @@ import org.keycloak.models.UserFederationProviderModel;
|
|||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.representations.idm.ApplicationRepresentation;
|
||||
import org.keycloak.representations.idm.ClaimRepresentation;
|
||||
import org.keycloak.representations.idm.ClaimTypeRepresentation;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.FederatedIdentityRepresentation;
|
||||
import org.keycloak.representations.idm.IdentityProviderRepresentation;
|
||||
import org.keycloak.representations.idm.OAuthClientRepresentation;
|
||||
import org.keycloak.representations.idm.ProtocolClaimMappingRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.RoleRepresentation;
|
||||
import org.keycloak.representations.idm.ScopeMappingRepresentation;
|
||||
|
@ -113,6 +117,8 @@ public class RepresentationToModel {
|
|||
if (rep.getPasswordPolicy() != null) newRealm.setPasswordPolicy(new PasswordPolicy(rep.getPasswordPolicy()));
|
||||
|
||||
importIdentityProviders(rep, newRealm);
|
||||
importClaimTypes(rep, newRealm);
|
||||
importProtocolClaimMappings(rep, newRealm);
|
||||
|
||||
if (rep.getApplications() != null) {
|
||||
Map<String, ApplicationModel> appMap = createApplications(rep, newRealm);
|
||||
|
@ -749,6 +755,21 @@ public class RepresentationToModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
private static void importClaimTypes(RealmRepresentation rep, RealmModel newRealm) {
|
||||
if (rep.getClaimTypes() != null) {
|
||||
for (ClaimTypeRepresentation representation : rep.getClaimTypes()) {
|
||||
newRealm.addClaimType(toModel(representation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void importProtocolClaimMappings(RealmRepresentation rep, RealmModel newRealm) {
|
||||
if (rep.getProtocolClaimMappings() != null) {
|
||||
for (ProtocolClaimMappingRepresentation representation : rep.getProtocolClaimMappings()) {
|
||||
newRealm.addProtocolClaimMapping(toModel(representation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IdentityProviderModel toModel(IdentityProviderRepresentation representation) {
|
||||
IdentityProviderModel identityProviderModel = new IdentityProviderModel();
|
||||
|
@ -765,4 +786,24 @@ public class RepresentationToModel {
|
|||
|
||||
return identityProviderModel;
|
||||
}
|
||||
|
||||
public static ClaimTypeModel toModel(ClaimTypeRepresentation rep) {
|
||||
ClaimTypeModel model = new ClaimTypeModel();
|
||||
model.setId(rep.getId());
|
||||
model.setType(ClaimTypeModel.ValueType.valueOf(rep.getType()));
|
||||
model.setBuiltIn(rep.isBuiltIn());
|
||||
model.setName(rep.getName());
|
||||
return model;
|
||||
}
|
||||
|
||||
public static ProtocolClaimMappingModel toModel(ProtocolClaimMappingRepresentation rep) {
|
||||
ProtocolClaimMappingModel model = new ProtocolClaimMappingModel();
|
||||
model.setId(rep.getId());
|
||||
model.setAppliedByDefault(rep.isAppliedByDefault());
|
||||
model.setSource(ProtocolClaimMappingModel.Source.valueOf(rep.getSource()));
|
||||
model.setSourceAttribute(rep.getSourceAttribute());
|
||||
model.setProtocol(rep.getProtocol());
|
||||
model.setProtocolClaim(rep.getProtocolClaim());
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -857,9 +857,9 @@ public class RealmAdapter implements RealmModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ClaimTypeModel addClaimType(String name, ClaimTypeModel.ValueType type, boolean builtIn) {
|
||||
public ClaimTypeModel addClaimType(ClaimTypeModel claimType) {
|
||||
getDelegateForUpdate();
|
||||
return updated.addClaimType(name, type, builtIn);
|
||||
return updated.addClaimType(claimType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -892,9 +892,9 @@ public class RealmAdapter implements RealmModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProtocolClaimMappingModel addProtocolClaimMapping(String protocolClaim, String protocol, String sourceAttribute, ProtocolClaimMappingModel.Source source, boolean appliedByDefault) {
|
||||
public ProtocolClaimMappingModel addProtocolClaimMapping(ProtocolClaimMappingModel model) {
|
||||
getDelegateForUpdate();
|
||||
return updated.addProtocolClaimMapping(protocolClaim, protocol, sourceAttribute, source, appliedByDefault);
|
||||
return updated.addProtocolClaimMapping(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1206,15 +1206,16 @@ public class RealmAdapter implements RealmModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ClaimTypeModel addClaimType(String name, ClaimTypeModel.ValueType type, boolean builtIn) {
|
||||
public ClaimTypeModel addClaimType(ClaimTypeModel model) {
|
||||
String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId();
|
||||
ClaimTypeEntity claimEntity = new ClaimTypeEntity();
|
||||
claimEntity.setId(KeycloakModelUtils.generateId());
|
||||
claimEntity.setType(type.name());
|
||||
claimEntity.setBuiltIn(builtIn);
|
||||
claimEntity.setId(id);
|
||||
claimEntity.setType(model.getType().name());
|
||||
claimEntity.setBuiltIn(model.isBuiltIn());
|
||||
claimEntity.setRealm(realm);
|
||||
em.persist(claimEntity);
|
||||
realm.getClaimTypes().add(claimEntity);
|
||||
return new ClaimTypeModel(claimEntity.getId(), name, builtIn, type);
|
||||
return new ClaimTypeModel(claimEntity.getId(), model.getName(), model.isBuiltIn(), model.getType());
|
||||
}
|
||||
|
||||
protected ClaimTypeEntity getClaimTypeEntity(ClaimTypeModel claim) {
|
||||
|
@ -1272,14 +1273,15 @@ public class RealmAdapter implements RealmModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProtocolClaimMappingModel addProtocolClaimMapping(String protocolClaim, String protocol, String sourceAttribute, ProtocolClaimMappingModel.Source source, boolean appliedByDefault) {
|
||||
public ProtocolClaimMappingModel addProtocolClaimMapping(ProtocolClaimMappingModel model) {
|
||||
String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId();
|
||||
ProtocolClaimMappingEntity entity = new ProtocolClaimMappingEntity();
|
||||
entity.setId(KeycloakModelUtils.generateId());
|
||||
entity.setSourceAttribute(sourceAttribute);
|
||||
entity.setProtocol(protocol);
|
||||
entity.setProtocolClaim(protocolClaim);
|
||||
entity.setSource(source.name());
|
||||
entity.setAppliedByDefault(appliedByDefault);
|
||||
entity.setId(id);
|
||||
entity.setSourceAttribute(model.getSourceAttribute());
|
||||
entity.setProtocol(model.getProtocol());
|
||||
entity.setProtocolClaim(model.getProtocolClaim());
|
||||
entity.setSource(model.getSource().name());
|
||||
entity.setAppliedByDefault(model.isAppliedByDefault());
|
||||
entity.setRealm(realm);
|
||||
em.persist(entity);
|
||||
ProtocolClaimMappingModel mapping = new ProtocolClaimMappingModel();
|
||||
|
|
|
@ -802,14 +802,15 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProtocolClaimMappingModel addProtocolClaimMapping(String protocolClaim, String protocol, String sourceAttribute, ProtocolClaimMappingModel.Source source, boolean appliedByDefault) {
|
||||
public ProtocolClaimMappingModel addProtocolClaimMapping(ProtocolClaimMappingModel model) {
|
||||
ProtocolClaimMappingEntity entity = new ProtocolClaimMappingEntity();
|
||||
entity.setId(KeycloakModelUtils.generateId());
|
||||
entity.setSourceAttribute(sourceAttribute);
|
||||
entity.setProtocol(protocol);
|
||||
entity.setProtocolClaim(protocolClaim);
|
||||
entity.setSource(source);
|
||||
entity.setAppliedByDefault(appliedByDefault);
|
||||
if (model.getId() != null) entity.setId(model.getId());
|
||||
else entity.setId(KeycloakModelUtils.generateId());
|
||||
entity.setSourceAttribute(model.getSourceAttribute());
|
||||
entity.setProtocol(model.getProtocol());
|
||||
entity.setProtocolClaim(model.getProtocolClaim());
|
||||
entity.setSource(model.getSource());
|
||||
entity.setAppliedByDefault(model.isAppliedByDefault());
|
||||
realm.getClaimMappings().add(entity);
|
||||
updateRealm();
|
||||
ProtocolClaimMappingModel mapping = new ProtocolClaimMappingModel();
|
||||
|
@ -881,13 +882,14 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public ClaimTypeModel addClaimType(String name, ClaimTypeModel.ValueType type, boolean builtIn) {
|
||||
ClaimTypeModel claim = new ClaimTypeModel(KeycloakModelUtils.generateId(), name, builtIn, type);
|
||||
public ClaimTypeModel addClaimType(ClaimTypeModel model) {
|
||||
String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId();
|
||||
ClaimTypeModel claim = new ClaimTypeModel(id, model.getName(), model.isBuiltIn(), model.getType());
|
||||
ClaimTypeEntity entity = new ClaimTypeEntity();
|
||||
entity.setId(claim.getId());
|
||||
entity.setType(type);
|
||||
entity.setBuiltIn(builtIn);
|
||||
entity.setName(name);
|
||||
entity.setType(model.getType());
|
||||
entity.setBuiltIn(model.isBuiltIn());
|
||||
entity.setName(model.getName());
|
||||
realm.getClaimTypes().add(entity);
|
||||
updateRealm();
|
||||
return claim;
|
||||
|
|
Loading…
Reference in a new issue