1 17 package org.alfresco.repo.security.authentication; 18 19 import org.alfresco.service.cmr.security.AuthenticationService; 20 21 public class AuthenticationServiceImpl implements AuthenticationService 22 { 23 MutableAuthenticationDao authenticationDao; 24 25 AuthenticationComponent authenticationComponent; 26 27 TicketComponent ticketComponent; 28 29 public AuthenticationServiceImpl() 30 { 31 super(); 32 } 33 34 public void setAuthenticationDao(MutableAuthenticationDao authenticationDao) 35 { 36 this.authenticationDao = authenticationDao; 37 } 38 39 public void setTicketComponent(TicketComponent ticketComponent) 40 { 41 this.ticketComponent = ticketComponent; 42 } 43 44 public void setAuthenticationComponent(AuthenticationComponent authenticationComponent) 45 { 46 this.authenticationComponent = authenticationComponent; 47 } 48 49 public void createAuthentication(String userName, char[] password) throws AuthenticationException 50 { 51 authenticationDao.createUser(userName, password); 52 } 53 54 public void updateAuthentication(String userName, char[] oldPassword, char[] newPassword) 55 throws AuthenticationException 56 { 57 authenticationDao.updateUser(userName, newPassword); 58 } 59 60 public void setAuthentication(String userName, char[] newPassword) throws AuthenticationException 61 { 62 authenticationDao.updateUser(userName, newPassword); 63 } 64 65 public void deleteAuthentication(String userName) throws AuthenticationException 66 { 67 authenticationDao.deleteUser(userName); 68 } 69 70 public boolean getAuthenticationEnabled(String userName) throws AuthenticationException 71 { 72 return authenticationDao.getEnabled(userName); 73 } 74 75 public void setAuthenticationEnabled(String userName, boolean enabled) throws AuthenticationException 76 { 77 authenticationDao.setEnabled(userName, enabled); 78 } 79 80 public void authenticate(String userName, char[] password) throws AuthenticationException 81 { 82 try 83 { 84 authenticationComponent.authenticate(userName, password); 85 } 86 catch(AuthenticationException ae) 87 { 88 clearCurrentSecurityContext(); 89 throw ae; 90 } 91 } 92 93 public String getCurrentUserName() throws AuthenticationException 94 { 95 return authenticationComponent.getCurrentUserName(); 96 } 97 98 public void invalidateUserSession(String userName) throws AuthenticationException 99 { 100 ticketComponent.invalidateTicketByUser(userName); 101 } 102 103 public void invalidateTicket(String ticket) throws AuthenticationException 104 { 105 ticketComponent.invalidateTicketById(ticket); 106 } 107 108 public void validate(String ticket) throws AuthenticationException 109 { 110 try 111 { 112 authenticationComponent.setCurrentUser(ticketComponent.validateTicket(ticket)); 113 } 114 catch(AuthenticationException ae) 115 { 116 clearCurrentSecurityContext(); 117 throw ae; 118 } 119 } 120 121 public String getCurrentTicket() 122 { 123 return ticketComponent.getTicket(getCurrentUserName()); 124 } 125 126 public void clearCurrentSecurityContext() 127 { 128 authenticationComponent.clearCurrentSecurityContext(); 129 } 130 131 public boolean isCurrentUserTheSystemUser() 132 { 133 String userName = getCurrentUserName(); 134 if ((userName != null) && userName.equals(authenticationComponent.getSystemUserName())) 135 { 136 return true; 137 } 138 return false; 139 } 140 141 public void authenticateAsGuest() throws AuthenticationException 142 { 143 authenticationComponent.setGuestUserAsCurrentUser(); 144 } 145 146 147 } 148 | Popular Tags |