Search in sources :

Example 11 with ExtMap

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

the class ExtensionProxy method invoke.

public ExtMap invoke(ExtMap input, boolean allowUnsupported, boolean allowFail) {
    ExtMap output = new ExtMap();
    invoke(input, output);
    String message = output.get(Base.InvokeKeys.MESSAGE);
    switch(output.<Integer>get(Base.InvokeKeys.RESULT, Base.InvokeResult.FAILED)) {
        case Base.InvokeResult.SUCCESS:
            break;
        case Base.InvokeResult.UNSUPPORTED:
            if (!allowUnsupported) {
                throw new ExtensionInvokeCommandUnsupportedException(message == null ? "Unsupported command" : message, input, output);
            }
            break;
        case Base.InvokeResult.FAILED:
        default:
            if (!allowFail) {
                throw new ExtensionInvokeCommandFailedException(message == null ? "Invoke failed" : message, input, output, output.get(ExtensionsManager.CAUSE_OUTPUT_KEY));
            }
            break;
    }
    return output;
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap)

Example 12 with ExtMap

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

the class SsoOAuthServiceUtils method getTokenInfo.

public static Map<String, Object> getTokenInfo(String token, String scope) {
    try {
        HttpPost request = createPost("/oauth/token-info");
        setClientIdSecretBasicAuthHeader(request);
        List<BasicNameValuePair> form = new ArrayList<>(2);
        form.add(new BasicNameValuePair("token", token));
        if (StringUtils.isNotEmpty(scope)) {
            form.add(new BasicNameValuePair("scope", scope));
        }
        request.setEntity(new UrlEncodedFormEntity(form, StandardCharsets.UTF_8));
        Map<String, Object> jsonData = getResponse(request);
        Map<String, Object> ovirtData = (Map<String, Object>) jsonData.get("ovirt");
        if (ovirtData != null) {
            Collection<ExtMap> groupIds = (Collection<ExtMap>) ovirtData.get("group_ids");
            if (groupIds != null) {
                ovirtData.put("group_ids", SsoOAuthServiceUtils.processGroupMembershipsFromJson(groupIds));
            }
        }
        return jsonData;
    } catch (Exception ex) {
        return buildMapWithError("server_error", ex.getMessage());
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ExtMap(org.ovirt.engine.api.extensions.ExtMap) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Collection(java.util.Collection) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ExtMap(org.ovirt.engine.api.extensions.ExtMap)

Example 13 with ExtMap

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

the class NegotiationFilter method cacheNegotiatingProfiles.

private synchronized void cacheNegotiatingProfiles() {
    schemes = new ArrayList<>();
    profiles = new ArrayList<>();
    for (AuthenticationProfile profile : AuthenticationProfileRepository.getInstance().getProfiles()) {
        ExtMap authnContext = profile.getAuthn().getContext();
        if ((authnContext.<Long>get(Authn.ContextKeys.CAPABILITIES).longValue() & caps) != 0) {
            profiles.add(profile);
            schemes.addAll(authnContext.<Collection<String>>get(Authn.ContextKeys.HTTP_AUTHENTICATION_SCHEME, Collections.<String>emptyList()));
        }
    }
    Collections.sort(profiles, Comparator.comparing(AuthenticationProfile::getNegotiationPriority));
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) AuthenticationProfile(org.ovirt.engine.core.aaa.AuthenticationProfile)

Example 14 with ExtMap

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

the class AAAServiceImpl method acctReport.

private void acctReport(int reason, String authzName, ExtMap authRecord, ExtMap principalRecord, String user, String msg) {
    String displayUser = null;
    if (displayUser == null && principalRecord != null) {
        displayUser = principalRecord.get(Authz.PrincipalRecord.NAME);
    }
    if (displayUser == null && authRecord != null) {
        displayUser = authRecord.get(Authn.AuthRecord.PRINCIPAL);
    }
    if (displayUser == null) {
        displayUser = user;
    }
    String displayMessage = String.format(msg, displayUser);
    List<ExtensionProxy> acctExtensions = getExtensionsManager().getExtensionsByService(Acct.class.getName());
    if (acctExtensions != null) {
        ExtMap input = new ExtMap().mput(Acct.InvokeKeys.REASON, reason).mput(Base.InvokeKeys.COMMAND, Acct.InvokeCommands.REPORT).mput(Acct.InvokeKeys.PRINCIPAL_RECORD, new ExtMap().mput(Acct.PrincipalRecord.AUTHZ_NAME, authzName).mput(Acct.PrincipalRecord.AUTH_RECORD, authRecord).mput(Acct.PrincipalRecord.PRINCIPAL_RECORD, principalRecord).mput(Acct.PrincipalRecord.USER, displayUser).mput(Acct.InvokeKeys.MESSAGE, String.format(displayMessage, displayUser)));
        for (ExtensionProxy proxy : acctExtensions) {
            log.info("API: -->Acct.InvokeCommands.REPORT extension={}, reason={}, user='{}', message='{}'", proxy.getContext().get(Base.ContextKeys.INSTANCE_NAME), getFieldNameByValue(Acct.ReportReason.class, reason), displayUser, displayMessage);
            proxy.invoke(input);
            log.info("API: <--Acct.InvokeCommands.REPORT");
        }
    }
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) ExtensionProxy(org.ovirt.engine.core.extensions.mgr.ExtensionProxy) Acct(org.ovirt.engine.api.extensions.aaa.Acct)

Example 15 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(Collection<ExtMap> groupIds, Map<String, ExtMap> accumulator) {
    for (ExtMap group : groupIds) {
        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)

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