realm.setAccessCodeLifespan(rep.getAccessCodeLifespan());
realm.setSslNotRequired(rep.isSslNotRequired());
realm = identityManager.create(realm);
Map<String, User> userMap = new HashMap<String, User>();
Role adminRole = identityManager.create(realm, "admin");
for (RequiredCredentialRepresentation requiredCred : rep.getRequiredCredentials())
{
RequiredCredential credential = new RequiredCredential();
credential.setType(requiredCred.getType());
credential.setInput(requiredCred.isInput());
credential.setSecret(requiredCred.isSecret());
identityManager.create(realm, credential);
}
for (UserRepresentation userRep : rep.getUsers())
{
User user = new User();
user.setUsername(userRep.getUsername());
user.setEnabled(userRep.isEnabled());
user = identityManager.create(realm, user);
userMap.put(user.getUsername(), user);
if (userRep.getCredentials() != null)
{
for (UserRepresentation.Credential cred : userRep.getCredentials())
{
UserCredential credential = new UserCredential();
credential.setType(cred.getType());
credential.setValue(cred.getValue());
credential.setHashed(cred.isHashed());
identityManager.create(user, credential);
}
}
if (userRep.getAttributes() != null)
{
for (Map.Entry<String, String> entry : userRep.getAttributes().entrySet())
{
UserAttribute attribute = new UserAttribute();
attribute.setName(entry.getKey());
attribute.setValue(entry.getValue());
identityManager.create(user, attribute);
}
}
}
for (RoleMappingRepresentation mapping : rep.getRoleMappings())
{
RoleMapping roleMapping = createRoleMapping(userMap, mapping);
User user = userMap.get(mapping.getUsername());
identityManager.create(realm, user, roleMapping);
}
for (ScopeMappingRepresentation scope : rep.getScopeMappings())
{
ScopeMapping scopeMapping = createScopeMapping(userMap, scope);
User user = userMap.get(scope.getUsername());
identityManager.create(realm, user, scopeMapping);
}
if (rep.getResources() != null)
{
for (ResourceRepresentation resourceRep : rep.getResources())
{
Resource resource = new Resource();
resource.setName(resourceRep.getName());
resource.setSurrogateAuthRequired(resourceRep.isSurrogateAuthRequired());
resource = identityManager.create(realm, resource);
if (resourceRep.getRoles() != null)
{
for (String role : resourceRep.getRoles())
{
Role r = identityManager.create(realm, resource, role);
}
}
if (resourceRep.getRoleMappings() != null)
{
for (RoleMappingRepresentation mapping : resourceRep.getRoleMappings())