use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.
the class AdElementListModel method addGroupsToModel.
protected void addGroupsToModel(QueryReturnValue returnValue, Set<String> excludeUsers) {
for (Queryable item : (Collection<Queryable>) returnValue.getReturnValue()) {
DirectoryGroup a = (DirectoryGroup) item;
if (!excludeUsers.contains(a.getId())) {
// TODO: This is a hack, we should either use DbGroup or reimplement user/group representation in GWT
DbUser group = new DbUser();
group.setExternalId(a.getId());
group.setFirstName(a.getName());
// $NON-NLS-1$
group.setLastName("");
// TODO: Due to group -> DbUser mapping hack we have to use note to represent display name of group
group.setNote(a.getDisplayName());
group.setDomain(a.getDirectoryName());
group.setNamespace(a.getNamespace());
EntityModel<DbUser> groupEntity = new EntityModel<>();
groupEntity.setEntity(group);
getgroups().add(groupEntity);
}
}
}
use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.
the class SearchQuery method searchDirectoryGroups.
private List<DirectoryGroup> searchDirectoryGroups() {
// Parse the query:
QueryData data = initQueryData(true);
if (data == null) {
return Collections.emptyList();
}
List<DirectoryGroup> results = new ArrayList<>();
Map<String, Object> response = SsoOAuthServiceUtils.searchGroups(sessionDataContainer.getSsoAccessToken(getParameters().getSessionId()), getParamsMap(data));
if (response.containsKey("result")) {
Collection<ExtMap> groups = (Collection<ExtMap>) response.get("result");
results = groups.stream().map((ExtMap g) -> directoryUtils.mapGroupRecordToDirectoryGroup(data.getAuthz(), g)).collect(Collectors.toList());
}
return results;
}
use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.
the class DirectoryUtils method mapGroupRecordToDirectoryGroup.
private DirectoryGroup mapGroupRecordToDirectoryGroup(final String authzName, final ExtMap group, final Set<String> loopPrevention) {
DirectoryGroup directoryGroup = null;
if (group != null) {
directoryGroup = new DirectoryGroup(authzName, group.get(Authz.GroupRecord.NAMESPACE), group.get(Authz.GroupRecord.ID), group.get(Authz.GroupRecord.NAME), group.get(Authz.GroupRecord.DISPLAY_NAME));
loopPrevention.add(directoryGroup.getId());
for (ExtMap memberOf : group.<Collection<ExtMap>>get(Authz.GroupRecord.GROUPS, Collections.<ExtMap>emptyList())) {
if (!loopPrevention.contains(memberOf.<String>get(GroupRecord.ID))) {
directoryGroup.getGroups().add(mapGroupRecordToDirectoryGroup(authzName, memberOf, loopPrevention));
}
}
}
return directoryGroup;
}
use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.
the class BackendGroupsResource method add.
@Override
public Response add(Group group) {
List<String> authzProvidersNames = getBackendCollection(String.class, QueryType.GetDomainList, new QueryParametersBase());
validateParameters(group, "name");
if (AuthzUtils.getAuthzNameFromEntityName(group.getName(), authzProvidersNames) == null) {
validateParameters(group, "domain.id|name");
}
String directoryName = getAuthzProviderName(group, authzProvidersNames);
DirectoryGroup directoryGroup = findDirectoryGroup(directoryName, group);
if (directoryGroup == null) {
return Response.status(Status.BAD_REQUEST).entity("No such group: " + group.getName() + " in directory " + directoryName).build();
}
AddGroupParameters parameters = new AddGroupParameters();
parameters.setGroupToAdd(new DbGroup(directoryGroup));
QueryIdResolver<Guid> resolver = new QueryIdResolver<>(QueryType.GetDbGroupById, IdQueryParameters.class);
return performCreate(ActionType.AddGroup, parameters, resolver, BaseResource.class);
}
use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.
the class UserMapper method map.
@Mapping(from = DirectoryUser.class, to = User.class)
public static User map(DirectoryUser entity, User template) {
User model = template != null ? template : new User();
model.setName(entity.getFirstName());
model.setUserName(entity.getName() + "@" + entity.getDirectoryName());
model.setId(DirectoryEntryIdUtils.encode(entity.getId()));
model.setLastName(entity.getLastName());
model.setEmail(entity.getEmail());
model.setDepartment(entity.getDepartment());
model.setPrincipal(entity.getPrincipal());
model.setNamespace(entity.getNamespace());
if (entity.getGroups() != null) {
model.setGroups(new Groups());
for (DirectoryGroup directoryGroup : entity.getGroups()) {
Group group = new Group();
group.setName(directoryGroup.getName());
model.getGroups().getGroups().add(group);
}
}
if (!StringUtils.isEmpty(entity.getDirectoryName())) {
Domain dom = new Domain();
dom.setName(entity.getDirectoryName());
dom.setId(DirectoryEntryIdUtils.encode(dom.getName()));
model.setDomain(dom);
}
return model;
}
Aggregations