use of org.ovirt.engine.api.extensions.ExtMap 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.api.extensions.ExtMap in project ovirt-engine by oVirt.
the class DirectoryUtils method flatGroups.
private void flatGroups(ExtMap entity, ExtKey key, Map<String, ExtMap> accumulator) {
for (ExtMap group : entity.<Collection<ExtMap>>get(key, Collections.<ExtMap>emptyList())) {
if (!accumulator.containsKey(group.<String>get(GroupRecord.ID))) {
accumulator.put(group.get(GroupRecord.ID), group);
flatGroups(group, GroupRecord.GROUPS, accumulator);
}
}
}
use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.
the class DirectoryUtils method mapPrincipalRecordToDbUser.
public DbUser mapPrincipalRecordToDbUser(String authz, ExtMap principal) {
principal = principal.clone();
flatGroups(principal);
DbUser dbUser = dbUserDao.getByExternalId(authz, principal.get(PrincipalRecord.ID));
Guid userId = dbUser != null ? dbUser.getId() : Guid.newGuid();
dbUser = new DbUser(mapPrincipalRecordToDirectoryUser(authz, principal));
dbUser.setId(userId);
Set<Guid> groupIds = new HashSet<>();
Set<String> groupsNames = new HashSet<>();
for (ExtMap group : principal.<Collection<ExtMap>>get(PrincipalRecord.GROUPS, Collections.<ExtMap>emptyList())) {
DbGroup dbGroup = dbGroupDao.getByExternalId(authz, group.get(GroupRecord.ID));
if (dbGroup != null) {
groupIds.add(dbGroup.getId());
groupsNames.add(dbGroup.getName());
}
}
dbUser.setGroupIds(groupIds);
dbUser.setGroupNames(groupsNames);
return dbUser;
}
use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.
the class LoginOnBehalfCommand method getDbUserForPrincipalName.
private DbUser getDbUserForPrincipalName(String principalName, String authzName) {
Map<String, Object> response = SsoOAuthServiceUtils.fetchPrincipalRecord(getSessionDataContainer().getSsoAccessToken(getParameters().getSessionId()), authzName, principalName, false, false);
ExtMap principalRecord = null;
if (response.containsKey("result")) {
Collection<ExtMap> records = (Collection<ExtMap>) response.get("result");
if (!records.isEmpty()) {
principalRecord = records.iterator().next();
}
}
if (principalRecord == null) {
throw new EngineException(EngineError.PRINCIPAL_NOT_FOUND, String.format("%s in domain '%s", principalName, authzName));
}
DbUser user = new DbUser(directoryUtils.mapPrincipalRecordToDirectoryUser(authzName, principalRecord));
user.setId(Guid.newGuid());
return user;
}
use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.
the class InternalAuthn method doLoad.
private void doLoad(ExtMap input) {
ExtMap context = input.get(Base.InvokeKeys.CONTEXT);
context.<Collection<String>>get(Base.ContextKeys.CONFIGURATION_SENSITIVE_KEYS).add("config.authn.user.password");
context.mput(Base.ContextKeys.AUTHOR, "The oVirt Project").mput(Base.ContextKeys.EXTENSION_NAME, "Internal Authn (Built-in)").mput(Base.ContextKeys.LICENSE, "ASL 2.0").mput(Base.ContextKeys.HOME_URL, "http://www.ovirt.org").mput(Base.ContextKeys.VERSION, "N/A").mput(Authn.ContextKeys.CAPABILITIES, Authn.Capabilities.AUTHENTICATE_CREDENTIALS | Authn.Capabilities.AUTHENTICATE_PASSWORD).mput(Base.ContextKeys.BUILD_INTERFACE_VERSION, Base.INTERFACE_VERSION_CURRENT);
Properties config = context.get(Base.ContextKeys.CONFIGURATION);
adminUser = config.getProperty("config.authn.user.name", "admin");
adminPassword = config.getProperty("config.authn.user.password");
}
Aggregations