Search in sources :

Example 36 with ExtMap

use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.

the class AuthenticationUtils method loginOnBehalf.

public static void loginOnBehalf(SsoContext ssoContext, HttpServletRequest request, String username) throws Exception {
    log.debug("Entered AuthenticationUtils.loginOnBehalf");
    int index = username.lastIndexOf("@");
    String profile = null;
    if (index != -1) {
        profile = username.substring(index + 1);
        username = username.substring(0, index);
    }
    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(profile)) {
        throw new AuthenticationException(ssoContext.getLocalizationUtils().localize(SsoConstants.APP_ERROR_PROVIDE_USERNAME_AND_PROFILE, (Locale) request.getAttribute(SsoConstants.LOCALE)));
    }
    ObjectMapper mapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false).enableDefaultTyping(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE);
    mapper.getDeserializationConfig().addMixInAnnotations(ExtMap.class, JsonExtMapMixIn.class);
    String authRecordJson = SsoUtils.getRequestParameter(request, SsoConstants.HTTP_PARAM_AUTH_RECORD, "");
    ExtMap authRecord;
    if (StringUtils.isNotEmpty(authRecordJson)) {
        authRecord = mapper.readValue(authRecordJson, ExtMap.class);
    } else {
        authRecord = new ExtMap().mput(Authn.AuthRecord.PRINCIPAL, username);
    }
    SsoSession ssoSession = login(ssoContext, request, new Credentials(username, null, profile, SsoUtils.getSsoContext(request).getSsoProfiles().contains(profile)), authRecord, false);
    log.info("User {}@{} successfully logged in using login-on-behalf with client id : {} and scopes : {}", username, profile, ssoSession.getClientId(), ssoSession.getScope());
}
Also used : Locale(java.util.Locale) ExtMap(org.ovirt.engine.api.extensions.ExtMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 37 with ExtMap

use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.

the class AuthenticationUtils method login.

private static SsoSession login(SsoContext ssoContext, HttpServletRequest request, Credentials credentials, ExtMap authRecord, boolean interactive) throws Exception {
    ExtensionProfile profile = getExtensionProfile(ssoContext, credentials.getProfile());
    String user = mapUser(profile, credentials);
    if (authRecord == null) {
        log.debug("AuthenticationUtils.handleCredentials invoking AUTHENTICATE_CREDENTIALS on authn");
        ExtMap outputMap = profile.authn.invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Authn.InvokeCommands.AUTHENTICATE_CREDENTIALS).mput(Authn.InvokeKeys.USER, user).mput(Authn.InvokeKeys.CREDENTIALS, credentials.getPassword()));
        if (outputMap.<Integer>get(Base.InvokeKeys.RESULT) != Base.InvokeResult.SUCCESS || outputMap.<Integer>get(Authn.InvokeKeys.RESULT) != Authn.AuthResult.SUCCESS) {
            if (interactive) {
                SsoUtils.getSsoSession(request).setChangePasswdCredentials(credentials);
            }
            log.debug("AuthenticationUtils.handleCredentials AUTHENTICATE_CREDENTIALS on authn failed");
            throw new AuthenticationException(AuthnMessageMapper.mapMessageErrorCode(ssoContext, request, credentials.getProfile(), outputMap));
        }
        log.debug("AuthenticationUtils.handleCredentials AUTHENTICATE_CREDENTIALS on authn succeeded");
        authRecord = outputMap.get(Authn.InvokeKeys.AUTH_RECORD);
    }
    if (profile.mapper != null) {
        log.debug("AuthenticationUtils.handleCredentials invoking MAP_AUTH_RECORD on mapper");
        authRecord = profile.mapper.invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Mapping.InvokeCommands.MAP_AUTH_RECORD).mput(Authn.InvokeKeys.AUTH_RECORD, authRecord), true).get(Authn.InvokeKeys.AUTH_RECORD, authRecord);
    }
    log.debug("AuthenticationUtils.handleCredentials invoking FETCH_PRINCIPAL_RECORD on authz");
    ExtMap output = profile.authz.invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Authz.InvokeCommands.FETCH_PRINCIPAL_RECORD).mput(Authn.InvokeKeys.AUTH_RECORD, authRecord).mput(Authz.InvokeKeys.QUERY_FLAGS, Authz.QueryFlags.RESOLVE_GROUPS | Authz.QueryFlags.RESOLVE_GROUPS_RECURSIVE));
    log.debug("AuthenticationUtils.handleCredentials saving data in session data");
    return SsoUtils.persistAuthInfoInContextWithToken(request, credentials.getPassword(), credentials.getProfile(), authRecord, output.get(Authz.InvokeKeys.PRINCIPAL_RECORD));
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap)

Example 38 with ExtMap

use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.

the class AuthenticationUtils method mapUser.

private static String mapUser(ExtensionProfile profile, Credentials credentials) {
    String user = credentials.getUsername();
    if (profile.mapper != null) {
        log.debug("AuthenticationUtils.handleCredentials invoking MAP_USER on mapper");
        user = profile.mapper.invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Mapping.InvokeCommands.MAP_USER).mput(Mapping.InvokeKeys.USER, user), true).get(Mapping.InvokeKeys.USER, user);
    }
    return user;
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap)

Example 39 with ExtMap

use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.

the class CreateUserSessionCommand method flatGroups.

private static 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(Authz.GroupRecord.ID))) {
            accumulator.put(group.get(Authz.GroupRecord.ID), group);
            flatGroups(group, Authz.GroupRecord.GROUPS, accumulator);
        }
    }
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) Collection(java.util.Collection)

Example 40 with ExtMap

use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.

the class CreateUserSessionCommand method buildUser.

private DbUser buildUser(T params, String authzName) {
    DbUser dbUser = dbUserDao.getByExternalId(authzName, params.getPrincipalId());
    DbUser user = new DbUser(dbUser);
    user.setId(dbUser == null ? Guid.newGuid() : dbUser.getId());
    user.setExternalId(params.getPrincipalId());
    user.setDomain(authzName);
    user.setEmail(params.getEmail());
    user.setFirstName(params.getFirstName());
    user.setLastName(params.getLastName());
    user.setNamespace(params.getNamespace());
    user.setLoginName(params.getPrincipalName());
    List<Guid> groupIds = new ArrayList<>();
    Map<String, ExtMap> groupRecords = new HashMap<>();
    flatGroups((Collection<ExtMap>) params.getGroupIds(), groupRecords);
    for (Map.Entry<String, ExtMap> group : groupRecords.entrySet()) {
        DbGroup dbGroup = dbGroupDao.getByExternalId(authzName, group.getKey());
        if (dbGroup != null) {
            dbGroup.setName(group.getValue().get(Authz.GroupRecord.NAME));
            dbGroupDao.update(dbGroup);
            groupIds.add(dbGroup.getId());
        }
    }
    user.setGroupIds(groupIds);
    user.setAdmin(!roleDao.getAnyAdminRoleForUserAndGroups(user.getId(), StringUtils.join(user.getGroupIds(), ",")).isEmpty());
    if (dbUser == null) {
        dbUserDao.save(user);
    } else if (!dbUser.equals(user)) {
        dbUserDao.update(user);
    }
    return user;
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) ExtMap(org.ovirt.engine.api.extensions.ExtMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Map(java.util.Map) ExtMap(org.ovirt.engine.api.extensions.ExtMap) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

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