001: /*
002: * Copyright 2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Sep 20, 2007
014: * @author wseyler
015: */
016:
017: package org.pentaho.repository.cwm;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023: import java.util.Set;
024:
025: import org.pentaho.core.system.PentahoSystem;
026: import org.pentaho.pms.schema.security.SecurityACL;
027: import org.pentaho.pms.schema.security.SecurityService;
028:
029: import com.pentaho.security.UserDetailsRoleListService;
030: import com.pentaho.security.acls.PentahoAclEntry;
031:
032: /**
033: * @author wseyler
034: *
035: */
036: public class PlatformSecurityService extends SecurityService {
037: List users = null;
038: List roles = null;
039: List acls = null;
040:
041: public PlatformSecurityService() {
042: super ();
043: UserDetailsRoleListService service = PentahoSystem
044: .getUserDetailsRoleListService();
045: users = service.getAllUsers();
046: roles = service.getAllRoles();
047: acls = new ArrayList();
048: Map validPermissionsNameMap = PentahoAclEntry
049: .getValidPermissionsNameMap(PentahoAclEntry.PERMISSIONS_LIST_ALL);
050: if (validPermissionsNameMap != null) {
051: Set aclsKeySet = validPermissionsNameMap.keySet();
052: for (Iterator aclsIterator = aclsKeySet.iterator(); aclsIterator
053: .hasNext();) {
054: String aclName = aclsIterator.next().toString();
055: int aclMask = null != validPermissionsNameMap
056: .get(aclName) ? Integer
057: .parseInt(validPermissionsNameMap.get(aclName)
058: .toString()) : 0;
059: acls.add(new SecurityACL(aclName, aclMask));
060: }
061: }
062: }
063:
064: /**
065: * Returns XML for list of users.
066: */
067: protected void doUsers(StringBuffer buf) {
068: UserDetailsRoleListService service = PentahoSystem
069: .getUserDetailsRoleListService();
070: buf.append("<users>"); //$NON-NLS-1$
071: if (service != null) {
072: List users = service.getAllUsers();
073: for (Iterator usersIterator = users.iterator(); usersIterator
074: .hasNext();) {
075: String username = usersIterator.next().toString();
076: if (null != username && username.length() > 0) {
077: buf.append("<user>" + username + "</user>"); //$NON-NLS-1$ //$NON-NLS-2$
078: }
079: }
080: }
081: buf.append("</users>"); //$NON-NLS-1$
082: }
083:
084: /**
085: * Returns XML for list of roles.
086: */
087: protected void doRoles(StringBuffer buf) {
088: UserDetailsRoleListService service = PentahoSystem
089: .getUserDetailsRoleListService();
090: buf.append("<roles>"); //$NON-NLS-1$
091: if (service != null) {
092: List roles = service.getAllRoles();
093: for (Iterator rolesIterator = roles.iterator(); rolesIterator
094: .hasNext();) {
095: String roleName = rolesIterator.next().toString();
096: if (null != roleName && roleName.length() > 0) {
097: buf.append("<role>" + roleName + "</role>"); //$NON-NLS-1$ //$NON-NLS-2$
098: }
099: }
100: }
101: buf.append("</roles>"); //$NON-NLS-1$
102: }
103:
104: /**
105: * Returns XML for list of ACLs.
106: */
107: protected void doACLs(StringBuffer buf) {
108: Map validPermissionsNameMap = PentahoAclEntry
109: .getValidPermissionsNameMap(PentahoAclEntry.PERMISSIONS_LIST_ALL);
110: buf.append("<acls>"); //$NON-NLS-1$
111: if (validPermissionsNameMap != null) {
112: Set aclsKeySet = validPermissionsNameMap.keySet();
113: for (Iterator aclsIterator = aclsKeySet.iterator(); aclsIterator
114: .hasNext();) {
115: String aclName = aclsIterator.next().toString();
116: String aclMask = null != validPermissionsNameMap
117: .get(aclName) ? validPermissionsNameMap.get(
118: aclName).toString() : null;
119:
120: if (null != aclName && aclName.length() > 0
121: && null != aclMask && aclMask.length() > 0) {
122: buf.append("<acl>"); //$NON-NLS-1$
123: buf.append("<name>"); //$NON-NLS-1$
124: buf.append(aclName);
125: buf.append("</name>"); //$NON-NLS-1$
126: buf.append("<mask>"); //$NON-NLS-1$
127: buf.append(aclMask);
128: buf.append("</mask>"); //$NON-NLS-1$
129: buf.append("</acl>"); //$NON-NLS-1$
130: }
131:
132: }
133: }
134: buf.append("</acls>"); //$NON-NLS-1$
135: }
136:
137: public List getAcls() {
138: return acls;
139: }
140:
141: public List getUsers() {
142: return users;
143: }
144:
145: public List getRoles() {
146: return roles;
147: }
148: }
|