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));
}