01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.acls.sid;
17:
18: import org.acegisecurity.Authentication;
19: import org.acegisecurity.GrantedAuthority;
20:
21: import java.util.List;
22: import java.util.Vector;
23:
24: /**
25: * Basic implementation of {@link SidRetrievalStrategy} that creates a {@link Sid} for the principal, as well as
26: * every granted authority the principal holds.<p>The returned array will always contain the {@link PrincipalSid}
27: * before any {@link GrantedAuthoritySid} elements.</p>
28: *
29: * @author Ben Alex
30: * @version $Id: SidRetrievalStrategyImpl.java 1754 2006-11-17 02:01:21Z benalex $
31: */
32: public class SidRetrievalStrategyImpl implements SidRetrievalStrategy {
33: //~ Methods ========================================================================================================
34:
35: public Sid[] getSids(Authentication authentication) {
36: List list = new Vector();
37: list.add(new PrincipalSid(authentication));
38:
39: GrantedAuthority[] authorities = authentication
40: .getAuthorities();
41:
42: for (int i = 0; i < authorities.length; i++) {
43: list.add(new GrantedAuthoritySid(authorities[i]));
44: }
45:
46: return (Sid[]) list.toArray(new Sid[] {});
47: }
48: }
|