Search in sources :

Example 1 with Client

use of com.authlete.common.dto.Client in project authlete-java-common by authlete.

the class CLI method executeGetClientApi.

private void executeGetClientApi(AuthleteApi api, Settings settings) {
    String value = getFirstKeyOrExit(settings.parameters, "getClient", "clientId");
    long clientId;
    try {
        clientId = Long.parseLong(value);
    } catch (Exception e) {
        showErrorAndExit("The value of {clientId} is invalid.");
        return;
    }
    // Get the client information.
    verbose(settings, "Calling getClient(clientId=%d)", clientId);
    Client client = api.getClient(clientId);
    // Dump the client information.
    System.out.println(Utils.toJson(client, true));
}
Also used : Client(com.authlete.common.dto.Client) AuthleteApiException(com.authlete.common.api.AuthleteApiException)

Example 2 with Client

use of com.authlete.common.dto.Client in project java-oauth-server by authlete.

the class ObbUtils method isObbDynamicClient.

/**
 * Judge whether the client identified by the client ID is a client that
 * has been dynamically registered for Open Banking Brasil.
 *
 * @param api
 *         An implementation of {@link AuthleteApi}.
 *
 * @param clientId
 *         A client ID.
 *
 * @return
 *         {@code true} if the client identified by the client ID is a
 *         client that has been dynamically registered for Open Banking
 *         Brasil.
 *
 * @see <a href="https://openbanking-brasil.github.io/specs-seguranca/open-banking-brasil-dynamic-client-registration-1_ID1.html"
 *      >Open Banking Brasil Financial-grade API Dynamic Client Registration 1.0 Implementers Draft 1</a>
 */
@SuppressWarnings("unchecked")
public static boolean isObbDynamicClient(AuthleteApi api, String clientId) {
    Client client;
    try {
        // Get information about the client identified by the client ID
        // by calling Authlete's /api/client/get/{clientIdentifier} API.
        client = api.getClient(clientId);
    } catch (Exception e) {
        // The API call failed.
        return false;
    }
    if (client == null) {
        // Client information is not available.
        return false;
    }
    // Custom metadata of the client. This implementation assumes that
    // a client is registered with some client metadata.
    String json = client.getCustomMetadata();
    if (json == null) {
        // The client does not have custom metadata.
        return false;
    }
    Map<String, Object> metadata;
    try {
        // Parse the string as JSON.
        metadata = Utils.fromJson(json, Map.class);
    } catch (Exception e) {
        // Failed to parse the string as JSON.
        return false;
    }
    // If the custom metadata does not contain "software_roles".
    if (!metadata.containsKey("software_roles")) {
        return false;
    }
    return true;
}
Also used : Client(com.authlete.common.dto.Client) Map(java.util.Map) AuthleteApiException(com.authlete.common.api.AuthleteApiException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 3 with Client

use of com.authlete.common.dto.Client in project java-oauth-server by authlete.

the class AuthorizationDecisionEndpoint method post.

/**
 * Process a request from the form in the authorization page.
 *
 * <p>
 * NOTE:
 * A better implementation would re-display the authorization page
 * when the pair of login ID and password is wrong, but this
 * implementation does not do it for brevity. A much better
 * implementation would check the login credentials by Ajax.
 * </p>
 *
 * @param request
 *         A request from the form in the authorization page.
 *
 * @param parameters
 *         Request parameters.
 *
 * @return
 *         A response to the user agent. Basically, the response
 *         will trigger redirection to the client's redirect
 *         endpoint.
 */
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response post(@Context HttpServletRequest request, MultivaluedMap<String, String> parameters) {
    // Get the existing session.
    HttpSession session = getSession(request);
    // Retrieve some variables from the session. See the implementation
    // of AuthorizationRequestHandlerSpiImpl.getAuthorizationPage().
    Params params = (Params) takeAttribute(session, "params");
    String[] acrs = (String[]) takeAttribute(session, "acrs");
    Client client = (Client) takeAttribute(session, "client");
    User user = getUser(session, parameters);
    Date authTime = (Date) session.getAttribute("authTime");
    // Implementation of AuthorizationDecisionHandlerSpi.
    AuthorizationDecisionHandlerSpi spi = new AuthorizationDecisionHandlerSpiImpl(parameters, user, authTime, params.getIdTokenClaims(), acrs, client);
    // Handle the end-user's decision.
    return handle(AuthleteApiFactory.getDefaultApi(), spi, params);
}
Also used : User(com.authlete.common.types.User) HttpSession(javax.servlet.http.HttpSession) Params(com.authlete.jaxrs.AuthorizationDecisionHandler.Params) AuthorizationDecisionHandlerSpi(com.authlete.jaxrs.spi.AuthorizationDecisionHandlerSpi) Client(com.authlete.common.dto.Client) Date(java.util.Date) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

Client (com.authlete.common.dto.Client)3 AuthleteApiException (com.authlete.common.api.AuthleteApiException)2 User (com.authlete.common.types.User)1 Params (com.authlete.jaxrs.AuthorizationDecisionHandler.Params)1 AuthorizationDecisionHandlerSpi (com.authlete.jaxrs.spi.AuthorizationDecisionHandlerSpi)1 Date (java.util.Date)1 Map (java.util.Map)1 HttpSession (javax.servlet.http.HttpSession)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1