Example usage for org.apache.commons.httpclient Credentials toString

List of usage examples for org.apache.commons.httpclient Credentials toString

Introduction

In this page you can find the example usage for org.apache.commons.httpclient Credentials toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.alfresco.repo.remoteticket.AbstractRemoteAlfrescoTicketImpl.java

/**
 * Returns the Ticket in the form used for HTTP Basic Authentication. 
 * This should be added as the value to a HTTP Request Header with 
 *  key Authorization//from w  ww  .j  av a 2 s  . co m
 */
public String getAsHTTPAuthorization() {
    // Build from the Username and Password
    Pair<String, String> userPass = getAsUsernameAndPassword();
    Credentials credentials = new UsernamePasswordCredentials(userPass.getFirst(), userPass.getSecond());

    // Encode it into the required format
    String credentialsEncoded = Base64.encodeBytes(credentials.toString().getBytes(utf8),
            Base64.DONT_BREAK_LINES);

    // Mark it as Basic, and we're done
    return "Basic " + credentialsEncoded;
}

From source file:org.apache.cocoon.transformation.WebDAVTransformer.java

public Serializable getKey() {
    if (m_state == null) {
        return "WebDAVTransformer";
    }//from  www  .j a  v  a 2 s  . c  o m
    final StringBuffer key = new StringBuffer();
    // get the credentials
    final Credentials credentials = m_state.getCredentials(null, null);
    if (credentials != null) {
        if (credentials instanceof UsernamePasswordCredentials) {
            key.append(((UsernamePasswordCredentials) credentials).getUserName());
        } else {
            key.append(credentials.toString());
        }
    }
    return key.toString();
}

From source file:org.apache.jackrabbit.spi2dav.CredentialsWrapper.java

CredentialsWrapper(javax.jcr.Credentials creds) {

    if (creds == null) {
        // NOTE: null credentials only work if 'missing-auth-mapping' param is set on the server
        userId = null;/*from  ww w .  j  a  v a 2s .c  om*/
        this.credentials = null;
    } else if (creds instanceof SimpleCredentials) {
        SimpleCredentials sCred = (SimpleCredentials) creds;
        userId = sCred.getUserID();
        this.credentials = new UsernamePasswordCredentials(userId, String.valueOf(sCred.getPassword()));
    } else {
        userId = null;
        this.credentials = new UsernamePasswordCredentials(creds.toString());
    }
}

From source file:org.apache.jackrabbit.spi2dav.CredentialsWrapper.java

CredentialsWrapper(javax.jcr.Credentials creds) {

    if (creds == null) {
        // NOTE: null credentials only work if 'missing-auth-mapping' param is set on the server
        userId = "";
        this.credentials = null;
    } else if (creds instanceof SimpleCredentials) {
        SimpleCredentials sCred = (SimpleCredentials) creds;
        userId = sCred.getUserID();//from   w  ww  . j  ava2  s  . co  m
        this.credentials = new UsernamePasswordCredentials(userId, String.valueOf(sCred.getPassword()));
    } else {
        userId = "";
        this.credentials = new UsernamePasswordCredentials(creds.toString());
    }
}