View Javadoc

1   /*******************************************************************************
2    *  Imixs Workflow 
3    *  Copyright (C) 2001, 2011 Imixs Software Solutions GmbH,  
4    *  http://www.imixs.com
5    *  
6    *  This program is free software; you can redistribute it and/or 
7    *  modify it under the terms of the GNU General Public License 
8    *  as published by the Free Software Foundation; either version 2 
9    *  of the License, or (at your option) any later version.
10   *  
11   *  This program is distributed in the hope that it will be useful, 
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
14   *  General Public License for more details.
15   *  
16   *  You can receive a copy of the GNU General Public
17   *  License at http://www.gnu.org/licenses/gpl.html
18   *  
19   *  Project: 
20   *  	http://www.imixs.org
21   *  	http://java.net/projects/imixs-workflow
22   *  
23   *  Contributors:  
24   *  	Imixs Software Solutions GmbH - initial API and implementation
25   *  	Ralph Soika - Software Developer
26   *******************************************************************************/
27  
28  package org.imixs.workflow.jee.faces;
29  
30  import java.util.HashMap;
31  
32  import javax.faces.context.ExternalContext;
33  import javax.faces.context.FacesContext;
34  
35  /**
36   * This is a helper Class to check access level of a user.
37   * Can be used in a JSP/JSF page to check for a specific user role
38   * 
39   * Example:
40   * 
41   * #{IsUserInRole['org.imixs.ACCESSLEVEL.MANAGERACCESS']}
42   * 
43   * where "IsUserInRole" is a backing bean instance of the SecurityHashMap
44   * 
45   * @author Ralph Soika
46   *
47   */
48  public class SecurityHashMap extends HashMap {
49  	public SecurityHashMap() {
50  		super();
51  	}
52  
53  	public Object get(Object object) {
54  		ExternalContext ectx = FacesContext.getCurrentInstance()
55  				.getExternalContext();
56  		String isMember = "false";
57  		
58  		if (object != null) {
59  			
60  			if ("anonymous".equals(object.toString().toLowerCase()))
61  				return isAnonymous();
62  
63  			isMember = ectx.isUserInRole((String) object) == true ? "true"
64  					: "false";
65  		}
66  		return new Boolean(isMember).booleanValue();
67  	}
68  	
69  	
70  	private boolean isAnonymous() {
71  		ExternalContext ectx = FacesContext.getCurrentInstance()
72  		.getExternalContext();
73  
74  		String stype=ectx.getAuthType();
75  		return (stype==null);
76  	}
77  	
78  }