01: /*
02: * Copyright 2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package com.pentaho.security.acls.voter;
14:
15: import org.acegisecurity.Authentication;
16: import org.acegisecurity.GrantedAuthority;
17: import org.acegisecurity.GrantedAuthorityImpl;
18: import org.pentaho.core.session.IPentahoSession;
19: import org.pentaho.core.system.ISystemSettings;
20: import org.pentaho.core.system.PentahoSystem;
21:
22: import org.pentaho.core.system.IPentahoInitializer;
23:
24: public abstract class AbstractPentahoAclVoter implements IAclVoter,
25: IPentahoInitializer {
26: protected GrantedAuthority adminRole;
27:
28: public abstract Authentication getAuthentication(
29: IPentahoSession session);
30:
31: public GrantedAuthority getAdminRole() {
32: return this .adminRole;
33: }
34:
35: public void setAdminRole(GrantedAuthority value) {
36: this .adminRole = value;
37: }
38:
39: public void init(IPentahoSession session) {
40: ISystemSettings settings = PentahoSystem.getSystemSettings();
41: String roleName = settings.getSystemSetting(
42: "acl-voter/admin-role", "Admin"); //$NON-NLS-1$ //$NON-NLS-2$
43: adminRole = new GrantedAuthorityImpl(roleName);
44: }
45:
46: public boolean isPentahoAdministrator(IPentahoSession session) {
47: // A user is considered a manager if they're authenticated,
48: // and a member of the adminRole specified.
49: return isGranted(session, adminRole);
50: }
51:
52: public boolean isGranted(IPentahoSession session,
53: GrantedAuthority role) {
54: Authentication auth = getAuthentication(session);
55: if ((auth != null) && auth.isAuthenticated()) {
56: GrantedAuthority[] userAuths = auth.getAuthorities();
57: if (userAuths == null) {
58: return false;
59: }
60: for (int i = 0; i < userAuths.length; i++) {
61: if (userAuths[i].equals(role)) {
62: return true;
63: }
64: }
65: return false;
66: } else {
67: return false;
68: }
69: }
70:
71: }
|