Search in sources :

Example 6 with AuthenticationProfile

use of org.ovirt.engine.core.aaa.AuthenticationProfile in project ovirt-engine by oVirt.

the class SsoRestApiNegotiationFilter 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 7 with AuthenticationProfile

use of org.ovirt.engine.core.aaa.AuthenticationProfile in project ovirt-engine by oVirt.

the class SsoRestApiNegotiationFilter method doAuth.

private AuthResult doAuth(HttpServletRequest req, HttpServletResponse rsp, Deque<AuthenticationProfile> stack) throws IOException, ServletException {
    AuthResult authResult = new AuthResult();
    log.debug("Performing external authentication");
    boolean stop = false;
    while (!stop && !stack.isEmpty()) {
        AuthenticationProfile profile = stack.peek();
        ExtMap output = profile.getAuthn().invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Authn.InvokeCommands.AUTHENTICATE_NEGOTIATE).mput(Authn.InvokeKeys.HTTP_SERVLET_REQUEST, req).mput(Authn.InvokeKeys.HTTP_SERVLET_RESPONSE, rsp));
        switch(output.<Integer>get(Authn.InvokeKeys.RESULT)) {
            case Authn.AuthResult.SUCCESS:
                ExtMap authRecord = output.get(Authn.InvokeKeys.AUTH_RECORD);
                authResult.authRecord = authRecord;
                authResult.username = String.format("%s@%s", authRecord.get(Authn.AuthRecord.PRINCIPAL), profile.getName());
                stack.clear();
                break;
            case Authn.AuthResult.NEGOTIATION_UNAUTHORIZED:
                stack.pop();
                break;
            case Authn.AuthResult.NEGOTIATION_INCOMPLETE:
                stop = true;
                break;
            default:
                log.error("Unexpected authentication result. AuthResult code is {}", output.<Integer>get(Authn.InvokeKeys.RESULT));
                stack.pop();
                break;
        }
    }
    log.debug("External Authentication result: {}", StringUtils.isNotEmpty(authResult.username));
    return authResult;
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) AuthenticationProfile(org.ovirt.engine.core.aaa.AuthenticationProfile)

Example 8 with AuthenticationProfile

use of org.ovirt.engine.core.aaa.AuthenticationProfile in project ovirt-engine by oVirt.

the class NegotiationFilter method doAuth.

private void doAuth(HttpServletRequest req, HttpServletResponse rsp, Deque<AuthenticationProfile> stack) throws IOException, ServletException {
    boolean stop = false;
    while (!stop && !stack.isEmpty()) {
        AuthenticationProfile profile = stack.peek();
        ExtMap output = profile.getAuthn().invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Authn.InvokeCommands.AUTHENTICATE_NEGOTIATE).mput(Authn.InvokeKeys.HTTP_SERVLET_REQUEST, req).mput(Authn.InvokeKeys.HTTP_SERVLET_RESPONSE, rsp));
        switch(output.<Integer>get(Authn.InvokeKeys.RESULT)) {
            case Authn.AuthResult.SUCCESS:
                req.setAttribute(FiltersHelper.Constants.REQUEST_AUTH_RECORD_KEY, output.<ExtMap>get(Authn.InvokeKeys.AUTH_RECORD));
                req.setAttribute(FiltersHelper.Constants.REQUEST_AUTH_TYPE_KEY, AuthType.NEGOTIATION);
                req.setAttribute(FiltersHelper.Constants.REQUEST_PROFILE_KEY, profile.getName());
                stack.clear();
                break;
            case Authn.AuthResult.NEGOTIATION_UNAUTHORIZED:
                stack.pop();
                break;
            case Authn.AuthResult.NEGOTIATION_INCOMPLETE:
                stop = true;
                break;
            default:
                log.error("Unexpected authentication result. AuthResult code is {}", output.<Integer>get(Authn.InvokeKeys.RESULT));
                stack.pop();
                break;
        }
    }
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) AuthenticationProfile(org.ovirt.engine.core.aaa.AuthenticationProfile)

Aggregations

AuthenticationProfile (org.ovirt.engine.core.aaa.AuthenticationProfile)8 ExtMap (org.ovirt.engine.api.extensions.ExtMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)1