Search in sources :

Example 6 with Credentials

use of org.ovirt.engine.core.sso.utils.Credentials in project ovirt-engine by oVirt.

the class InteractiveChangePasswdServlet method getUserCredentials.

private Credentials getUserCredentials(HttpServletRequest request) throws AuthenticationException {
    try {
        String username = SsoUtils.getFormParameter(request, USERNAME);
        String credentials = SsoUtils.getFormParameter(request, CREDENTIALS);
        String credentialsNew1 = SsoUtils.getFormParameter(request, CREDENTIALS_NEW1);
        String credentialsNew2 = SsoUtils.getFormParameter(request, CREDENTIALS_NEW2);
        String profile = SsoUtils.getFormParameter(request, PROFILE);
        return StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(credentials) && StringUtils.isNotEmpty(credentialsNew1) && StringUtils.isNotEmpty(credentialsNew2) && StringUtils.isNotEmpty(profile) ? new Credentials(username, credentials, credentialsNew1, credentialsNew2, profile) : null;
    } catch (Exception ex) {
        throw new AuthenticationException(ssoContext.getLocalizationUtils().localize(SsoConstants.APP_ERROR_UNABLE_TO_EXTRACT_CREDENTIALS, (Locale) request.getAttribute(SsoConstants.LOCALE)), ex);
    }
}
Also used : AuthenticationException(org.ovirt.engine.core.sso.utils.AuthenticationException) Credentials(org.ovirt.engine.core.sso.utils.Credentials) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) AuthenticationException(org.ovirt.engine.core.sso.utils.AuthenticationException)

Example 7 with Credentials

use of org.ovirt.engine.core.sso.utils.Credentials in project ovirt-engine by oVirt.

the class OAuthTokenServlet method issueTokenForPasswd.

protected void issueTokenForPasswd(HttpServletRequest request, HttpServletResponse response, String scope) throws Exception {
    log.debug("Entered issueTokenForPasswd");
    Credentials credentials = null;
    try {
        credentials = getCredentials(request);
        SsoSession ssoSession = handleIssueTokenForPasswd(request, scope, credentials);
        log.debug("Sending json response");
        SsoUtils.sendJsonData(response, buildResponse(ssoSession));
    } catch (AuthenticationException ex) {
        String profile = "N/A";
        if (credentials != null) {
            profile = credentials.getProfile() == null ? "N/A" : credentials.getProfile();
        }
        throw new AuthenticationException(String.format(ssoContext.getLocalizationUtils().localize(SsoConstants.APP_ERROR_CANNOT_AUTHENTICATE_USER_IN_DOMAIN, (Locale) request.getAttribute(SsoConstants.LOCALE)), credentials == null ? "N/A" : credentials.getUsername(), profile, ex.getMessage()));
    }
}
Also used : Locale(java.util.Locale) AuthenticationException(org.ovirt.engine.core.sso.utils.AuthenticationException) Credentials(org.ovirt.engine.core.sso.utils.Credentials) SsoSession(org.ovirt.engine.core.sso.utils.SsoSession)

Example 8 with Credentials

use of org.ovirt.engine.core.sso.utils.Credentials in project ovirt-engine by oVirt.

the class InteractiveAuthServlet method getUserCredentials.

private Credentials getUserCredentials(HttpServletRequest request) throws Exception {
    String username = SsoUtils.getFormParameter(request, USERNAME);
    String password = SsoUtils.getFormParameter(request, PASSWORD);
    String profile = SsoUtils.getFormParameter(request, PROFILE);
    Credentials credentials;
    // we extract the credentials from the credentials saved to sso session.
    if (username == null || password == null || profile == null) {
        credentials = SsoUtils.getSsoSession(request).getTempCredentials();
    } else {
        credentials = new Credentials(username, password, profile, ssoContext.getSsoProfiles().contains(profile));
    }
    return credentials;
}
Also used : Credentials(org.ovirt.engine.core.sso.utils.Credentials)

Example 9 with Credentials

use of org.ovirt.engine.core.sso.utils.Credentials in project ovirt-engine by oVirt.

the class OpenIdTokenServlet method issueTokenForPasswd.

protected void issueTokenForPasswd(HttpServletRequest request, HttpServletResponse response, String scope) throws Exception {
    log.debug("Entered issueTokenForPasswd");
    Credentials credentials = null;
    try {
        String[] clientIdAndSecret = SsoUtils.getClientIdClientSecret(request);
        SsoUtils.validateClientRequest(request, clientIdAndSecret[0], clientIdAndSecret[1], scope, null);
        String clientId = clientIdAndSecret[0];
        String clientSecret = clientIdAndSecret[1];
        credentials = getCredentials(request);
        SsoSession ssoSession = handleIssueTokenForPasswd(request, scope, credentials);
        log.debug("Sending json response");
        SsoUtils.sendJsonData(response, buildResponse(request, ssoSession, clientId, clientSecret));
    } catch (AuthenticationException ex) {
        String profile = "N/A";
        if (credentials != null) {
            profile = credentials.getProfile() == null ? "N/A" : credentials.getProfile();
        }
        throw new AuthenticationException(String.format(ssoContext.getLocalizationUtils().localize(SsoConstants.APP_ERROR_CANNOT_AUTHENTICATE_USER_IN_DOMAIN, (Locale) request.getAttribute(SsoConstants.LOCALE)), credentials == null ? "N/A" : credentials.getUsername(), profile, ex.getMessage()));
    }
}
Also used : Locale(java.util.Locale) AuthenticationException(org.ovirt.engine.core.sso.utils.AuthenticationException) Credentials(org.ovirt.engine.core.sso.utils.Credentials) SsoSession(org.ovirt.engine.core.sso.utils.SsoSession)

Aggregations

Credentials (org.ovirt.engine.core.sso.utils.Credentials)9 AuthenticationException (org.ovirt.engine.core.sso.utils.AuthenticationException)6 Locale (java.util.Locale)4 SsoSession (org.ovirt.engine.core.sso.utils.SsoSession)4 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 Cookie (javax.servlet.http.Cookie)1 OAuthException (org.ovirt.engine.core.sso.utils.OAuthException)1