Package org.apache.commons.httpclient.auth

Examples of org.apache.commons.httpclient.auth.AuthenticationException


        mac.init( kg.generateKey() );
        byte[] result = mac.doFinal(baseString.getBytes())
       
        return new String(Base64.encodeBase64(result));
      } catch (Exception e) {
        throw new AuthenticationException(e.getMessage(), e);
      }
    } else if (method.equalsIgnoreCase("md5")) {
      return new String(Base64.encodeBase64(DigestUtils.md5( baseString )));
    } else if (method.equalsIgnoreCase("sha1")) {
      return new String(Base64.encodeBase64(DigestUtils.sha( baseString )));
    } else if (method.equalsIgnoreCase("RSA-SHA1")) {
      if (cert == null) {
        throw new AuthenticationException("a cert is mandatory to use SHA1 with RSA");
      }
      try {       
        Cipher cipher = Cipher.getInstance("SHA1withRSA");
        cipher.init(Cipher.ENCRYPT_MODE, cert);
        byte[] result = cipher.doFinal( baseString.getBytes() );
        return new String(Base64.encodeBase64( result ));
      } catch (Exception e) {
        throw new AuthenticationException(e.getMessage(), e);
      }
    } else {
      throw new AuthenticationException("unsupported algorithm method: " + method );
    }   
  }
View Full Code Here


                case GSSException.NO_CRED:
                    throw new CredentialsNotAvailableException(e.getMessage(), e);
                default:
                    String errorMessage = "Caught GSSException in GSSContext.initSecContext()";
                    LOGGER.log(Level.SEVERE, errorMessage, e);
                    throw new AuthenticationException(errorMessage, e);
            }
        }
    }
View Full Code Here

protected void execute(HttpServletRequest request,
    HttpServletResponse response, RequestContext context) throws Exception {
 
  try {
    if(context.getUser().getName().equals("")) {
      throw new AuthenticationException("Login needed");
    }
    if(request.getMethod().toLowerCase().equals("get")) {
      writeSavedSearches(request, response, context);
    } else if(request.getMethod().toLowerCase().equals("put") ||
        request.getMethod().toLowerCase().equals("post")) {
View Full Code Here

     *
     * @deprecated Use {@link #authenticate(Credentials, HttpMethod)}
     */
    public String authenticate(Credentials credentials, String method, String uri)
      throws AuthenticationException {
        throw new AuthenticationException("method not supported by Negotiate scheme");
    }
View Full Code Here

                    init( method.getURI().getHost());
                }
            } catch (org.apache.commons.httpclient.URIException urie) {
                LOG.error(urie.getMessage());
                state = FAILED;
                throw new AuthenticationException(urie.getMessage());
            }
       
            String username = null;
            String password = null;
           
            if(credentials instanceof NTCredentials){
              username = ((NTCredentials)credentials).getUserName();
              password = ((NTCredentials)credentials).getPassword();
            }else if(credentials instanceof UsernamePasswordCredentials){
              username = ((UsernamePasswordCredentials)credentials).getUserName();
              password = ((UsernamePasswordCredentials)credentials).getPassword();
            }
            try {
              LoginContext lc = new LoginContext("com.sun.security.jgss.login", new TestCallbackHandler(username, password));
              if(lc != null){
                lc.login();
                subject = lc.getSubject();
              } else {
                throw new LoginException();
              }
            } catch (LoginException e1) {
              LOG.error(e1.getMessage());
              throw new GSSException(GSSException.DEFECTIVE_CREDENTIAL);
            }
            if(subject != null){
              Subject.doAs(subject, this);
            }else{
           throw new GSSException(GSSException.DEFECTIVE_CREDENTIAL);
         }
            // HTTP 1.1 issue:
            // Mutual auth will never complete do to 200 insted of 401 in
            // return from server. "state" will never reach ESTABLISHED
            // but it works anyway
            //token = context.initSecContext(token, 0, token.length);
            //LOG.info("got token, sending " + token.length + " to server");
        } catch (GSSException gsse) {
            LOG.fatal(gsse.getMessage());
            state = FAILED;
            if( gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL
                    || gsse.getMajor() == GSSException.CREDENTIALS_EXPIRED )
                throw new InvalidCredentialsException(gsse.getMessage(),gsse);
            if( gsse.getMajor() == GSSException.NO_CRED )
                throw new CredentialsNotAvailableException(gsse.getMessage(),gsse);
            if( gsse.getMajor() == GSSException.DEFECTIVE_TOKEN
                    || gsse.getMajor() == GSSException.DUPLICATE_TOKEN
                    || gsse.getMajor() == GSSException.OLD_TOKEN )
                throw new AuthChallengeException(gsse.getMessage(),gsse);
            // other error
            throw new AuthenticationException(gsse.getMessage());
        }
        return "Negotiate " + new String(new Base64().encode(token));
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.auth.AuthenticationException

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.