| 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 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
@author |
| 18 |
|
|
|
|
|
| 43,9% |
Uncovered Elements: 64 (114) |
Complexity: 40 |
Complexity Density: 0,59 |
|
| 19 |
|
public class PebbleUserDetails implements UserDetails { |
| 20 |
|
|
| 21 |
|
private String username; |
| 22 |
|
private String password; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
private String name; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
private String emailAddress; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
private String website; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
private String profile; |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
private Map<String,String> preferences = new HashMap<String,String>(); |
| 38 |
|
|
| 39 |
|
private GrantedAuthority grantedAuthories[]; |
| 40 |
|
|
| 41 |
|
private boolean detailsUpdateable = true; |
| 42 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 43 |
0
|
public PebbleUserDetails() {... |
| 44 |
|
} |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
| 46 |
0
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
|
| 57 |
32
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
82
|
public String getUsername() {... |
| 70 |
82
|
return this.username; |
| 71 |
|
} |
| 72 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 73 |
22
|
public String getPassword() {... |
| 74 |
22
|
return this.password; |
| 75 |
|
} |
| 76 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 77 |
0
|
public boolean isAccountNonExpired() {... |
| 78 |
0
|
return true; |
| 79 |
|
} |
| 80 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
0
|
public boolean isAccountNonLocked() {... |
| 82 |
0
|
return true; |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 85 |
0
|
public boolean isCredentialsNonExpired() {... |
| 86 |
0
|
return true; |
| 87 |
|
} |
| 88 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 89 |
0
|
public boolean isEnabled() {... |
| 90 |
0
|
return true; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
@return |
| 97 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 98 |
32
|
public String getName() {... |
| 99 |
32
|
return name; |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
@return |
| 106 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 107 |
20
|
public String getEmailAddress() {... |
| 108 |
20
|
return emailAddress; |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
@return |
| 115 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 116 |
20
|
public String getWebsite() {... |
| 117 |
20
|
return website; |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
@return |
| 124 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 125 |
16
|
public String getProfile() {... |
| 126 |
16
|
return this.profile; |
| 127 |
|
} |
| 128 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 129 |
22
|
public GrantedAuthority[] getAuthorities() {... |
| 130 |
22
|
return this.grantedAuthories; |
| 131 |
|
} |
| 132 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
| 133 |
0
|
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 |
|
|
|
|
|
| 90,9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0,43 |
|
| 143 |
14
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
| 157 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 169 |
0
|
public boolean isBlogAdmin() {... |
| 170 |
0
|
return isUserInRole(Constants.BLOG_ADMIN_ROLE); |
| 171 |
|
} |
| 172 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 173 |
0
|
public boolean isBlogOwner() {... |
| 174 |
0
|
return isUserInRole(Constants.BLOG_OWNER_ROLE); |
| 175 |
|
} |
| 176 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 177 |
0
|
public boolean isBlogPublisher() {... |
| 178 |
0
|
return isUserInRole(Constants.BLOG_PUBLISHER_ROLE); |
| 179 |
|
} |
| 180 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 181 |
0
|
public boolean isBlogContributor() {... |
| 182 |
0
|
return isUserInRole(Constants.BLOG_CONTRIBUTOR_ROLE); |
| 183 |
|
} |
| 184 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
| 185 |
32
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 197 |
0
|
public void setUsername(String username) {... |
| 198 |
0
|
this.username = username; |
| 199 |
|
} |
| 200 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 201 |
0
|
public void setPassword(String password) {... |
| 202 |
0
|
this.password = password; |
| 203 |
|
} |
| 204 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 205 |
0
|
public void setName(String name) {... |
| 206 |
0
|
this.name = name; |
| 207 |
|
} |
| 208 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 209 |
0
|
public void setEmailAddress(String emailAddress) {... |
| 210 |
0
|
this.emailAddress = emailAddress; |
| 211 |
|
} |
| 212 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 213 |
0
|
public void setWebsite(String website) {... |
| 214 |
0
|
this.website = website; |
| 215 |
|
} |
| 216 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 217 |
0
|
public void setProfile(String profile) {... |
| 218 |
0
|
this.profile = profile; |
| 219 |
|
} |
| 220 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 221 |
0
|
public void setGrantedAuthories(GrantedAuthority[] grantedAuthories) {... |
| 222 |
0
|
this.grantedAuthories = grantedAuthories; |
| 223 |
|
} |
| 224 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 225 |
14
|
public boolean isDetailsUpdateable() {... |
| 226 |
14
|
return detailsUpdateable; |
| 227 |
|
} |
| 228 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 229 |
0
|
public void setDetailsUpdateable(boolean detailsUpdateable) {... |
| 230 |
0
|
this.detailsUpdateable = detailsUpdateable; |
| 231 |
|
} |
| 232 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 233 |
14
|
public Map<String,String> getPreferences() {... |
| 234 |
14
|
return new HashMap<String,String>(preferences); |
| 235 |
|
} |
| 236 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 237 |
2
|
public String getPreference(String key) {... |
| 238 |
2
|
return preferences.get(key); |
| 239 |
|
} |
| 240 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 241 |
0
|
public void setPreferences(Map<String,String> preferences) {... |
| 242 |
0
|
this.preferences = new HashMap<String,String>(preferences); |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
} |