1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.client.acegi;
17
18 import org.acegisecurity.GrantedAuthority;
19 import org.acegisecurity.GrantedAuthorityImpl;
20 import org.acegisecurity.userdetails.User;
21 import org.acegisecurity.userdetails.UserDetails;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.springframework.beans.factory.InitializingBean;
25
26
27
28
29
30
31
32
33 public class KualiUserDetailsServiceImpl implements KualiUserDetailsService, InitializingBean
34 {
35 private static final Log logger = LogFactory.getLog(KualiUserDetailsServiceImpl.class);
36
37 public void afterPropertiesSet() throws Exception {}
38
39
40
41
42
43
44
45 public UserDetails loadUserByTicketResponse(KualiTicketResponse response) {
46 GrantedAuthority[] authorities = new GrantedAuthority[1];
47 authorities[0]= new GrantedAuthorityImpl(response.getDistributedSessionToken());
48 if (logger.isDebugEnabled()) {
49 logger.debug("loadUserByTicketResponse:" + response.getDistributedSessionToken());
50 }
51 return loadUserByUsernameAndAuthorities(response.getUser(), authorities);
52 }
53
54
55
56
57
58
59 public UserDetails loadUserByUsername(String username)
60 {
61 if (logger.isDebugEnabled()) {
62 logger.debug("loadUserByUsername");
63 }
64 return loadUserByUsernameAndAuthorities(username, new GrantedAuthority[0]);
65 }
66
67
68
69
70
71
72
73
74 public UserDetails loadUserByUsernameAndAuthorities(String username, GrantedAuthority[] authorities) {
75 if (logger.isDebugEnabled()) {
76 logger.debug("loadUserByUsernameAndAuthorities");
77 }
78 GrantedAuthority[] newAuthorities = new GrantedAuthority[authorities.length+1];
79 System.arraycopy(authorities, 0, newAuthorities, 0, authorities.length);
80 newAuthorities[authorities.length]= new GrantedAuthorityImpl("ROLE_KUALI_USER");
81 logger.warn("setting granted authorities:" + newAuthorities.toString());
82 UserDetails user = new User(username, "empty_password", true, true, true, true, newAuthorities);
83 return user;
84 }
85
86
87 }