public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
if (authentication == null || authentication.getDetails() == null
|| !(authentication.getDetails() instanceof SecurityContext)) return;
ForceConnectorConfig config = new ForceConnectorConfig();
try {
SecurityContext sc = ((SecurityContext) authentication.getDetails());
// Use the value from session and not the login endpoint
request.setAttribute(LogoutSuccessHandler.FORCE_ENDPOINT_ATTRIBUTE, sc.getEndPoint());
config.setServiceEndpoint(sc.getEndPoint());
config.setSessionId(sc.getSessionId());
config.setSessionRenewer(this);
ForceServiceConnector connector = new ForceServiceConnector();
connector.setConnectorConfig(config);
//logout from the partner API
connector.getConnection().logout();