1 17 package org.alfresco.repo.webservice.axis; 18 19 import java.io.IOException ; 20 21 import javax.security.auth.callback.Callback ; 22 import javax.security.auth.callback.CallbackHandler ; 23 import javax.security.auth.callback.UnsupportedCallbackException ; 24 25 import org.alfresco.repo.security.authentication.AuthenticationException; 26 import org.alfresco.repo.webservice.authentication.AuthenticationFault; 27 import org.alfresco.service.cmr.security.AuthenticationService; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.ws.security.WSPasswordCallback; 31 32 38 public class TicketCallbackHandler implements CallbackHandler 39 { 40 private static final Log logger = LogFactory.getLog(TicketCallbackHandler.class); 41 42 private AuthenticationService authenticationService; 43 44 49 public void setAuthenticationService(AuthenticationService authenticationService) 50 { 51 this.authenticationService = authenticationService; 52 } 53 54 57 public void handle(Callback [] callbacks) throws IOException , UnsupportedCallbackException 58 { 59 for (int i = 0; i < callbacks.length; i++) 60 { 61 if (callbacks[i] instanceof WSPasswordCallback) 62 { 63 WSPasswordCallback pc = (WSPasswordCallback)callbacks[i]; 64 String ticket = pc.getPassword(); 65 66 if (logger.isDebugEnabled()) 67 { 68 logger.debug("Verifying ticket for: " + pc.getIdentifer()); 69 logger.debug("Ticket: " + ticket); 70 } 71 72 try 74 { 75 this.authenticationService.validate(ticket); 76 } 77 catch (AuthenticationException ae) 78 { 79 if (logger.isDebugEnabled()) 80 logger.debug("Ticket validation failed: " + ae.getMessage()); 81 82 throw new AuthenticationFault(701, "Authentication failed due to an invalid ticket"); 86 } 87 88 if (logger.isDebugEnabled()) 89 logger.debug("Ticket validated successfully"); 90 91 pc.setPassword(pc.getPassword()); 93 } 94 else 95 { 96 throw new UnsupportedCallbackException (callbacks[i], "Unrecognized Callback"); 97 } 98 } 99 } 100 } 101 | Popular Tags |