Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart5.png 38% of files have more coverage
68   245   40   2
12   163   0,59   34
34     1,18  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  PebbleUserDetails       Line # 19 68 0% 40 64 43,9% 0.4385965
 
  (14)
 
1    package net.sourceforge.pebble.security;
2   
3    import net.sourceforge.pebble.Constants;
4    import org.acegisecurity.GrantedAuthority;
5    import org.acegisecurity.GrantedAuthorityImpl;
6    import org.acegisecurity.userdetails.UserDetails;
7   
8    import java.util.HashSet;
9    import java.util.Set;
10    import java.util.HashMap;
11    import java.util.Map;
12   
13    /**
14    * Extension of the Acegi User class that adds additional information
15    * such as the user's e-mail address.
16    *
17    * @author Simon Brown
18    */
 
19    public class PebbleUserDetails implements UserDetails {
20   
21    private String username;
22    private String password;
23   
24    /** the name */
25    private String name;
26   
27    /** the e-mail address */
28    private String emailAddress;
29   
30    /** the website */
31    private String website;
32   
33    /** the profile */
34    private String profile;
35   
36    /** the user's preferences */
37    private Map<String,String> preferences = new HashMap<String,String>();
38   
39    private GrantedAuthority grantedAuthories[];
40   
41    private boolean detailsUpdateable = true;
42   
 
43  0 toggle public PebbleUserDetails() {
44    }
45   
 
46  0 toggle public PebbleUserDetails(String username, String name, String emailAddress, String website, String profile, String roles[], Map<String,String> preferences, boolean detailsUpdateable) {
47  0 this.username = username;
48  0 this.name = name;
49  0 this.emailAddress = emailAddress;
50  0 this.website = website;
51  0 this.profile = profile;
52  0 this.grantedAuthories = createGrantedAuthorities(roles);
53  0 this.preferences = preferences;
54  0 this.detailsUpdateable = detailsUpdateable;
55    }
56   
 
57  32 toggle public PebbleUserDetails(String username, String password, String name, String emailAddress, String website, String profile, String roles[], Map<String,String> preferences, boolean detailsUpdateable) {
58  32 this.username = username;
59  32 this.password = password;
60  32 this.name = name;
61  32 this.emailAddress = emailAddress;
62  32 this.website = website;
63  32 this.profile = profile;
64  32 this.grantedAuthories = createGrantedAuthorities(roles);
65  32 this.preferences = preferences;
66  32 this.detailsUpdateable = detailsUpdateable;
67    }
68   
 
69  82 toggle public String getUsername() {
70  82 return this.username;
71    }
72   
 
73  22 toggle public String getPassword() {
74  22 return this.password;
75    }
76   
 
77  0 toggle public boolean isAccountNonExpired() {
78  0 return true;
79    }
80   
 
81  0 toggle public boolean isAccountNonLocked() {
82  0 return true;
83    }
84   
 
85  0 toggle public boolean isCredentialsNonExpired() {
86  0 return true;
87    }
88   
 
89  0 toggle public boolean isEnabled() {
90  0 return true;
91    }
92   
93    /**
94    * Gets the name.
95    *
96    * @return a String
97    */
 
98  32 toggle public String getName() {
99  32 return name;
100    }
101   
102    /**
103    * Gets the e-mail address.
104    *
105    * @return a String
106    */
 
107  20 toggle public String getEmailAddress() {
108  20 return emailAddress;
109    }
110   
111    /**
112    * Gets the website.
113    *
114    * @return a String
115    */
 
116  20 toggle public String getWebsite() {
117  20 return website;
118    }
119   
120    /**
121    * Gets the user's profile.
122    *
123    * @return a String
124    */
 
125  16 toggle public String getProfile() {
126  16 return this.profile;
127    }
128   
 
129  22 toggle public GrantedAuthority[] getAuthorities() {
130  22 return this.grantedAuthories;
131    }
132   
 
133  0 toggle public String[] getRoles() {
134  0 GrantedAuthority[] authorities = getAuthorities();
135  0 String[] roles = new String[authorities.length];
136  0 for (int i = 0; i < authorities.length; i++) {
137  0 roles[i] = authorities[i].getAuthority();
138    }
139   
140  0 return roles;
141    }
142   
 
143  14 toggle public String getRolesAsString() {
144  14 StringBuffer buf = new StringBuffer();
145   
146  14 GrantedAuthority[] authorities = getAuthorities();
147  72 for (int i = 0; i < authorities.length; i++) {
148  58 buf.append(authorities[i].getAuthority());
149  58 if (i < authorities.length) {
150  58 buf.append(",");
151    }
152    }
153   
154  14 return buf.toString();
155    }
156   
 
157  0 toggle public boolean isUserInRole(String role) {
158  0 GrantedAuthority[] authorities = getAuthorities();
159  0 if (authorities != null) {
160  0 for (GrantedAuthority authority : authorities) {
161  0 if (authority.getAuthority().equals(role)) {
162  0 return true;
163    }
164    }
165    }
166  0 return false;
167    }
168   
 
169  0 toggle public boolean isBlogAdmin() {
170  0 return isUserInRole(Constants.BLOG_ADMIN_ROLE);
171    }
172   
 
173  0 toggle public boolean isBlogOwner() {
174  0 return isUserInRole(Constants.BLOG_OWNER_ROLE);
175    }
176   
 
177  0 toggle public boolean isBlogPublisher() {
178  0 return isUserInRole(Constants.BLOG_PUBLISHER_ROLE);
179    }
180   
 
181  0 toggle public boolean isBlogContributor() {
182  0 return isUserInRole(Constants.BLOG_CONTRIBUTOR_ROLE);
183    }
184   
 
185  32 toggle private static GrantedAuthority[] createGrantedAuthorities(String roles[]) {
186  32 Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
187  32 if (roles != null) {
188  30 for (String role : roles) {
189  60 authorities.add(new GrantedAuthorityImpl(role.trim()));
190    }
191    }
192  32 authorities.add(new GrantedAuthorityImpl(Constants.BLOG_READER_ROLE));
193   
194  32 return authorities.toArray(new GrantedAuthority[]{});
195    }
196   
 
197  0 toggle public void setUsername(String username) {
198  0 this.username = username;
199    }
200   
 
201  0 toggle public void setPassword(String password) {
202  0 this.password = password;
203    }
204   
 
205  0 toggle public void setName(String name) {
206  0 this.name = name;
207    }
208   
 
209  0 toggle public void setEmailAddress(String emailAddress) {
210  0 this.emailAddress = emailAddress;
211    }
212   
 
213  0 toggle public void setWebsite(String website) {
214  0 this.website = website;
215    }
216   
 
217  0 toggle public void setProfile(String profile) {
218  0 this.profile = profile;
219    }
220   
 
221  0 toggle public void setGrantedAuthories(GrantedAuthority[] grantedAuthories) {
222  0 this.grantedAuthories = grantedAuthories;
223    }
224   
 
225  14 toggle public boolean isDetailsUpdateable() {
226  14 return detailsUpdateable;
227    }
228   
 
229  0 toggle public void setDetailsUpdateable(boolean detailsUpdateable) {
230  0 this.detailsUpdateable = detailsUpdateable;
231    }
232   
 
233  14 toggle public Map<String,String> getPreferences() {
234  14 return new HashMap<String,String>(preferences);
235    }
236   
 
237  2 toggle public String getPreference(String key) {
238  2 return preferences.get(key);
239    }
240   
 
241  0 toggle public void setPreferences(Map<String,String> preferences) {
242  0 this.preferences = new HashMap<String,String>(preferences);
243    }
244   
245    }