Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
104a9f9842
69 files changed
+699
-154
No files matched your search
@@ -24,6 +24,10 @@ public interface ClientModel extends RoleContainerModel {
|
||||
|
||||
void setClientId(String clientId);
|
||||
|
||||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
void setEnabled(boolean enabled);
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -145,6 +145,7 @@ public interface RealmModel extends RoleContainerModel {
|
||||
|
||||
void updateDefaultRoles(String[] defaultRoles);
|
||||
|
||||
// Key is clientId
|
||||
Map<String, ClientModel> getClientNameMap();
|
||||
|
||||
List<ClientModel> getClients();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Map;
|
||||
public class ClientEntity extends AbstractIdentifiableEntity {
|
||||
|
||||
private String clientId;
|
||||
private String name;
|
||||
private String realmId;
|
||||
private boolean enabled;
|
||||
private String secret;
|
||||
@@ -49,6 +50,14 @@ public class ClientEntity extends AbstractIdentifiableEntity {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@@ -226,6 +226,7 @@ public class ModelToRepresentation {
|
||||
ClientRepresentation rep = new ClientRepresentation();
|
||||
rep.setId(clientModel.getId());
|
||||
rep.setClientId(clientModel.getClientId());
|
||||
rep.setName(clientModel.getName());
|
||||
rep.setEnabled(clientModel.isEnabled());
|
||||
rep.setAdminUrl(clientModel.getManagementUrl());
|
||||
rep.setPublicClient(clientModel.isPublicClient());
|
||||
|
||||
@@ -523,6 +523,7 @@ public class RepresentationToModel {
|
||||
logger.debug("Create client: {0}" + resourceRep.getClientId());
|
||||
|
||||
ClientModel client = resourceRep.getId()!=null ? realm.addClient(resourceRep.getId(), resourceRep.getClientId()) : realm.addClient(resourceRep.getClientId());
|
||||
if (resourceRep.getName() != null) client.setName(resourceRep.getName());
|
||||
if (resourceRep.isEnabled() != null) client.setEnabled(resourceRep.isEnabled());
|
||||
client.setManagementUrl(resourceRep.getAdminUrl());
|
||||
if (resourceRep.isSurrogateAuthRequired() != null)
|
||||
@@ -614,6 +615,7 @@ public class RepresentationToModel {
|
||||
|
||||
public static void updateClient(ClientRepresentation rep, ClientModel resource) {
|
||||
if (rep.getClientId() != null) resource.setClientId(rep.getClientId());
|
||||
if (rep.getName() != null) resource.setName(rep.getName());
|
||||
if (rep.isEnabled() != null) resource.setEnabled(rep.isEnabled());
|
||||
if (rep.isBearerOnly() != null) resource.setBearerOnly(rep.isBearerOnly());
|
||||
if (rep.isConsentRequired() != null) resource.setConsentRequired(rep.isConsentRequired());
|
||||
@@ -792,23 +794,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