code: public static User getUserByBasicAuthentication(Request applicationRequest, HttpServletRequest request, HttpServletResponse response, String realmDescription) throws IOException, ServletRequestAlreadyRedirectedException
  	{
  //		Request applicationRequest = application.getCurrentRequest();
  //		String realmId = applicationRequest.getRealm().getId();
  		if (applicationRequest == null)
  		{
  			throw new IllegalStateException("application request is missing; is entry point configured?");
  		}
  		User user = applicationRequest.getUser();
  		if (user == null)
  		{
  			String header = request.getHeader("Authorization");
  
  			if (header == null)
  			{
  				response.addHeader("WWW-Authenticate", "Basic realm=\"" + (realmDescription != null ? realmDescription : "access to realm IGLU") + '\"');
  				response.sendError(401);
  				throw new ServletRequestAlreadyRedirectedException("user must be authenticated first");
  			}
  			else
  			{
  				String credentials = header.substring(6);
  				System.out.println(new LogEntry("about to login"));
  				try
  				{
  					user = applicationRequest.login(new Base64EncodedCredentials(credentials));
  				}
  				catch(AuthenticationException ae)
  				{
  					System.out.println(new LogEntry(ae.getMessage()));
  					response.addHeader("WWW-Authenticate", "Basic realm=\"" + (realmDescription != null ? realmDescription : "access to realm IGLU") + '\"');
  					response.sendError(401);
  					throw new ServletRequestAlreadyRedirectedException("user must be authenticated first");
  				}
  				System.out.println(new LogEntry("logged in:" + user.getId()));
  			}
  		}
  		return user;
  	}
docs: Does one of the following things:
  <ul
  <li>retrieves current logged in user</li>
  <li>performs authentication based on the credentials provided</li>
  <li>asks the client to provide credentials if no one is logged in to current session,
  followed by throwing a ServletRequestAlreadyRedirectedException</li>
  </ul>
  
  @param request
  @param response
  @param realmDescription @return logged in user if found @throws java.io.IOException
  @throws ServletRequestAlreadyRedirectedException in case the http-request must be aborted at this stage