more claims work
This commit is contained in:
1 parent
6d224745b2
commit
69582ee3be
30 files changed
+697
-268
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package org.keycloak.models;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Specifies a mapping from user data to a protocol claim assertion. If protocolMapper is set, this points
|
||||
* to a @Provider that will perform the mapping. If you have this set, then no other attributes of this class need to be set.
|
||||
@@ -10,21 +12,14 @@ package org.keycloak.models;
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class ProtocolMapperModel {
|
||||
public static enum Source {
|
||||
USER_MODEL,
|
||||
USER_ATTRIBUTE,
|
||||
USER_SESSION_NOTE,
|
||||
CLIENT_SESSION_NOTE
|
||||
}
|
||||
|
||||
protected String id;
|
||||
protected String name;
|
||||
protected String protocolClaim;
|
||||
protected String protocol;
|
||||
protected Source source;
|
||||
protected String sourceAttribute;
|
||||
protected String protocolMapper;
|
||||
protected boolean consentRequired;
|
||||
protected String consentText;
|
||||
protected boolean appliedByDefault;
|
||||
protected Map<String, String> config;
|
||||
|
||||
|
||||
public String getId() {
|
||||
@@ -43,14 +38,6 @@ public class ProtocolMapperModel {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getProtocolClaim() {
|
||||
return protocolClaim;
|
||||
}
|
||||
|
||||
public void setProtocolClaim(String protocolClaim) {
|
||||
this.protocolClaim = protocolClaim;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
@@ -59,14 +46,6 @@ public class ProtocolMapperModel {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public String getSourceAttribute() {
|
||||
return sourceAttribute;
|
||||
}
|
||||
|
||||
public void setSourceAttribute(String sourceAttribute) {
|
||||
this.sourceAttribute = sourceAttribute;
|
||||
}
|
||||
|
||||
public boolean isAppliedByDefault() {
|
||||
return appliedByDefault;
|
||||
}
|
||||
@@ -75,14 +54,6 @@ public class ProtocolMapperModel {
|
||||
this.appliedByDefault = appliedByDefault;
|
||||
}
|
||||
|
||||
public Source getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(Source source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getProtocolMapper() {
|
||||
return protocolMapper;
|
||||
}
|
||||
@@ -91,6 +62,30 @@ public class ProtocolMapperModel {
|
||||
this.protocolMapper = protocolMapper;
|
||||
}
|
||||
|
||||
public boolean isConsentRequired() {
|
||||
return consentRequired;
|
||||
}
|
||||
|
||||
public void setConsentRequired(boolean consentRequired) {
|
||||
this.consentRequired = consentRequired;
|
||||
}
|
||||
|
||||
public String getConsentText() {
|
||||
return consentText;
|
||||
}
|
||||
|
||||
public void setConsentText(String consentText) {
|
||||
this.consentText = consentText;
|
||||
}
|
||||
|
||||
public Map<String, String> getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setConfig(Map<String, String> config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.keycloak.models;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class RealmListenerHelper {
|
||||
protected LinkedList<RealmProvider.RealmCreationListener> list = new LinkedList<RealmProvider.RealmCreationListener>();
|
||||
|
||||
public void registerListener(RealmProvider.RealmCreationListener listener) {
|
||||
synchronized (list) {
|
||||
list.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterListener(RealmProvider.RealmCreationListener listener) {
|
||||
synchronized (list) {
|
||||
list.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void executeCreationListeners(RealmModel realm) {
|
||||
synchronized (list) {
|
||||
for (RealmProvider.RealmCreationListener listener : list) {
|
||||
listener.created(realm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,16 @@ import java.util.List;
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public interface RealmProvider extends Provider {
|
||||
public interface RealmCreationListener {
|
||||
void created(RealmModel realm);
|
||||
}
|
||||
|
||||
// Note: The reason there are so many query methods here is for layering a cache on top of an persistent KeycloakSession
|
||||
|
||||
RealmModel createRealm(String name);
|
||||
RealmModel createRealm(String id, String name);
|
||||
void registerListener(RealmCreationListener listener);
|
||||
void unregisterListener(RealmCreationListener listener);
|
||||
RealmModel getRealm(String id);
|
||||
RealmModel getRealmByName(String name);
|
||||
|
||||
|
||||
@@ -2,18 +2,21 @@ package org.keycloak.models.entities;
|
||||
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class ProtocolMapperEntity {
|
||||
protected String id;
|
||||
protected String protocolClaim;
|
||||
protected String name;
|
||||
protected String protocol;
|
||||
protected ProtocolMapperModel.Source source;
|
||||
protected String sourceAttribute;
|
||||
protected String protocolMapper;
|
||||
protected boolean appliedByDefault;
|
||||
protected boolean consentRequired;
|
||||
protected String consentText;
|
||||
protected Map<String, String> config;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
@@ -23,12 +26,12 @@ public class ProtocolMapperEntity {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getProtocolClaim() {
|
||||
return protocolClaim;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setProtocolClaim(String protocolClaim) {
|
||||
this.protocolClaim = protocolClaim;
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
@@ -39,22 +42,6 @@ public class ProtocolMapperEntity {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public ProtocolMapperModel.Source getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(ProtocolMapperModel.Source source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getSourceAttribute() {
|
||||
return sourceAttribute;
|
||||
}
|
||||
|
||||
public void setSourceAttribute(String sourceAttribute) {
|
||||
this.sourceAttribute = sourceAttribute;
|
||||
}
|
||||
|
||||
public boolean isAppliedByDefault() {
|
||||
return appliedByDefault;
|
||||
}
|
||||
@@ -70,4 +57,28 @@ public class ProtocolMapperEntity {
|
||||
public void setProtocolMapper(String protocolMapper) {
|
||||
this.protocolMapper = protocolMapper;
|
||||
}
|
||||
|
||||
public Map<String, String> getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setConfig(Map<String, String> config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public boolean isConsentRequired() {
|
||||
return consentRequired;
|
||||
}
|
||||
|
||||
public void setConsentRequired(boolean consentRequired) {
|
||||
this.consentRequired = consentRequired;
|
||||
}
|
||||
|
||||
public String getConsentText() {
|
||||
return consentText;
|
||||
}
|
||||
|
||||
public void setConsentText(String consentText) {
|
||||
this.consentText = consentText;
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class RealmEntity extends AbstractIdentifiableEntity {
|
||||
private List<UserFederationProviderEntity> userFederationProviders = new ArrayList<UserFederationProviderEntity>();
|
||||
private List<IdentityProviderEntity> identityProviders = new ArrayList<IdentityProviderEntity>();
|
||||
private List<ClaimTypeEntity> claimTypes = new ArrayList<ClaimTypeEntity>();
|
||||
private List<ProtocolMapperEntity> claimMappings = new ArrayList<ProtocolMapperEntity>();
|
||||
private List<ProtocolMapperEntity> protocolMappers = new ArrayList<ProtocolMapperEntity>();
|
||||
|
||||
private Map<String, String> browserSecurityHeaders = new HashMap<String, String>();
|
||||
private Map<String, String> smtpConfig = new HashMap<String, String>();
|
||||
@@ -401,12 +401,12 @@ public class RealmEntity extends AbstractIdentifiableEntity {
|
||||
this.claimTypes = claimTypes;
|
||||
}
|
||||
|
||||
public List<ProtocolMapperEntity> getClaimMappings() {
|
||||
return claimMappings;
|
||||
public List<ProtocolMapperEntity> getProtocolMappers() {
|
||||
return protocolMappers;
|
||||
}
|
||||
|
||||
public void setClaimMappings(List<ProtocolMapperEntity> claimMappings) {
|
||||
this.claimMappings = claimMappings;
|
||||
public void setProtocolMappers(List<ProtocolMapperEntity> protocolMappers) {
|
||||
this.protocolMappers = protocolMappers;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -341,11 +341,14 @@ public class ModelToRepresentation {
|
||||
ProtocolMapperRepresentation rep = new ProtocolMapperRepresentation();
|
||||
rep.setId(model.getId());
|
||||
rep.setProtocol(model.getProtocol());
|
||||
rep.setProtocolClaim(model.getProtocolClaim());
|
||||
rep.setSourceAttribute(model.getSourceAttribute());
|
||||
rep.setSource(model.getSource().name());
|
||||
Map<String, String> config = new HashMap<String, String>();
|
||||
config.putAll(model.getConfig());
|
||||
rep.setConfig(config);
|
||||
rep.setName(model.getName());
|
||||
rep.setProtocolMapper(model.getProtocolMapper());
|
||||
rep.setAppliedByDefault(model.isAppliedByDefault());
|
||||
rep.setConsentText(model.getConsentText());
|
||||
rep.setConsentRequired(model.isConsentRequired());
|
||||
return rep;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ public class RepresentationToModel {
|
||||
|
||||
importIdentityProviders(rep, newRealm);
|
||||
importClaimTypes(rep, newRealm);
|
||||
importProtocolClaimMappings(rep, newRealm);
|
||||
importProtocolMappers(rep, newRealm);
|
||||
|
||||
if (rep.getApplications() != null) {
|
||||
Map<String, ApplicationModel> appMap = createApplications(rep, newRealm);
|
||||
@@ -772,10 +772,15 @@ public class RepresentationToModel {
|
||||
}
|
||||
}
|
||||
|
||||
private static void importProtocolClaimMappings(RealmRepresentation rep, RealmModel newRealm) {
|
||||
private static void importProtocolMappers(RealmRepresentation rep, RealmModel newRealm) {
|
||||
if (rep.getProtocolClaimMappings() != null) {
|
||||
// we make sure we don't recreate mappers that are automatically created by the protocol providers.
|
||||
for (ProtocolMapperRepresentation representation : rep.getProtocolClaimMappings()) {
|
||||
newRealm.addProtocolMapper(toModel(representation));
|
||||
if (representation.getId() == null || newRealm.getProtocolMapperById(representation.getId()) == null) {
|
||||
newRealm.addProtocolMapper(toModel(representation));
|
||||
} else {
|
||||
newRealm.updateProtocolMapper(toModel(representation));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -808,12 +813,13 @@ public class RepresentationToModel {
|
||||
public static ProtocolMapperModel toModel(ProtocolMapperRepresentation rep) {
|
||||
ProtocolMapperModel model = new ProtocolMapperModel();
|
||||
model.setId(rep.getId());
|
||||
model.setName(rep.getName());
|
||||
model.setAppliedByDefault(rep.isAppliedByDefault());
|
||||
model.setSource(ProtocolMapperModel.Source.valueOf(rep.getSource()));
|
||||
model.setSourceAttribute(rep.getSourceAttribute());
|
||||
model.setConsentRequired(rep.isConsentRequired());
|
||||
model.setConsentText(rep.getConsentText());
|
||||
model.setProtocol(rep.getProtocol());
|
||||
model.setProtocolClaim(rep.getProtocolClaim());
|
||||
model.setProtocolMapper(rep.getProtocolMapper());
|
||||
model.setConfig(rep.getConfig());
|
||||
return model;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user