Search in sources :

Example 16 with ExtMap

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;
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) Collection(java.util.Collection)

Example 17 with ExtMap

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);
        }
    }
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) Collection(java.util.Collection)

Example 18 with ExtMap

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;
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) ExtMap(org.ovirt.engine.api.extensions.ExtMap) Collection(java.util.Collection) Guid(org.ovirt.engine.core.compat.Guid) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Example 19 with ExtMap

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;
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) EngineException(org.ovirt.engine.core.common.errors.EngineException) Collection(java.util.Collection) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 20 with ExtMap

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");
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) Properties(java.util.Properties)

Aggregations

ExtMap (org.ovirt.engine.api.extensions.ExtMap)48 Collection (java.util.Collection)15 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)5 Map (java.util.Map)5 IOException (java.io.IOException)4 AuthenticationProfile (org.ovirt.engine.core.aaa.AuthenticationProfile)4 DirectoryGroup (org.ovirt.engine.core.aaa.DirectoryGroup)4 Properties (java.util.Properties)3 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)3 ExtensionProxy (org.ovirt.engine.core.extensions.mgr.ExtensionProxy)3 HashSet (java.util.HashSet)2 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 ServletException (javax.servlet.ServletException)2 ExtKey (org.ovirt.engine.api.extensions.ExtKey)2 DirectoryUser (org.ovirt.engine.core.aaa.DirectoryUser)2 QueryData (org.ovirt.engine.core.aaa.QueryData)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 CreateUserSessionParameters (org.ovirt.engine.core.common.action.CreateUserSessionParameters)2