Search in sources :

Example 1 with Parameter

use of org.restlet.data.Parameter in project OpenAM by OpenRock.

the class OAuth2Representation method toRepresentation.

/**
     * Converts the authorization token into a representation to send back to the user agent.
     *
     * @param context The Restlet context.
     * @param request The Restlet request.
     * @param response The Restlet response.
     * @param authorizationToken The authorization token.
     * @param redirectUri The redirect uri.
     * @return The representation to send to the user agent.
     */
Representation toRepresentation(Context context, Request request, Response response, AuthorizationToken authorizationToken, String redirectUri) {
    final Form tokenForm = toForm(authorizationToken);
    final Reference redirectReference = new Reference(redirectUri);
    if (authorizationToken.isFragment()) {
        redirectReference.setFragment(tokenForm.getQueryString());
    } else {
        final Iterator<Parameter> iter = tokenForm.iterator();
        while (iter.hasNext()) {
            redirectReference.addQueryParameter(iter.next());
        }
    }
    if (isFormPostRequest(requestFactory.create(request))) {
        return getFormPostRepresentation(context, authorizationToken, redirectReference.toString());
    }
    final Redirector dispatcher = new Redirector(context, redirectReference.toString(), Redirector.MODE_CLIENT_FOUND);
    dispatcher.handle(request, response);
    return response == null ? null : response.getEntity();
}
Also used : Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) Parameter(org.restlet.data.Parameter) Redirector(org.restlet.routing.Redirector)

Example 2 with Parameter

use of org.restlet.data.Parameter in project OpenAM by OpenRock.

the class OpenAMResourceOwnerSessionValidator method removeLoginPrompt.

/**
     * Removes "login" from prompt query parameter.
     *
     * This needs to be done before redirecting the user to login so that an infinite redirect loop is avoided.
     */
private void removeLoginPrompt(Request req) {
    Form query = req.getResourceRef().getQueryAsForm();
    Parameter param = query.getFirst(PROMPT);
    if (param != null && param.getValue() != null) {
        String newValue = param.getValue().toLowerCase().replace(OpenIdPrompt.PROMPT_LOGIN, "").trim();
        param.setValue(newValue);
    }
    req.getResourceRef().setQuery(query.getQueryString());
}
Also used : Form(org.restlet.data.Form) Parameter(org.restlet.data.Parameter)

Example 3 with Parameter

use of org.restlet.data.Parameter in project camel by apache.

the class RestletComponent method addServerIfNecessary.

