Package javax.ws.rs

Examples of javax.ws.rs.NotAuthorizedException


            } else switch (status) {
                case BAD_REQUEST:
                    webAppException = new BadRequestException(response);
                    break;
                case UNAUTHORIZED:
                    webAppException = new NotAuthorizedException(response);
                    break;
                case FORBIDDEN:
                    webAppException = new ForbiddenException(response);
                    break;
                case NOT_FOUND:
View Full Code Here


        }
    }
   
    protected Element readToken(Message message, String assertion) {
        if (assertion == null) {
            throw new NotAuthorizedException(errorResponse());
        }
        try {
            byte[] deflatedToken = Base64UrlUtility.decode(assertion);
            InputStream is = new ByteArrayInputStream(deflatedToken);
            return readToken(message, is);
        } catch (Base64Exception ex) {
            throw new NotAuthorizedException(errorResponse());
        }        
    }
View Full Code Here

       
        // This is specific to OAuth2 path
        // Introduce SAMLOAuth2Validator to be reused between auth and grant handlers
        Subject subject = SAMLUtils.getSubject(message, wrapper);
        if (subject.getName() == null) {
            throw new NotAuthorizedException(errorResponse())
        }
       
        if (clientId != null && !clientId.equals(subject.getName())) {
            //TODO:  Attempt to map client_id to subject.getName()
            throw new NotAuthorizedException(errorResponse());
        }
        samlOAuthValidator.validate(message, wrapper);
        message.put(OAuthConstants.CLIENT_ID, subject.getName());
    }
View Full Code Here

       
        Form form = readFormData(message);   
        String assertionType = form.getData().getFirst(Constants.CLIENT_AUTH_ASSERTION_TYPE);
        String decodedAssertionType = assertionType != null ? HttpUtils.urlDecode(assertionType) : null;
        if (decodedAssertionType == null || !Constants.CLIENT_AUTH_SAML2_BEARER.equals(decodedAssertionType)) {
            throw new NotAuthorizedException(errorResponse());
        }
        String assertion = form.getData().getFirst(Constants.CLIENT_AUTH_ASSERTION_PARAM);
       
        Element token = readToken(message, assertion);        
        String clientId = form.getData().getFirst(OAuthConstants.CLIENT_ID);
        validateToken(message, token, clientId);
       
       
        form.getData().remove(OAuthConstants.CLIENT_ID);
        form.getData().remove(Constants.CLIENT_AUTH_ASSERTION_PARAM);
        form.getData().remove(Constants.CLIENT_AUTH_ASSERTION_TYPE);
       
        // restore input stream
        try {
            FormUtils.restoreForm(provider, form, message);
        } catch (Exception ex) {
            throw new NotAuthorizedException(errorResponse());
        }
        return null;
    }
View Full Code Here

   
    private Form readFormData(Message message) {
        try {
            return FormUtils.readForm(provider, message);
        } catch (Exception ex) {
            throw new NotAuthorizedException(errorResponse());   
        }
    }
View Full Code Here

                client = getAndValidateClient(authInfo[0], authInfo[1]);
            }
        }
       
        if (client == null) {
            throw new NotAuthorizedException(Response.status(401).build());
        }
        return client;
    }
View Full Code Here

    // Get the Client and check the id and secret
    private Client getAndValidateClient(String clientId, String clientSecret) {
        Client client = getClient(clientId);
        if (clientSecret == null || !client.getClientId().equals(clientId)
            || !client.getClientSecret().equals(clientSecret)) {
            throw new NotAuthorizedException(Response.status(401).build());
        }
        return client;
    }
View Full Code Here

     * @throws WebApplicationException with Status 401 if not authenticated
     */
    public static OAuthContext getContext(final MessageContext mc) {
        final OAuthContext oauth = mc.getContent(OAuthContext.class);
        if ((oauth == null) || (oauth.getSubject() == null) || (oauth.getSubject().getLogin() == null)) {
            throw new NotAuthorizedException(Response.status(401).build());
        }
        return oauth;
    }
View Full Code Here

    public static String[] getBasicAuthParts(String data) {
        String authDecoded = null;
        try {
            authDecoded = new String(Base64Utility.decode(data));
        } catch (Exception ex) {
            throw new NotAuthorizedException(ex);
        }
        String authInfo[] = authDecoded.split(":");
        if (authInfo.length == 2) {
            return authInfo;
        }
        throw new NotAuthorizedException(Response.status(401).build());
    }
View Full Code Here

        }
        if (sb.length() > 0) {
            rb.header(HttpHeaders.WWW_AUTHENTICATE, sb.toString());
        }
        Response r = rb.build();
        throw new NotAuthorizedException(r);
    }
View Full Code Here

TOP

Related Classes of javax.ws.rs.NotAuthorizedException

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.