如果你真的要刪除它可以通過實現LogoutSuccessHandler接口來實現會話數據。
package com.arjun.security;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Service;
import com.informage.arnav.domain.CassandraLoginSession;
@Service
public class AppLogoutSuccessHandler implements LogoutSuccessHandler {
@Autowired
private CassandraLoginSessionDao cassandraLoginSessionDao;
public AppLogoutSuccessHandler() {
super();
}
@Override
public void onLogoutSuccess(HttpServletRequest request,
HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
if (authentication != null) {
final Object principal = authentication.getPrincipal();
final AppUserDetails appUserDetails;
if (principal != null && principal instanceof AppUserDetails) {
appUserDetails = (AppUserDetails) principal;
CassandraLoginSession cassandraLoginSession=cassandraLoginSessionDao.findBySessionId(appUserDetails.getSessionId().toString());
//can also delete based on userId
//CassandraLoginSession cassandraLoginSession=cassandraLoginSessionDao.findByUserId(appUserDetails.getUserId());
cassandraLoginSessionDao.hardDelete(cassandraLoginSession);
//delete the session data from DB where session is stored
}
}
}
}
在您的安全配置中,您需要配置此處理程序。
<logout logout-url="/logout" success-handler-ref="appLogoutSuccessHandler" />
我不明白這個問題。有沒有辦法做什麼?您希望網頁在每次訪問其餘服務時登錄? –
對不起,它更像這樣: 我想直接通過客戶端調用我的webservices,那些應該總是通過httpBasic頭授權 - 不會以這種方式創建會話。 但我也有一個網頁,在發佈消息,評論等(webservices)之前,需要登錄(獲取會話)。這些應通過會議授權。 – user3272488
同樣的事情不是嗎?網頁需要將授權標題存儲在會話中並每次發送。 –