| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.security.spring; |
| 17 |
|
|
| 18 |
|
import org.kuali.rice.core.config.Config; |
| 19 |
|
import org.kuali.rice.core.config.ConfigContext; |
| 20 |
|
import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo; |
| 21 |
|
import org.kuali.rice.kim.service.IdentityService; |
| 22 |
|
import org.kuali.student.common.util.security.UserWithId; |
| 23 |
|
import org.springframework.security.GrantedAuthority; |
| 24 |
|
import org.springframework.security.providers.UsernamePasswordAuthenticationToken; |
| 25 |
|
import org.springframework.security.userdetails.User; |
| 26 |
|
import org.springframework.security.userdetails.UserDetails; |
| 27 |
|
import org.springframework.security.userdetails.UserDetailsService; |
| 28 |
|
import org.springframework.security.userdetails.UsernameNotFoundException; |
| 29 |
|
import org.springframework.security.util.AuthorityUtils; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@author |
| 35 |
|
|
| 36 |
|
|
|
|
|
| 0% |
Uncovered Elements: 62 (62) |
Complexity: 13 |
Complexity Density: 0.3 |
|
| 37 |
|
public class KSRiceDefaultUserDetailsService implements UserDetailsService{ |
| 38 |
|
|
| 39 |
|
private UserWithId ksuser = null; |
| 40 |
|
private String password = ""; |
| 41 |
|
|
| 42 |
|
private boolean enabled = true; |
| 43 |
|
private boolean nonlocked = true; |
| 44 |
|
|
| 45 |
|
private IdentityService identityService = null; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
private GrantedAuthority[] authorities = |
| 50 |
|
AuthorityUtils.commaSeparatedStringToAuthorityArray("ROLE_KS_ADMIN, ROLE_KS_USER"); |
| 51 |
|
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0.31 |
|
| 52 |
0
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {... |
| 53 |
0
|
if(username==null || username.equals("")){ |
| 54 |
0
|
throw new UsernameNotFoundException("Username cannot be null or empty"); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
0
|
Config config = ConfigContext.getCurrentContextConfig(); |
| 58 |
0
|
String ksIgnoreRiceLogin = config.getProperty("ks.ignore.rice.login"); |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
0
|
if(Boolean.valueOf(ksIgnoreRiceLogin) == true){ |
| 63 |
0
|
return new User(username, password, enabled, true, true, nonlocked, authorities); |
| 64 |
|
} |
| 65 |
|
|
| 66 |
0
|
KimPrincipalInfo kimPrincipalInfo = null; |
| 67 |
0
|
kimPrincipalInfo = identityService.getPrincipalByPrincipalName(username); |
| 68 |
|
|
| 69 |
0
|
String userId; |
| 70 |
0
|
if (null != kimPrincipalInfo) { |
| 71 |
0
|
username = kimPrincipalInfo.getPrincipalName(); |
| 72 |
0
|
userId = kimPrincipalInfo.getPrincipalId(); |
| 73 |
|
} else { |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
0
|
throw new KimUserNotFoundException("Invalid username or password"); |
| 78 |
|
} |
| 79 |
0
|
ksuser = new UserWithId(username, password, enabled, true, true, nonlocked, authorities); |
| 80 |
0
|
ksuser.setUserId(userId); |
| 81 |
0
|
return ksuser; |
| 82 |
|
} |
| 83 |
|
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 6 |
Complexity Density: 0.23 |
|
| 84 |
0
|
public UserDetails loadUserByUsernameAndToken(String username, UsernamePasswordAuthenticationToken authentication) throws UsernameNotFoundException {... |
| 85 |
0
|
if(username==null || username.equals("")){ |
| 86 |
0
|
throw new UsernameNotFoundException("Username cannot be null or empty"); |
| 87 |
|
} |
| 88 |
|
|
| 89 |
0
|
Config config = ConfigContext.getCurrentContextConfig(); |
| 90 |
0
|
String ksIgnoreRiceLogin = config.getProperty("ks.ignore.rice.login"); |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
0
|
if(Boolean.valueOf(ksIgnoreRiceLogin) == true){ |
| 112 |
0
|
KimPrincipalInfo kimPrincipalInfo; |
| 113 |
0
|
kimPrincipalInfo = identityService.getPrincipalByPrincipalName(username); |
| 114 |
0
|
String userId; |
| 115 |
0
|
if (null != kimPrincipalInfo) { |
| 116 |
0
|
username = kimPrincipalInfo.getPrincipalName(); |
| 117 |
0
|
userId = kimPrincipalInfo.getPrincipalId(); |
| 118 |
|
} else { |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
0
|
throw new KimUserNotFoundException("Invalid username or password"); |
| 124 |
|
} |
| 125 |
0
|
ksuser = new UserWithId(username, password, enabled, true, true, nonlocked, authorities); |
| 126 |
0
|
ksuser.setUserId(userId); |
| 127 |
0
|
return ksuser; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
0
|
password = (String)authentication.getCredentials(); |
| 131 |
|
|
| 132 |
0
|
KimPrincipalInfo kimPrincipalInfo = null; |
| 133 |
|
|
| 134 |
0
|
kimPrincipalInfo = identityService.getPrincipalByPrincipalNameAndPassword(username, password); |
| 135 |
0
|
String userId; |
| 136 |
0
|
if (null != kimPrincipalInfo) { |
| 137 |
0
|
username = kimPrincipalInfo.getPrincipalName(); |
| 138 |
0
|
userId = kimPrincipalInfo.getPrincipalId(); |
| 139 |
|
} else { |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
0
|
throw new KimUserNotFoundException("Invalid username or password"); |
| 145 |
|
} |
| 146 |
0
|
ksuser = new UserWithId(username, password, enabled, true, true, nonlocked, authorities); |
| 147 |
0
|
ksuser.setUserId(userId); |
| 148 |
0
|
return ksuser; |
| 149 |
|
} |
| 150 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 151 |
0
|
public void setAuthorities(String[] roles) {... |
| 152 |
0
|
this.authorities = AuthorityUtils.stringArrayToAuthorityArray(roles); |
| 153 |
|
} |
| 154 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 155 |
0
|
public void setIdentityService(IdentityService identityService) {... |
| 156 |
0
|
this.identityService = identityService; |
| 157 |
|
} |
| 158 |
|
} |