Search in sources :

Example 1 with ApplicationHeader

use of org.commonjava.indy.util.ApplicationHeader in project indy by Commonjava.

the class UserPass method parse.

public static UserPass parse(final ApplicationHeader header, final HttpRequest httpRequest, String userpass) {
    Logger logger = LoggerFactory.getLogger(UserPass.class);
    if (userpass == null) {
        Header[] headers = httpRequest.getHeaders(header.key());
        if (headers != null && headers.length > 0) {
            for (Header h : headers) {
                String value = h.getValue();
                if (value.toUpperCase().startsWith("BASIC ")) {
                    final String[] authParts = value.split(" ");
                    userpass = new String(Base64.decodeBase64(authParts[1]));
                    logger.info("userpass is: '{}'", userpass);
                    break;
                }
            }
        }
    }
    if (userpass != null) {
        final String[] upStr = userpass.split(":");
        logger.info("Split userpass into:\n  {}", StringUtils.join(upStr, "\n  "));
        if (upStr.length < 1) {
            return null;
        }
        return new UserPass(upStr[0], upStr.length > 1 ? upStr[1] : null);
    }
    return null;
}
Also used : ApplicationHeader(org.commonjava.indy.util.ApplicationHeader) Header(org.apache.http.Header) Logger(org.slf4j.Logger)

Aggregations

Header (org.apache.http.Header)1 ApplicationHeader (org.commonjava.indy.util.ApplicationHeader)1 Logger (org.slf4j.Logger)1