1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.portlets.security.users;
1819import java.security.Principal;
20import java.util.Iterator;
21import java.util.LinkedHashMap;
22import java.util.Map;
23import java.util.prefs.BackingStoreException;
24import java.util.prefs.Preferences;
2526import javax.security.auth.Subject;
2728import org.apache.jetspeed.security.User;
29import org.apache.jetspeed.security.UserPrincipal;
3031/***32 * User state.33 *34 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>35 * @version $Id: JetspeedUserBean.java 348264 2005-11-22 22:06:45Z taylor $36 */37publicclassJetspeedUserBean38 {
39private String principal;
40private Map attributes = new LinkedHashMap();
4142publicJetspeedUserBean(User user)
43 {
44 Principal userPrincipal = createPrincipal(user.getSubject(), UserPrincipal.class);
45this.principal = userPrincipal.getName();
46try47 {
48 Preferences userAttributes = user.getUserAttributes();
49 String[] keys = userAttributes.keys();
50for (int ix = 0; ix < keys.length; ix++)
51 {
52 attributes.put(keys[ix], userAttributes.get(keys[ix], null));
53 }
54 }
55catch (BackingStoreException e)
56 {
57 }
58 }
5960/***61 * @return Returns the principal.62 */63public String getPrincipal()
64 {
65return principal;
66 }
67/***68 * @param principal The principal to set.69 */70publicvoid setPrincipal(String principal)
71 {
72this.principal = principal;
73 }
7475public Principal createPrincipal(Subject subject, Class classe)
76 {
77 Principal principal = null;
78 Iterator principals = subject.getPrincipals().iterator();
79while (principals.hasNext())
80 {
81 Principal p = (Principal) principals.next();
82if (classe.isInstance(p))
83 {
84 principal = p;
85break;
86 }
87 }
88return principal;
89 }
9091/***92 * @return Returns the attributes.93 */94public Map getAttributes()
95 {
96return attributes;
97 }
98 }