Search in sources :

Example 1 with ClientAssociation

use of org.gluu.oxtrust.model.association.ClientAssociation in project oxTrust by GluuFederation.

the class ClientAssociationWebService method getAssociatedPersons.

@Path("/Client/{cid}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAssociatedPersons(@HeaderParam("Authorization") String authorization, @PathParam("cid") String cid) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        log.info("getting the client");
        OxAuthClient client = clientService.getClientByInum(cid);
        if (client == null) {
            // sets HTTP status code 404 Not Found
            return getErrorResponse("Resource " + cid + " not found", Response.Status.NOT_FOUND.getStatusCode());
        }
        log.info("mapping client attributes");
        ClientAssociation clientAssociation = MapperUtil.map(client, null);
        log.info("getting URL");
        URI location = new URI("/ClientAssociation/Client/" + cid);
        log.info("returning response");
        return Response.ok(clientAssociation).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Exception: ", ex);
        return getErrorResponse("Resource " + cid + " not found", Response.Status.NOT_FOUND.getStatusCode());
    } catch (Exception ex) {
        log.error("Exception: ", ex);
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : Response(javax.ws.rs.core.Response) OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) ClientAssociation(org.gluu.oxtrust.model.association.ClientAssociation) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ClientAssociation

use of org.gluu.oxtrust.model.association.ClientAssociation in project oxTrust by GluuFederation.

the class MapperUtil method map.

/**
 * Maps Clients association attribute with ClientAssociation
 *
 * @param source
 * @param destination
 * @return
 */
public static ClientAssociation map(OxAuthClient source, ClientAssociation destination) {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        destination = new ClientAssociation();
    }
    destination.setEntryAssociation(source.getInum());
    destination.setUserAssociations(source.getAssociatedPersons());
    return destination;
}
Also used : ClientAssociation(org.gluu.oxtrust.model.association.ClientAssociation)

Aggregations

ClientAssociation (org.gluu.oxtrust.model.association.ClientAssociation)2 URI (java.net.URI)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)1 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)1