Package org.apache.commons.httpclient.auth

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


    }

    public void testSimpleAuthPost() throws Exception {
        HttpClient client = createHttpClient();
        client.getState().setCredentials(
            new HttpAuthRealm(getHost(), getPort(), "BasicAuthServlet"),
            new UsernamePasswordCredentials("jakarta","commons"));
        PostMethod method = new PostMethod("/" + getWebappContext() + "/auth/basic");
        method.setRequestBody(new NameValuePair[] { new NameValuePair("testing","one") } );
       
        try {
View Full Code Here


    }

    public void testSimpleAuthPut() throws Exception {
        HttpClient client = createHttpClient();
        client.getState().setCredentials(
            new HttpAuthRealm(getHost(), getPort(), "BasicAuthServlet"),
            new UsernamePasswordCredentials("jakarta","commons"));
        PutMethod method = new PutMethod("/" + getWebappContext() + "/auth/basic");
        method.setRequestEntity(new StringRequestEntity("testing one two three"));
        try {
            client.executeMethod(method);
View Full Code Here

        assertEquals(401,method.getStatusCode());
        assertTrue(method.getResponseBodyAsString().indexOf("<title>BasicAuth Servlet: GET</title>") >= 0);
        assertTrue(method.getResponseBodyAsString().indexOf("<p>Not authorized.</p>") >= 0);

        client.getState().setCredentials(
            new HttpAuthRealm(getHost(), getPort(), "BasicAuthServlet"),
            new UsernamePasswordCredentials("jakarta","commons"));

        method.recycle();
        method.setPath("/" + getWebappContext() + "/auth/basic");
        try {
View Full Code Here

        assertEquals(HttpStatus.SC_UNAUTHORIZED,method.getStatusCode());
        assertTrue(method.getResponseBodyAsString().indexOf("<title>BasicAuth Servlet: GET</title>") >= 0);
        assertTrue(method.getResponseBodyAsString().indexOf("<p>Not authorized.</p>") >= 0);

        client.getState().setCredentials(
            new HttpAuthRealm(getHost(), getPort(), "BasicAuthServlet"),
            new UsernamePasswordCredentials("bad","creds"));

        method.recycle();
        method.setPath("/" + getWebappContext() + "/auth/basic");
        try {
View Full Code Here

     */
   
    public synchronized void setCredentials(String realm, String host, Credentials credentials) {
        LOG.trace(
            "enter HttpState.setCredentials(String realm, String host, Credentials credentials)");
        credMap.put(new HttpAuthRealm(host, realm), credentials);
    }
View Full Code Here

     * @param host the host the realm is on
     * @return the credentials
     *
     */
    private static Credentials matchCredentials(HashMap map, String realm, String host) {
        HttpAuthRealm entry = new HttpAuthRealm(host, realm);
        Credentials creds = (Credentials) map.get(entry);
        if (creds == null && host != null && realm != null) {
            entry = new HttpAuthRealm(host, null);
            creds = (Credentials) map.get(entry);
            if (creds == null) {
                entry = new HttpAuthRealm(null, realm);
                creds = (Credentials) map.get(entry);
            }
        }
        if (creds == null) {
            creds = (Credentials) map.get(DEFAULT_AUTH_REALM);
View Full Code Here

        String realm,
        String proxyHost,
        Credentials credentials
    ) {
        LOG.trace("enter HttpState.setProxyCredentials(String, String, Credentials");
        proxyCred.put(new HttpAuthRealm(proxyHost, realm), credentials);
    }
View Full Code Here

     */
   
    public synchronized void setCredentials(String realm, String host, Credentials credentials) {
        LOG.trace(
            "enter HttpState.setCredentials(String realm, String host, Credentials credentials)");
        credMap.put(new HttpAuthRealm(host, realm), credentials);
    }
View Full Code Here

     * @param host the host the realm is on
     * @return the credentials
     *
     */
    private static Credentials matchCredentials(HashMap map, String realm, String host) {
        HttpAuthRealm entry = new HttpAuthRealm(host, realm);
        Credentials creds = (Credentials) map.get(entry);
        if (creds == null && host != null && realm != null) {
            entry = new HttpAuthRealm(host, null);
            creds = (Credentials) map.get(entry);
            if (creds == null) {
                entry = new HttpAuthRealm(null, realm);
                creds = (Credentials) map.get(entry);
            }
        }
        if (creds == null) {
            creds = (Credentials) map.get(DEFAULT_AUTH_REALM);
View Full Code Here

        String realm,
        String proxyHost,
        Credentials credentials
    ) {
        LOG.trace("enter HttpState.setProxyCredentials(String, String, Credentials");
        proxyCred.put(new HttpAuthRealm(proxyHost, realm), credentials);
    }
View Full Code Here

TOP

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

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.