本文整理汇总了Java中org.apache.commons.httpclient.auth.AuthenticationException类的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationException类的具体用法?Java AuthenticationException怎么用?Java AuthenticationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationException类属于org.apache.commons.httpclient.auth包,在下文中一共展示了AuthenticationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
/**
* Produces bearer authorization string for the given set of {@link Credentials}.
*
* @param credentials The set of credentials to be used for authentication
* @param method The method being authenticated
* @throws InvalidCredentialsException If authentication credentials are not valid or not applicable for this authentication
* scheme.
* @throws AuthenticationException If authorization string cannot be generated due to an authentication failure.
*
* @return a basic authorization string
*/
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");
if (method == null) {
throw new IllegalArgumentException("Method may not be null");
}
BearerCredentials bearer = null;
try {
bearer = (BearerCredentials) credentials;
} catch (ClassCastException e) {
throw new InvalidCredentialsException(
"Credentials cannot be used for bearer authentication: "
+ credentials.getClass().getName());
}
return BearerAuthScheme.authenticate(
bearer,
method.getParams().getCredentialCharset());
}
示例2: readWsdl
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
private Definition readWsdl(WSDLReader wsdlReader, String uri, String username, String password)
throws WSDLException, KettleException, AuthenticationException {
try {
HTTPProtocol http = new HTTPProtocol();
Document doc = XMLHandler.loadXMLString(http.get(wsdlURI.toString(), username, password), true, false);
if (doc != null) {
return(wsdlReader.readWSDL(doc.getBaseURI(), doc));
}
else {
throw new KettleException("Unable to get document.");
}
}
catch (MalformedURLException mue) {
throw new KettleException(mue);
}
catch (AuthenticationException ae) {
// re-throw this. If not IOException seems to catch it
throw ae;
}
catch (IOException ioe) {
throw new KettleException(ioe);
}
}
示例3: NTLMMessage
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
/** Constructor to use when message contents are known */
NTLMMessage(String messageBody, int expectedType) throws AuthenticationException {
messageContents = Base64.decodeBase64(EncodingUtils.getBytes(messageBody,
DEFAULT_CHARSET));
// Look for NTLM message
if (messageContents.length < SIGNATURE.length) {
throw new AuthenticationException("NTLM message decoding error - packet too short");
}
int i = 0;
while (i < SIGNATURE.length) {
if (messageContents[i] != SIGNATURE[i]) {
throw new AuthenticationException(
"NTLM message expected - instead got unrecognized bytes");
}
i++;
}
// Check to be sure there's a type 2 message indicator next
int type = readULong(SIGNATURE.length);
if (type != expectedType) {
throw new AuthenticationException("NTLM type " + Integer.toString(expectedType)
+ " message expected - instead got type " + Integer.toString(type));
}
currentOutputPosition = messageContents.length;
}
示例4: generateType3Msg
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
public String generateType3Msg(
final String username,
final String password,
final String domain,
final String workstation,
final String challenge) throws AuthenticationException {
Type2Message t2m = new Type2Message(challenge);
return getType3Message(
username,
password,
workstation,
domain,
t2m.getChallenge(),
t2m.getFlags(),
t2m.getTarget(),
t2m.getTargetInfo());
}
示例5: authenticate
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
private void authenticate(final HttpMethod method) {
try {
if (this.conn.isProxied() && !this.conn.isSecure()) {
authenticateProxy(method);
}
authenticateHost(method);
} catch (AuthenticationException e) {
LOG.error(e.getMessage(), e);
}
}
示例6: authenticateProxy
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
private void authenticateProxy(final HttpMethod method) throws AuthenticationException {
// Clean up existing authentication headers
if (!cleanAuthHeaders(method, PROXY_AUTH_RESP)) {
// User defined authentication header(s) present
return;
}
AuthState authstate = method.getProxyAuthState();
AuthScheme authscheme = authstate.getAuthScheme();
if (authscheme == null) {
return;
}
if (authstate.isAuthRequested() || !authscheme.isConnectionBased()) {
AuthScope authscope = new AuthScope(
conn.getProxyHost(), conn.getProxyPort(),
authscheme.getRealm(),
authscheme.getSchemeName());
if (LOG.isDebugEnabled()) {
LOG.debug("Authenticating with " + authscope);
}
Credentials credentials = this.state.getProxyCredentials(authscope);
if (credentials != null) {
String authstring = authscheme.authenticate(credentials, method);
if (authstring != null) {
method.addRequestHeader(new Header(PROXY_AUTH_RESP, authstring, true));
}
} else {
if (LOG.isWarnEnabled()) {
LOG.warn("Required proxy credentials not available for " + authscope);
if (method.getProxyAuthState().isPreemptive()) {
LOG.warn("Preemptive authentication requested but no default " +
"proxy credentials available");
}
}
}
}
}
示例7: getType3MessageResponse
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
@Override
protected String getType3MessageResponse(String type2message, NTCredentials ntcredentials, HttpMethodParams params)
throws AuthenticationException {
if (!params.getBooleanParameter(WebServiceHelper.USE_NATIVE_CREDENTIALS, false) || myAuthSequenceObject == null) {
return super.getType3MessageResponse(type2message, ntcredentials, params);
}
try {
return (String)myGetAuthHeaderMethod.invoke(myAuthSequenceObject, new Object[]{type2message});
}
catch (Throwable t) {
LOG.warn("Native authentication failed", t);
return "";
}
}
示例8: EwsJCIFSNTLMScheme
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
public EwsJCIFSNTLMScheme() throws AuthenticationException {
// Check if JCIFS is present. If not present, do not proceed.
try {
Class.forName("jcifs.ntlmssp.NtlmMessage",false,this.getClass().getClassLoader());
} catch (ClassNotFoundException e) {
throw new AuthenticationException("Unable to proceed as JCIFS library is not found.");
}
}
示例9: parse
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
/**
* Load and parse the WSDL file using the wsdlLocator.
*
* @param wsdlLocator A WSDLLocator instance.
* @param username to use for authentication
* @param password to use for authentication
* @return wsdl Definition.
* @throws WSDLException on error.
*/
private Definition parse(WSDLLocator wsdlLocator, String username, String password)
throws WSDLException, KettleException, AuthenticationException {
WSDLReader wsdlReader = getReader();
try {
return wsdlReader.readWSDL(wsdlLocator);
}
catch (WSDLException we) {
readWsdl(wsdlReader, wsdlURI.toString(), username, password);
return null;
}
}
示例10: get
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
/**
* Performs a get on urlAsString using username and password as credentials.
*
* If the status code returned not -1 and 401 then the contents are returned.
* If the status code is 401 an AuthenticationException is thrown.
*
* All other values of status code are not dealt with but logic can be
* added as needed.
*
* @param urlAsString
* @param username
* @param password
* @param encoding
* @return
* @throws MalformedURLException
* @throws IOException
*/
public String get(String urlAsString, String username, String password)
throws MalformedURLException, IOException, AuthenticationException {
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(urlAsString);
httpClient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(username, password);
httpClient.getState().setCredentials(AuthScope.ANY, defaultcreds);
int statusCode = httpClient.executeMethod(getMethod);
StringBuffer bodyBuffer = new StringBuffer();
if (statusCode!= -1) {
if (statusCode != 401) {
// the response
InputStreamReader inputStreamReader = new InputStreamReader(getMethod.getResponseBodyAsStream());
int c;
while ( (c=inputStreamReader.read())!=-1) {
bodyBuffer.append((char)c);
}
inputStreamReader.close();
}
else {
throw new AuthenticationException();
}
}
// Display response
return bodyBuffer.toString();
}
示例11: readULong
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
private static int readULong(byte[] src, int index) throws AuthenticationException {
if (src.length < index + 4) {
throw new AuthenticationException("NTLM authentication - buffer too small for DWORD");
}
return (src[index] & 0xff) | ((src[index + 1] & 0xff) << 8)
| ((src[index + 2] & 0xff) << 16) | ((src[index + 3] & 0xff) << 24);
}
示例12: readSecurityBuffer
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
private static byte[] readSecurityBuffer(byte[] src, int index) throws AuthenticationException {
int length = readUShort(src, index);
int offset = readULong(src, index + 4);
if (src.length < offset + length) {
throw new AuthenticationException(
"NTLM authentication - buffer too small for data item");
}
byte[] buffer = new byte[length];
System.arraycopy(src, offset, buffer, 0, length);
return buffer;
}
示例13: makeRandomChallenge
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
/** Calculate a challenge block */
private static byte[] makeRandomChallenge() throws AuthenticationException {
if (RND_GEN == null) {
throw new AuthenticationException("Random generator not available");
}
byte[] rval = new byte[8];
synchronized (RND_GEN) {
RND_GEN.nextBytes(rval);
}
return rval;
}
示例14: makeSecondaryKey
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
/** Calculate a 16-byte secondary key */
private static byte[] makeSecondaryKey() throws AuthenticationException {
if (RND_GEN == null) {
throw new AuthenticationException("Random generator not available");
}
byte[] rval = new byte[16];
synchronized (RND_GEN) {
RND_GEN.nextBytes(rval);
}
return rval;
}
示例15: getClientChallenge
import org.apache.commons.httpclient.auth.AuthenticationException; //导入依赖的package包/类
/** Calculate and return client challenge */
public byte[] getClientChallenge()
throws AuthenticationException {
if (clientChallenge == null) {
clientChallenge = makeRandomChallenge();
}
return clientChallenge;
}