Package javax.ws.rs

Examples of javax.ws.rs.BadRequestException


     */
    protected void checkTransportSecurity() { 
        if (!mc.getSecurityContext().isSecure()) {
            LOG.warning("Unsecure HTTP, Transport Layer Security is recommended");
            if (blockUnsecureRequests) {
                throw new BadRequestException();   
            }
        }
    }
View Full Code Here


    protected void reportInvalidRequestError(OAuthError entity, MediaType mt) {
        ResponseBuilder rb = Response.status(400);
        if (mt != null) {
            rb.type(mt);
        }
        throw new BadRequestException(rb.entity(entity).build());
    }
View Full Code Here

        // Make sure the end user has authenticated, check if HTTPS is used
        SecurityContext securityContext = getAndValidateSecurityContext();
       
        // Make sure the session is valid
        if (!compareRequestAndSessionTokens(params.getFirst(OAuthConstants.SESSION_AUTHENTICITY_TOKEN))) {
            throw new BadRequestException();    
        }
        //TODO: additionally we can check that the Principal that got authenticated
        // in startAuthorization is the same that got authenticated in completeAuthorization
       
        Client client = getClient(params);
View Full Code Here

    }
   
    protected void throwFault(String error, Exception ex) {
        LOG.warning(error);
        Response response = Response.status(400).entity(error).build();
        throw ex != null ? new BadRequestException(response, ex) : new BadRequestException(response);
    }
View Full Code Here

    }
   
    private RequestState processRelayState(String relayState) {
        if (relayState == null) {
            reportError("MISSING_RELAY_STATE");
            throw new BadRequestException();
        }
        if (relayState.getBytes().length < 0 || relayState.getBytes().length > 80) {
            reportError("INVALID_RELAY_STATE");
            throw new BadRequestException();
        }
        RequestState requestState = getStateProvider().removeRequestState(relayState);
        if (requestState == null) {
            reportError("MISSING_REQUEST_STATE");
            throw new WebApplicationException(400);
        }
        if (isStateExpired(requestState.getCreatedAt(), 0)) {
            reportError("EXPIRED_REQUEST_STATE");
            throw new BadRequestException();
        }
        return requestState;
    }
View Full Code Here

        boolean postBinding,
        String samlResponse
    ) {
        if (StringUtils.isEmpty(samlResponse)) {
            reportError("MISSING_SAML_RESPONSE");
            throw new BadRequestException();
        }
       
        String samlResponseDecoded = samlResponse;
        /*
        // URL Decoding only applies for the re-direct binding
        if (!postBinding) {
            try {
                samlResponseDecoded = URLDecoder.decode(samlResponse, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new BadRequestException();
            }
        }
        */
        InputStream tokenStream = null;
        if (isSupportBase64Encoding()) {
            try {
                byte[] deflatedToken = Base64Utility.decode(samlResponseDecoded);
                tokenStream = !postBinding && isSupportDeflateEncoding()
                    ? new DeflateEncoderDecoder().inflateToken(deflatedToken)
                    : new ByteArrayInputStream(deflatedToken);
            } catch (Base64Exception ex) {
                throw new BadRequestException(ex);
            } catch (DataFormatException ex) {
                throw new BadRequestException(ex);
            }
        } else {
            try {
                tokenStream = new ByteArrayInputStream(samlResponseDecoded.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException ex) {
                throw new BadRequestException(ex);
            }
        }
       
        Document responseDoc = null;
        try {
            responseDoc = StaxUtils.read(new InputStreamReader(tokenStream, "UTF-8"));
        } catch (Exception ex) {
            throw new WebApplicationException(400);
        }
       
        LOG.fine("Received response: " + DOM2Writer.nodeToString(responseDoc.getDocumentElement()));
       
        XMLObject responseObject = null;
        try {
            responseObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
        } catch (WSSecurityException ex) {
            throw new BadRequestException(ex);
        }
        if (!(responseObject instanceof org.opensaml.saml2.core.Response)) {
            throw new BadRequestException();
        }
        return (org.opensaml.saml2.core.Response)responseObject;
    }
View Full Code Here

            SAMLProtocolResponseValidator protocolValidator = new SAMLProtocolResponseValidator();
            protocolValidator.validateSamlResponse(samlResponse, getSignatureCrypto(), getCallbackHandler());
        } catch (WSSecurityException ex) {
            LOG.log(Level.FINE, ex.getMessage(), ex);
            reportError("INVALID_SAML_RESPONSE");
            throw new BadRequestException();
        }
    }
View Full Code Here

            ssoResponseValidator.setReplayCache(getReplayCache());

            return ssoResponseValidator.validateSamlResponse(samlResponse, postBinding);
        } catch (WSSecurityException ex) {
            reportError("INVALID_SAML_RESPONSE");
            throw new BadRequestException(ex);
        }
    }
View Full Code Here

                reportError("INVALID_TARGET_URI");
            }
        } else {
            reportError("MISSING_TARGET_URI");
        }
        throw new BadRequestException();
    }
View Full Code Here

        try {
            @SuppressWarnings("unchecked")
            T result = (T)format.unmarshal(null, is);
            return result;
        } catch (Exception ex) {
            throw new BadRequestException(ex);
        }
    }
View Full Code Here

TOP

Related Classes of javax.ws.rs.BadRequestException

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.