| 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 java.util.List; |
| 19 | |
|
| 20 | |
import org.springframework.security.core.GrantedAuthority; |
| 21 | |
import org.springframework.security.core.authority.AuthorityUtils; |
| 22 | |
import org.springframework.security.core.userdetails.User; |
| 23 | |
import org.springframework.security.core.userdetails.UserDetails; |
| 24 | |
import org.springframework.security.core.userdetails.UserDetailsService; |
| 25 | |
import org.springframework.security.core.userdetails.UsernameNotFoundException; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 0 | public class KSDefaultUserDetailsService implements UserDetailsService{ |
| 34 | |
|
| 35 | 0 | private User ksuser = null; |
| 36 | 0 | private String password = ""; |
| 37 | |
|
| 38 | 0 | private boolean enabled = true; |
| 39 | 0 | private boolean nonlocked = true; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 0 | private List<GrantedAuthority> authorities = |
| 44 | |
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_KS_ADMIN, ROLE_KS_USER"); |
| 45 | |
|
| 46 | |
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { |
| 47 | |
|
| 48 | 0 | if(username==null || username.equals("")){ |
| 49 | 0 | throw new UsernameNotFoundException("Username cannot be null or empty"); |
| 50 | |
} |
| 51 | 0 | password = username; |
| 52 | |
|
| 53 | 0 | ksuser = new User(username, password, enabled, true, true, nonlocked, authorities); |
| 54 | |
|
| 55 | 0 | return ksuser; |
| 56 | |
} |
| 57 | |
|
| 58 | |
public void setAuthorities(String[] roles) { |
| 59 | 0 | this.authorities = AuthorityUtils.createAuthorityList(roles); |
| 60 | 0 | } |
| 61 | |
} |