What you could do is handle if the user has not enough permissions to access a certain resource and stop rendering the web part.
Firstly, access denied handling: Assuming you are accessing the resources in CreateChildControls of the web part:
private bool accessDenied;
protected override void CreateChildControls()
{
try
{
// prevent SharePoint from catching an access denied exception and
// redirecting to the error page.
using (new SPSecurity.SuppressAccessDeniedRedirectInScope())
{
SPContext.Current.Web.Lists["Restriced"] // some thing...
}
}
catch (UnauthorizedAccessException)
{
// set variable in case the user has not enough permissions
accessDenied = true;
}
}
Now, we know whether the user has not enough rights to access a resource. Next step is to disable rendering and hide the web part and its contents. Hiding the web part is straightforward. All we need to do is override the render method and do nothing:
protected override void RenderWebPart(HtmlTextWriter writer)
{
if (accessDenied) return;
base.RenderWebPart(writer);
}
You could alternatively display an error message. However this would defeat the purpose, I guess.
Last step is to disable the web part's chrome. This can be done by setting the ChromeType in the OnPreRender method:
protected override void OnPreRender(EventArgs e)
{
// Important to call base method in order to ensure child controls...
base.OnPreRender(e);
if (accessDenied)
{
ChromeType = PartChromeType.None;
}
}
Of course, if you are overriding other methods in the web part you need to check if accessDenied is set.