I recently moved my website from shared hosting to Amazon EC2. I also added domain access module which allows me to have subdomains within drupal to seperate content. I am using them like chicago.example.com nyc.example.com etc to have different city sections on my website.

For some reason some of my users are getting an "Access Denied" error immediatly after logging in. This is only happeneing to some of my users but enough of them that its quite a big problem.

I have posted an issue in the Domain Access issue queue #824548: Access denied when logging in but still cant seem to track the error down. It may be server mis configuration or some other module or setting.

If anyone thinks they can help me fix this issue I am offering a bounty of $50.

Comments

sukr_s’s picture

i had the same problem when SSO module was enabled. i'm not sure if you have an SSO module enabled, but here is a workaround
1. set a menu that needs to be called on access denied in admin -> settings -> error reporting e.g. accessdenied
2. in that menu handler do the following

global $base_url;
global $user;
//get the menu parameter
$param=arg(0);
//assuming that your menu is /accessdenied
if($param=='accessdenied'&& !empty($user->uid) &&
			(  strpos($_SERVER['REDIRECT_URL'],'login')!==FALSE 
			|| strpos($_SERVER['REDIRECT_QUERY_STRING'],'login')!==FALSE
			|| strpos($_SERVER['QUERY_STRING'],'login')!==FALSE
			|| strpos($_SERVER['REQUEST_URI'],'login')!==FALSE)){
   durpal_goto($base_url);//or your preferred page
}
else
   return t("Access denied");

sukr_s’s picture

If an access denied error occurs during the logon process and if the user has actually been logged on, then he will be redirected to the site's homepage. If the user tries to access a page that he is not authorized to access, then it shows him an access denied error message.

1. Create a folder in your site's module folder and name it access_denied
2. Create a access_denied.info file in this folder
3. Copy the following contents in to access_denied.info file

; $Id$
name = "Access denied"
description = "Module to redirect users to home page of the site when access denied error occurs in spite of successful logon"
core = "6.x"
package = Others

4. Create a access_denied.module file in the same folder
5. Copy the following code in to this file

<?php
/*
 * This module implements one menu item that will be called on access denied error. If the access denied
 * error occurs during the login process, the menu will redirect the user to the site's front page
 * otherwise it shows and access denied error
 */


/*
 * implementation of hook_menu
 */
function access_denied_menu(){
//menu definition for handling accessdenied error
 $items['accessdenied'] = array(
	 'page callback' => 'access_denied_process',
	 'access callback' => TRUE,
	 'type' => MENU_CALLBACK,
	);
	
 return $items;
}

function access_denied_process(){
  global $base_url;
  global $user;
 // if the user is successfully logged on $user will be set and one of the $_SERVER parameter will be set
 // as below. if any of the following is true, take the user to the homepage of the site
	if(!empty($user->uid) &&
	(  strpos($_SERVER['REDIRECT_URL'],'login')!==FALSE
	|| strpos($_SERVER['REDIRECT_QUERY_STRING'],'login')!==FALSE
	|| strpos($_SERVER['QUERY_STRING'],'login')!==FALSE
	|| strpos($_SERVER['REQUEST_URI'],'login')!==FALSE)){
	  //get the frontpage setting
	  $frontpage=variable_get('site_frontpage','');
	  //navigate the user to the frontpage of the site
	  durpal_goto("$base_url/$frontpage");//or your preferred page
	}
	else{
	   //user has not be successfully logged on or is trying to access a page that he is not authorized to view e.g. /admin
	   //set the page title to Access denied
	   drupal_set_title(t('Access denied')); 
	   return t("You are not authorized to access this page");
	}
}

6. To install this module
6.a enable this via admin/build/modules.
6.b Set the access denied handler in Administer -> Settings -> Error reporting -> Default 404 (not found) page: to accessdenied and save the configuration.

j0k3z’s picture

This worked perfectly. Extremely helpful information!

neelanjana das’s picture

I get an access denied title in d7 though the user is logged in . how should i fix that?