Package org.apache.amber.oauth2.common.exception

Examples of org.apache.amber.oauth2.common.exception.OAuthRuntimeException


            .setRedirectURL(CommonExt.APP_REDIRECT_URI)
            .buildBodyMessage();

        OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new URLConnectionClient());
        try {
            OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertNotNull(e.getError());
        }
View Full Code Here


    public Response register(@Context HttpServletRequest request) throws OAuthSystemException {


        OAuthServerRegistrationRequest oauthRequest = null;
        try {
            oauthRequest = new OAuthServerRegistrationRequest(new JSONHttpServletRequestWrapper(request));
            oauthRequest.discover();
            oauthRequest.getClientName();
            oauthRequest.getClientUrl();
            oauthRequest.getClientDescription();
            oauthRequest.getRedirectURI();
View Full Code Here

    @Consumes("application/json")
    @Produces("application/json")
    public Response register(@Context HttpServletRequest request) throws OAuthSystemException {


        OAuthServerRegistrationRequest oauthRequest = null;
        try {
            oauthRequest = new OAuthServerRegistrationRequest(new JSONHttpServletRequestWrapper(request));
            oauthRequest.discover();
            oauthRequest.getClientName();
            oauthRequest.getClientUrl();
            oauthRequest.getClientDescription();
            oauthRequest.getRedirectURI();

            OAuthResponse response = OAuthServerRegistrationResponse
                .status(HttpServletResponse.SC_OK)
                .setClientId(CommonExt.CLIENT_ID)
                .setClientSecret(CommonExt.CLIENT_SECRET)
View Full Code Here

    public Response get(@Context HttpServletRequest request) throws OAuthSystemException {

        try {

            // Make the OAuth Request out of this request
            OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request,
                ParameterStyle.HEADER);

            // Get the access token
            String accessToken = oauthRequest.getAccessToken();

            // Validate the access token
            if (!Common.ACCESS_TOKEN_VALID.equals(accessToken)) {

                // Return the OAuth error message
View Full Code Here

    public Response get(@Context HttpServletRequest request) throws OAuthSystemException {

        try {

            // Make the OAuth Request out of this request
            OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request,
                ParameterStyle.QUERY);

            // Get the access token
            String accessToken = oauthRequest.getAccessToken();

            // Validate the access token
            if (!Common.ACCESS_TOKEN_VALID.equals(accessToken)) {

                // Return the OAuth error message
View Full Code Here

    public Response get(@Context HttpServletRequest request) throws OAuthSystemException {

        try {

            // Make the OAuth Request out of this request and validate it
            OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request,
                ParameterStyle.BODY);

            // Get the access token
            String accessToken = oauthRequest.getAccessToken();

            // Check if the token is valid
            if (Common.ACCESS_TOKEN_VALID.equals(accessToken)) {

                // Return the resource
View Full Code Here

            }

            return Collections.unmodifiableMap(parameters);
        } catch (JSONException e) {
            log.error("Dynamic client registration error: ", e);
            throw new OAuthRuntimeException("OAuth server error");
        }
    }
View Full Code Here

                body = new JSONObject(jsonString);
            } catch (JSONException e) {
                log.error("Cannot decode request body as a JSON: ", e);
            } catch (Exception e) {
                log.error("Dynamic client registration error: ", e);
                throw new OAuthRuntimeException("OAuth server error");
            }
        }
    }
View Full Code Here

            final JSONTokener x = new JSONTokener(body);
            char c;
            String key;

            if (x.nextClean() != '{') {
                throw new OAuthRuntimeException(format("String '%s' is not a valid JSON object representation, a JSON object text must begin with '{'",
                                                       body));
            }
            for (;;) {
                c = x.nextClean();
                switch (c) {
                case 0:
                    throw new OAuthRuntimeException(format("String '%s' is not a valid JSON object representation, a JSON object text must end with '}'",
                                                           body));
                case '}':
                    return Collections.unmodifiableMap(parameters);
                default:
                    x.back();
                    key = x.nextValue().toString();
                }

                /*
                 * The key is followed by ':'. We will also tolerate '=' or '=>'.
                 */
                c = x.nextClean();
                if (c == '=') {
                    if (x.next() != '>') {
                        x.back();
                    }
                } else if (c != ':') {
                    throw new OAuthRuntimeException(format("String '%s' is not a valid JSON object representation, expected a ':' after the key '%s'",
                                                           body, key));
                }
                Object value = x.nextValue();

                // guard from null values
                if (value != null) {
                    if (value instanceof JSONArray) { // only plain simple arrays in this version
                        JSONArray array = (JSONArray) value;
                        String[] values = new String[array.length()];
                        for (int i = 0; i < array.length(); i++) {
                            values[i] = String.valueOf(array.get(i));
                        }
                        parameters.put(key, values);
                    } else {
                        parameters.put(key, new String[]{ String.valueOf(value) });
                    }
                }

                /*
                 * Pairs are separated by ','. We will also tolerate ';'.
                 */
                switch (x.nextClean()) {
                case ';':
                case ',':
                    if (x.nextClean() == '}') {
                        return Collections.unmodifiableMap(parameters);
                    }
                    x.back();
                    break;
                case '}':
                    return Collections.unmodifiableMap(parameters);
                default:
                    throw new OAuthRuntimeException(format("String '%s' is not a valid JSON object representation, Expected a ',' or '}",
                                                           body));
                }
            }
        }

View Full Code Here

            bodyRead = true;
            return OAuthUtils.saveStreamAsString(inputStream);
        } catch (Exception e) {
            log.error("Dynamic client registration error: ", e);
            throw new OAuthRuntimeException("OAuth server error");
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.amber.oauth2.common.exception.OAuthRuntimeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.