Package javax.ws.rs

Examples of javax.ws.rs.NotAuthorizedException


    protected void throwFault(String error, Exception ex) {
        // TODO: get bundle resource message once this filter is moved
        // to rt/rs/security
        LOG.warning(error);
        Response response = Response.status(401).entity(error).build();
        throw ex != null ? new NotAuthorizedException(ex, response) : new NotAuthorizedException(response);
    }
View Full Code Here


   
    private SecurityContext getAndValidateSecurityContext() {
        SecurityContext securityContext = 
            (SecurityContext)getMessageContext().get(SecurityContext.class.getName());
        if (securityContext == null || securityContext.getUserPrincipal() == null) {
            throw new NotAuthorizedException(Response.status(401).build());
        }
        checkTransportSecurity();
        return securityContext;
    }
View Full Code Here

                builder.header("oauth_problem", text);
            } else {
                builder.entity(e.getMessage());   
            }
        }
        throw new NotAuthorizedException(builder.build());
    }
View Full Code Here

       
        List<String> authHeaders = messageContext.getHttpHeaders()
            .getRequestHeader(HttpHeaders.AUTHORIZATION);
        if (authHeaders.size() != 1) {
            LOG.fine("No Authorization header is available");
            throw new NotAuthorizedException(getFaultResponse());
        }
        String[] authPair = StringUtils.split(authHeaders.get(0), " ");
        if (authPair.length != 2 || !NEGOTIATE_SCHEME.equalsIgnoreCase(authPair[0])) {
            LOG.fine("Negotiate Authorization scheme is expected");
            throw new NotAuthorizedException(getFaultResponse());
        }
               
        byte[] serviceTicket = getServiceTicket(authPair[1]);
       
        try {
            Subject serviceSubject = loginAndGetSubject();
           
            GSSContext gssContext = createGSSContext();

            Subject.doAs(serviceSubject, new ValidateServiceTicketAction(gssContext, serviceTicket));
           
            GSSName srcName = gssContext.getSrcName();
            if (srcName == null) {
                throw new NotAuthorizedException(getFaultResponse());
            }
           
            String complexUserName = srcName.toString();
           
            String simpleUserName = complexUserName;
            int index = simpleUserName.lastIndexOf('@');
            if (index > 0) {
                simpleUserName = simpleUserName.substring(0, index);
            }
            if (!gssContext.getCredDelegState()) {
                gssContext.dispose();
                gssContext = null;
            }

            m.put(SecurityContext.class,
                new KerberosSecurityContext(new KerberosPrincipal(simpleUserName,
                                                                  complexUserName),
                                            gssContext));
           
        } catch (LoginException e) {
            LOG.fine("Unsuccessful JAAS login for the service principal: " + e.getMessage());
            throw new NotAuthorizedException(getFaultResponse(), e);
        } catch (GSSException e) {
            LOG.fine("GSS API exception: " + e.getMessage());
            throw new NotAuthorizedException(getFaultResponse(), e);
        } catch (PrivilegedActionException e) {
            LOG.fine("PrivilegedActionException: " + e.getMessage());
            throw new NotAuthorizedException(getFaultResponse(), e);
        }
       
        return null;
    }
View Full Code Here

   
    private byte[] getServiceTicket(String encodedServiceTicket) {
        try {
            return Base64Utility.decode(encodedServiceTicket);
        } catch (Base64Exception ex) {
            throw new NotAuthorizedException(getFaultResponse());
        }
    }
View Full Code Here

   @Override
   public void filter(ContainerRequestContext requestContext) throws IOException
   {
      String authorization = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
      if (authorization == null) throw new NotAuthorizedException("OTP");

      String[] split = authorization.split(" ");
      final String user = split[0];
      String otp = split[1];

      String secret = userSecretMap.get(user);
      if (secret == null) throw new NotAuthorizedException("OTP");

      String regen = OTP.generateToken(secret);
      if (!regen.equals(otp)) throw new NotAuthorizedException("OTP");

      final SecurityContext securityContext = requestContext.getSecurityContext();
      requestContext.setSecurityContext(new SecurityContext()
      {
         @Override
View Full Code Here

      switch (status)
      {
         case 400:
            throw new BadRequestException(response);
         case 401:
            throw new NotAuthorizedException(response);
         case 404:
            throw new NotFoundException(response);
         case 405:
            throw new NotAllowedException(response);
         case 406:
View Full Code Here

            } 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

            } 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

       
        List<String> authHeaders = messageContext.getHttpHeaders()
            .getRequestHeader(HttpHeaders.AUTHORIZATION);
        if (authHeaders.size() != 1) {
            LOG.fine("No Authorization header is available");
            throw new NotAuthorizedException(getFaultResponse());
        }
        String[] authPair = StringUtils.split(authHeaders.get(0), " ");
        if (authPair.length != 2 || !NEGOTIATE_SCHEME.equalsIgnoreCase(authPair[0])) {
            LOG.fine("Negotiate Authorization scheme is expected");
            throw new NotAuthorizedException(getFaultResponse());
        }
               
        byte[] serviceTicket = getServiceTicket(authPair[1]);
       
        try {
            Subject serviceSubject = loginAndGetSubject();
           
            GSSContext gssContext = createGSSContext();

            Subject.doAs(serviceSubject, new ValidateServiceTicketAction(gssContext, serviceTicket));
           
            GSSName srcName = gssContext.getSrcName();
            if (srcName == null) {
                throw new NotAuthorizedException(getFaultResponse());
            }
           
            String complexUserName = srcName.toString();
           
            String simpleUserName = complexUserName;
            int index = simpleUserName.lastIndexOf('@');
            if (index > 0) {
                simpleUserName = simpleUserName.substring(0, index);
            }
            if (!gssContext.getCredDelegState()) {
                gssContext.dispose();
                gssContext = null;
            }

            m.put(SecurityContext.class,
                new KerberosSecurityContext(new KerberosPrincipal(simpleUserName,
                                                                  complexUserName),
                                            gssContext));
           
        } catch (LoginException e) {
            LOG.fine("Unsuccessful JAAS login for the service principal");
            throw new NotAuthorizedException(getFaultResponse());
        } catch (GSSException e) {
            LOG.fine("GSS API exception: " + e.getMessage());
            throw new NotAuthorizedException(getFaultResponse());
        } catch (PrivilegedActionException e) {
            LOG.fine("PrivilegedActionException: " + e.getMessage());
            throw new NotAuthorizedException(getFaultResponse());
        }
       
        return null;
    }
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.