001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006 007package org.fcrepo.camel.common.processor; 008 009import org.apache.camel.Exchange; 010import org.apache.camel.Processor; 011import org.apache.commons.lang3.StringUtils; 012 013import static org.fcrepo.camel.common.helpers.BasicAuth.BASIC_AUTH_HEADER; 014import static org.fcrepo.camel.common.helpers.BasicAuth.generateBasicAuthHeader; 015 016/** 017 * A processor for adding a basic auth header when username is present. 018 * @author dbernstein 019 */ 020public class AddBasicAuthProcessor implements Processor { 021 022 private final String username; 023 private final String password; 024 025 /** 026 * Constructor 027 * @param username The username 028 * @param password The password 029 */ 030 public AddBasicAuthProcessor(final String username, final String password) { 031 this.username = username; 032 this.password = password; 033 } 034 @Override 035 public void process(final Exchange exchange) throws Exception { 036 if (!StringUtils.isBlank(this.username)) { 037 exchange.getIn().setHeader(BASIC_AUTH_HEADER, 038 generateBasicAuthHeader(this.username, this.password)); 039 } 040 } 041}