protected void addServerIfNecessary(RestletEndpoint endpoint) throws Exception {
    String key = buildKey(endpoint);
    Server server;
    synchronized (servers) {
        server = servers.get(key);
        if (server == null) {
            server = createServer(endpoint);
            component.getServers().add(server);
            // Add any Restlet server parameters that were included
            Series<Parameter> params = server.getContext().getParameters();
            if ("https".equals(endpoint.getProtocol())) {
                SSLContextParameters scp = endpoint.getSslContextParameters();
                if (endpoint.getSslContextParameters() == null) {
                    throw new InvalidParameterException("Need to specify the SSLContextParameters option here!");
                }
                setupServerWithSSLContext(params, scp);
            }
            if (getControllerDaemon() != null) {
                params.add("controllerDaemon", getControllerDaemon().toString());
            }
            if (getControllerSleepTimeMs() != null) {
                params.add("controllerSleepTimeMs", getControllerSleepTimeMs().toString());
            }
            if (getInboundBufferSize() != null) {
                params.add("inboundBufferSize", getInboundBufferSize().toString());
            }
            if (getMinThreads() != null) {
                params.add("minThreads", getMinThreads().toString());
            }
            if (getMaxThreads() != null) {
                params.add("maxThreads", getMaxThreads().toString());
            }
            if (getLowThreads() != null) {
                params.add("lowThreads", getLowThreads().toString());
            }
            if (getMaxQueued() != null) {
                params.add("maxQueued", getMaxQueued().toString());
            }
            if (getMaxConnectionsPerHost() != null) {
                params.add("maxConnectionsPerHost", getMaxConnectionsPerHost().toString());
            }
            if (getMaxTotalConnections() != null) {
                params.add("maxTotalConnections", getMaxTotalConnections().toString());
            }
            if (getOutboundBufferSize() != null) {
                params.add("outboundBufferSize", getOutboundBufferSize().toString());
            }
            if (getPersistingConnections() != null) {
                params.add("persistingConnections", getPersistingConnections().toString());
            }
            if (getPipeliningConnections() != null) {
                params.add("pipeliningConnections", getPipeliningConnections().toString());
            }
            if (getThreadMaxIdleTimeMs() != null) {
                params.add("threadMaxIdleTimeMs", getThreadMaxIdleTimeMs().toString());
            }
            if (getUseForwardedForHeader() != null) {
                params.add("useForwardedForHeader", getUseForwardedForHeader().toString());
            }
            if (getReuseAddress() != null) {
                params.add("reuseAddress", getReuseAddress().toString());
            }
            LOG.debug("Setting parameters: {} to server: {}", params, server);
            server.getContext().setParameters(params);
            servers.put(key, server);
            LOG.debug("Added server: {}", key);
            server.start();
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Server(org.restlet.Server) Parameter(org.restlet.data.Parameter) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 4 with Parameter

use of org.restlet.data.Parameter in project qi4j-sdk by Qi4j.

the class FormResponseWriter method writeResponse.

@Override
public boolean writeResponse(final Object result, final Response response) throws ResourceException {
    if (result instanceof Form) {
        MediaType type = getVariant(response.getRequest(), ENGLISH, supportedMediaTypes).getMediaType();
        if (MediaType.APPLICATION_JSON.equals(type)) {
            JSONObject json = new JSONObject();
            Form form = (Form) result;
            try {
                for (Parameter parameter : form) {
                    String value = parameter.getValue();
                    if (value == null) {
                        json.put(parameter.getName(), JSONObject.NULL);
                    } else {
                        json.put(parameter.getName(), value);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            StringRepresentation representation = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON);
            response.setEntity(representation);
            return true;
        } else if (MediaType.TEXT_HTML.equals(type)) {
            Representation rep = new WriterRepresentation(MediaType.TEXT_HTML) {

                @Override
                public void write(Writer writer) throws IOException {
                    Map<String, Object> root = new HashMap<String, Object>();
                    root.put("request", response.getRequest());
                    root.put("response", response);
                    root.put("result", result);
                    try {
                        Template formHtmlTemplate = cfg.getTemplate("form.htm");
                        formHtmlTemplate.process(root, writer);
                    } catch (TemplateException e) {
                        throw new IOException(e);
                    }
                }
            };
            response.setEntity(rep);
            return true;
        }
    }
    return false;
}
Also used : Form(org.restlet.data.Form) TemplateException(freemarker.template.TemplateException) JSONException(org.json.JSONException) StringRepresentation(org.restlet.representation.StringRepresentation) Representation(org.restlet.representation.Representation) WriterRepresentation(org.restlet.representation.WriterRepresentation) IOException(java.io.IOException) Template(freemarker.template.Template) JSONObject(org.json.JSONObject) StringRepresentation(org.restlet.representation.StringRepresentation) WriterRepresentation(org.restlet.representation.WriterRepresentation) MediaType(org.restlet.data.MediaType) Parameter(org.restlet.data.Parameter) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Writer(java.io.Writer)

Example 5 with Parameter

use of org.restlet.data.Parameter in project OpenAM by OpenRock.

the class OpenAMResourceOwnerSessionValidator method alterMaxAge.

/**
     * After we are sent to authN we will come back to authZ, next time make sure
     * we don't fail to max_age again (in case it's only a few seconds),
     * otherwise we'll loop forever and ever...
     */
private void alterMaxAge(OAuth2Request req) {
    final Request request = req.getRequest();
    Form query = request.getResourceRef().getQueryAsForm();
    Parameter param = query.getFirst(MAX_AGE);
    if (param == null) {
        param = new Parameter(MAX_AGE, CONFIRMED_MAX_AGE);
        query.add(param);
    } else {
        param.setValue(CONFIRMED_MAX_AGE);
    }
    request.getResourceRef().setQuery(query.getQueryString());
}
Also used : Form(org.restlet.data.Form) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) Parameter(org.restlet.data.Parameter)

Aggregations

Parameter (org.restlet.data.Parameter)5 Form (org.restlet.data.Form)4 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 InvalidParameterException (java.security.InvalidParameterException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SSLContextParameters (org.apache.camel.util.jsse.SSLContextParameters)1 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Request (org.restlet.Request)1 Server (org.restlet.Server)1 MediaType (org.restlet.data.MediaType)1 Reference (org.restlet.data.Reference)1 Representation (org.restlet.representation.Representation)1 StringRepresentation (org.restlet.representation.StringRepresentation)1