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.ldap;
14:
15: import java.util.Arrays;
16: import java.util.HashSet;
17: import java.util.Iterator;
18: import java.util.Set;
19:
20: import org.acegisecurity.GrantedAuthority;
21: import org.acegisecurity.ldap.LdapDataAccessException;
22: import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator;
23: import org.acegisecurity.userdetails.ldap.LdapUserDetails;
24: import org.springframework.beans.factory.InitializingBean;
25: import org.springframework.util.Assert;
26: import org.pentaho.messages.Messages;
27:
28: /**
29: * Delegates to populators and unions the results.
30: *
31: * @author mlowery
32: */
33: public class UnionizingLdapAuthoritiesPopulator implements
34: LdapAuthoritiesPopulator, InitializingBean {
35:
36: private Set populators;
37:
38: public GrantedAuthority[] getGrantedAuthorities(
39: final LdapUserDetails userDetails)
40: throws LdapDataAccessException {
41: Iterator iter = populators.iterator();
42: Set allAuthorities = new HashSet();
43: while (iter.hasNext()) {
44: LdapAuthoritiesPopulator populator = (LdapAuthoritiesPopulator) iter
45: .next();
46: GrantedAuthority[] auths = populator
47: .getGrantedAuthorities(userDetails);
48: if (null != auths && auths.length > 0) {
49: allAuthorities.addAll(Arrays.asList(auths));
50: }
51: }
52: return (GrantedAuthority[]) allAuthorities
53: .toArray(new GrantedAuthority[0]);
54: }
55:
56: public void setPopulators(final Set populators) {
57: this .populators = populators;
58: }
59:
60: public void afterPropertiesSet() throws Exception {
61: Assert
62: .notNull(
63: populators,
64: Messages
65: .getString("UnionizingLdapAuthoritiesPopulator.ERROR_0001_POPULATOR_NULL")); //$NON-NLS-1$
66: }
67:
68: }
|