/**
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you 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 org.jasig.portlet.calendar.credentials;

import java.util.Map;

import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
import javax.servlet.http.HttpSession;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.portlet.calendar.adapter.CalendarException;


/**
 * This {@link ICredentialsExtractor} implementation can retrieve the necessary
 * username and password from named attributes within the user's {@link HttpSession}
 * or {@link PortletSession}.
 * 
 * @author Nicholas Blair, nblair@doit.wisc.edu
 * @version $Header: RequestAttributeCredentialsExtractorImpl.java Exp $
 */
public class RequestAttributeCredentialsExtractorImpl implements ICredentialsExtractor {

	protected final Log log = LogFactory.getLog(this.getClass());
	
	/**
	 * Default constructor
	 */
	public RequestAttributeCredentialsExtractorImpl() { }
	
	/**
	 * @param passwordAttribute
	 * @param usernameAttribute
	 */
	public RequestAttributeCredentialsExtractorImpl(String passwordAttribute,
			String usernameAttribute) {
		this.passwordAttribute = passwordAttribute;
		this.usernameAttribute = usernameAttribute;
	}
	
	/* (non-Javadoc)
	 * @see org.jasig.portlet.calendar.adapter.CredentialsExtractor#getCredentials(javax.portlet.PortletRequest)
	 */
	public Credentials getCredentials(PortletRequest request) {
	    Map<String,String> userInfo = (Map<String,String>) request.getAttribute(PortletRequest.USER_INFO);
	    String username = userInfo.get(usernameAttribute);
	    String password = userInfo.get(passwordAttribute);
		return new UsernamePasswordCredentials(username, password);
	}

	private String usernameAttribute = "username";
	public void setUsernameAttribute(String usernameAttribute) {
		this.usernameAttribute = usernameAttribute;
	}

	private String passwordAttribute = "password";
	public void setPasswordAttribute(String passwordAttribute) {
		this.passwordAttribute = passwordAttribute;
	}
	
}

@@ -1059,32 +1059,76 @@
 ordCredentials;%0A
+import org.apache.commons.lang.StringUtils;%0A
 import org.apach
@@ -1320,20 +1320,16 @@
 ion 
-can 
 retrieve
  the
@@ -1324,16 +1324,17 @@
 retrieve
+s
  the nec
@@ -1402,64 +1402,74 @@
 the 
-user's %7B@link HttpSession%7D%0A * or %7B@link PortletSession%7D.
+USER_INFO map bound%0A * to the %7B@link javax.portlet.PortletRequest%7D
 %0A * 
@@ -1601,16 +1601,22 @@
 %0Apublic 
+final 
 class Re
@@ -1697,15 +1697,13 @@
 %0A%09pr
-otec
+iva
 te
-d
  fin
@@ -1733,21 +1733,16 @@
 .getLog(
-this.
 getClass
@@ -2468,63 +2468,433 @@
 e);%0A
-%09    String password = userInfo.get(passwordAttribute);
+        if (StringUtils.isBlank(username)) %7B%0A            log.warn(%22No username found in the USER_INFO map on the PortletRequest;  attribute name was:  %22 + usernameAttribute);%0A        %7D%0A%09    String password = userInfo.get(passwordAttribute);%0A        if (StringUtils.isBlank(password)) %7B%0A            log.warn(%22No password found in the USER_INFO map on the PortletRequest;  attribute name was:  %22 + passwordAttribute);%0A        %7D
 %0A%09%09r

Correct javadoc, add helpful WARN logging when AuthN attributes are missing