package ${packageName};

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.ModelAttribute;

import edu.uiowa.icts.datatable.DataTable;
import ${daoPackageName}.${daoServiceClassName};

/**
 * Generated by Protogen
 * @since ${date}
 */
public abstract class ${abstractControllerClassName} {

	protected ${daoServiceClassName} ${daoServiceVariableName};

	@Autowired
	public void set${daoServiceClassName}( ${daoServiceClassName} ${daoServiceVariableName} ) {
		this.${daoServiceVariableName} = ${daoServiceVariableName};
	}

	@ModelAttribute( value = "username" )
	public String getUsername() {
		return SecurityContextHolder.getContext().getAuthentication().getName();
	}

	/**
	 * @param e
	 * @param draw
	 * @return {@link DataTable}
	 */
	protected DataTable datatableError( Exception e, String draw ) {
		String stackTrace = e.getMessage() + String.valueOf( '\n' );
		for ( StackTraceElement ste : e.getStackTrace() ) {
			stackTrace += ste.toString() + String.valueOf( '\n' );
		}
		DataTable error = new DataTable();
		error.setDraw( draw );
		error.setRecordsFiltered( 0 );
		error.setRecordsTotal( 0 );
		error.setError( stackTrace );
		return error;
	}

}
package ${packageName};

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.ModelAttribute;

import edu.uiowa.icts.datatable.DataTable;
import edu.uiowa.icts.spring.Security;
import ${daoPackageName}.${daoServiceClassName};

/**
 * Generated by Protogen
 * @since ${date}
 */
public abstract class ${abstractControllerClassName} {

	protected ${daoServiceClassName} ${daoServiceVariableName};

	@Autowired
	public void set${daoServiceClassName}( ${daoServiceClassName} ${daoServiceVariableName} ) {
		this.${daoServiceVariableName} = ${daoServiceVariableName};
	}

	@ModelAttribute( value = "username" )
	public String getUsername() {
		if ( Security.isAuthenticated() ) {
			return SecurityContextHolder.getContext().getAuthentication().getName();
		}
		return null;
	}

	/**
	 * @param e
	 * @param draw
	 * @return {@link DataTable}
	 */
	protected DataTable datatableError( Exception e, String draw ) {
		String stackTrace = e.getMessage() + String.valueOf( '\n' );
		for ( StackTraceElement ste : e.getStackTrace() ) {
			stackTrace += ste.toString() + String.valueOf( '\n' );
		}
		DataTable error = new DataTable();
		error.setDraw( draw );
		error.setRecordsFiltered( 0 );
		error.setRecordsTotal( 0 );
		error.setError( stackTrace );
		return error;
	}

}
add is authenticated check for username model attribute