Example usage for javax.naming AuthenticationException getExplanation

List of usage examples for javax.naming AuthenticationException getExplanation

Introduction

In this page you can find the example usage for javax.naming AuthenticationException getExplanation.

Prototype

public String getExplanation() 

Source Link

Document

Retrieves the explanation associated with this exception.

Usage

From source file:org.restlet.ext.oauth.AccessTokenServerResource.java

/**
 * Executes the "password" flow. (4.3. Resource Owner Password Credentials
 * Grant)/* w  ww  . j  a va 2 s .  c o  m*/
 * 
 * @param params
 * @return
 * @throws OAuthException
 * @throws JSONException
 */
private Representation doPasswordFlow(Form params) throws OAuthException, JSONException {
    Object users = getContext().getAttributes().get(ResourceOwnerManager.class.getName());
    if (users == null) {
        throw new OAuthException(OAuthError.unsupported_grant_type, "'password' flow is not supported.", null);
    }

    // The flow require authenticated client.
    Client client = getAuthenticatedClient();
    if (client == null) {
        // XXX: 'password' flow MAY use the public client. (3.2.1 Client
        // Authentication)
        client = getClient(params);
    }

    ensureGrantTypeAllowed(client, GrantType.password);

    String username = getUsername(params);
    String password = getPassword(params);
    String identifier;

    try {
        identifier = ((ResourceOwnerManager) users).authenticate(username, password.toCharArray());
    } catch (AuthenticationException ex) {
        throw new OAuthException(OAuthError.invalid_grant, ex.getExplanation(), null);
    }

    String[] requestedScope = getScope(params);

    // Generate token for the resource owner.
    Token token = tokens.generateToken(client, identifier, requestedScope);

    return responseTokenRepresentation(token, requestedScope);
}