KEYCLOAK-1070 add setProtocolMappers/getProtocolMappers to ClientSession
This commit is contained in:
1 parent
dae219d32e
commit
535023d800
27 files changed
+345
-70
No files matched your search
@@ -28,6 +28,9 @@ public interface ClientSessionModel {
|
||||
public Set<String> getRoles();
|
||||
public void setRoles(Set<String> roles);
|
||||
|
||||
public Set<String> getProtocolMappers();
|
||||
public void setProtocolMappers(Set<String> protocolMappers);
|
||||
|
||||
/**
|
||||
* Authentication request type, i.e. OAUTH, SAML 2.0, SAML 1.1, etc.
|
||||
*
|
||||
|
||||
@@ -8,31 +8,20 @@ import java.util.Set;
|
||||
*/
|
||||
public class UserConsentModel {
|
||||
|
||||
private final RealmModel realm;
|
||||
private final ClientModel client;
|
||||
private Set<ProtocolMapperModel> protocolMappers = new HashSet<ProtocolMapperModel>();
|
||||
private Set<RoleModel> roles = new HashSet<RoleModel>();
|
||||
|
||||
public UserConsentModel(RealmModel realm, String clientId) {
|
||||
this.realm = realm;
|
||||
this.client = realm.getClientById(clientId);
|
||||
|
||||
if (client == null) {
|
||||
throw new ModelException("Client with id [" + clientId + "] is not available");
|
||||
}
|
||||
public UserConsentModel(ClientModel client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public ClientModel getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void addGrantedRole(String roleId) {
|
||||
RoleModel role = realm.getRoleById(roleId);
|
||||
|
||||
// Chance that role was already deleted by other transaction and is not available anymore
|
||||
if (role != null) {
|
||||
roles.add(role);
|
||||
}
|
||||
public void addGrantedRole(RoleModel role) {
|
||||
roles.add(role);
|
||||
}
|
||||
|
||||
public Set<RoleModel> getGrantedRoles() {
|
||||
@@ -46,13 +35,8 @@ public class UserConsentModel {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addGrantedProtocolMapper(String protocolMapperId) {
|
||||
ProtocolMapperModel protocolMapper = client.getProtocolMapperById(protocolMapperId);
|
||||
|
||||
// Chance that protocolMapper was already deleted by other transaction and is not available anymore
|
||||
if (protocolMapper != null) {
|
||||
protocolMappers.add(protocolMapper);
|
||||
}
|
||||
public void addGrantedProtocolMapper(ProtocolMapperModel protocolMapper) {
|
||||
protocolMappers.add(protocolMapper);
|
||||
}
|
||||
|
||||
public Set<ProtocolMapperModel> getGrantedProtocolMappers() {
|
||||
|
||||
@@ -792,23 +792,25 @@ public class RepresentationToModel {
|
||||
throw new RuntimeException("Unable to find client consent mappings for client: " + entry.getKey());
|
||||
}
|
||||
|
||||
UserConsentModel consentModel = new UserConsentModel(newRealm, client.getId());
|
||||
UserConsentModel consentModel = new UserConsentModel(client);
|
||||
|
||||
UserConsentRepresentation consentRep = entry.getValue();
|
||||
if (consentRep.getGrantedRoles() != null) {
|
||||
for (String roleId : consentRep.getGrantedRoles()) {
|
||||
if (newRealm.getRoleById(roleId) == null) {
|
||||
RoleModel role = newRealm.getRoleById(roleId);
|
||||
if (role == null) {
|
||||
throw new RuntimeException("Unable to find realm role referenced in consent mappings of user " + user.getUsername() + ". Role ID: " + roleId);
|
||||
}
|
||||
consentModel.addGrantedRole(roleId);
|
||||
consentModel.addGrantedRole(role);
|
||||
}
|
||||
}
|
||||
if (consentRep.getGrantedProtocolMappers() != null) {
|
||||
for (String mapperId : consentRep.getGrantedProtocolMappers()) {
|
||||
if (client.getProtocolMapperById(mapperId) == null) {
|
||||
ProtocolMapperModel protocolMapper = client.getProtocolMapperById(mapperId);
|
||||
if (protocolMapper == null) {
|
||||
throw new RuntimeException("Unable to find protocol mapper referenced in consent mappings of user " + user.getUsername() + ". Protocol mapper ID: " + mapperId);
|
||||
}
|
||||
consentModel.addGrantedProtocolMapper(mapperId);;
|
||||
consentModel.addGrantedProtocolMapper(protocolMapper);
|
||||
}
|
||||
}
|
||||
user.addConsent(consentModel);
|
||||
|
||||
Reference in new issue
Block a user