CredentialsUtil.java :  » Web-Crawler » crawler » com » torunski » crawler » parser » httpclient » Java Open Source

Java Open Source » Web Crawler » crawler 
crawler » com » torunski » crawler » parser » httpclient » CredentialsUtil.java
/*
 * Copyright 2006 by Lars Torunski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.torunski.crawler.parser.httpclient;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;

/** 
 * This utility class helps users who don't want to know any details of HttpClient.
 * 
 * The class helps to create an authentication credentials based on 
 * username and password or 
 */
public final class CredentialsUtil {

    /**
     * Avoid instances of CredentialsUtil.
     */
    private CredentialsUtil() {
    }

    /**
   * Creates an username and password credentials.
   * 
     * @param userName the user name
     * @param password the password
     * 
     * @see org.apache.commons.httpclient.UsernamePasswordCredentials#UsernamePasswordCredentials(java.lang.String, java.lang.String)
     */
  public static Credentials createUsernamePasswordCredentials(String userName, String password) {
    return new UsernamePasswordCredentials(userName, password);      
    }
    
    /**
     * Creates a credentials for use with the NTLM authentication scheme which requires additional information.
     * 
     * @param userName The user name.  This should not include the domain to authenticate with. For example: "user" is correct whereas "DOMAIN\\user" is not.
     * @param password The password.
     * @param host The host the authentication request is originating from.  Essentially, the computer name for this machine.
     * @param domain The domain to authenticate within.
     * 
     * @see org.apache.commons.httpclient.NTCredentials#NTCredentials(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
     */
  public static Credentials createNTLMCredentials(String userName, String password, String host, String domain) {
    return new NTCredentials(userName, password, host, domain);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.