Search in sources :

Example 1 with ConsumerRegistration

use of oauth2.common.ConsumerRegistration in project tesb-rt-se by Talend.

the class ThirdPartyRegistrationService method register.

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/")
public ConsumerRegistration register(MultipartBody body) {
    String appName = body.getAttachmentObject("appName", String.class);
    String appURI = body.getAttachmentObject("appURI", String.class);
    String appRedirectURI = body.getAttachmentObject("appRedirectURI", String.class);
    String appDesc = body.getAttachmentObject("appDescription", String.class);
    URI logoURI = null;
    Attachment att = body.getAttachment("appLogo");
    if (att != null) {
        InputStream logoStream = att.getObject(InputStream.class);
        CachedOutputStream cos = new CachedOutputStream();
        try {
            IOUtils.copy(logoStream, cos);
            appLogos.put(appName.toLowerCase(), cos);
            UriBuilder ub = uriInfo.getAbsolutePathBuilder();
            ub.path("logo").path(appName.toLowerCase());
            ContentDisposition cd = att.getContentDisposition();
            if (cd != null && cd.getParameter("filename") != null) {
                ub.path(cd.getParameter("filename"));
            }
            logoURI = ub.build();
        } catch (IOException ex) {
        // ignore
        }
    }
    String clientId = generateClientId(appName, appURI);
    String clientSecret = generateClientSecret();
    Client newClient = new Client(clientId, clientSecret, true, appName, appURI);
    newClient.setApplicationDescription(appDesc);
    newClient.setApplicationLogoUri(logoURI.toString());
    newClient.setRedirectUris(Collections.singletonList(appRedirectURI));
    manager.registerClient(newClient);
    return new ConsumerRegistration(clientId, clientSecret);
}
Also used : ContentDisposition(org.apache.cxf.jaxrs.ext.multipart.ContentDisposition) InputStream(java.io.InputStream) ConsumerRegistration(oauth2.common.ConsumerRegistration) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) Client(org.apache.cxf.rs.security.oauth2.common.Client) URI(java.net.URI) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with ConsumerRegistration

use of oauth2.common.ConsumerRegistration in project tesb-rt-se by Talend.

the class ThirdPartyRegistrationService method registerForm.

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/")
public ConsumerRegistration registerForm(@FormParam("appName") String appName, @FormParam("appURI") String appURI, @FormParam("appRedirectURI") String appRedirectURI) {
    String clientId = generateClientId(appName, appURI);
    String clientSecret = generateClientSecret();
    Client newClient = new Client(clientId, clientSecret, true, appName, appURI);
    newClient.setRedirectUris(Collections.singletonList(appRedirectURI));
    manager.registerClient(newClient);
    return new ConsumerRegistration(clientId, clientSecret);
}
Also used : ConsumerRegistration(oauth2.common.ConsumerRegistration) Client(org.apache.cxf.rs.security.oauth2.common.Client) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 ConsumerRegistration (oauth2.common.ConsumerRegistration)2 Client (org.apache.cxf.rs.security.oauth2.common.Client)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)1 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)1 ContentDisposition (org.apache.cxf.jaxrs.ext.multipart.ContentDisposition)1