SingleLogout

This commit is contained in:
Crystal.Sea
2020-11-09 07:46:20 +08:00
parent a90fb9ad20
commit 49246f0ffa
5 changed files with 183 additions and 27 deletions

View File

@@ -17,13 +17,23 @@
package org.maxkey.web.endpoint;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.authn.SigninPrincipal;
import org.maxkey.authn.online.OnlineTicket;
import org.maxkey.authn.online.OnlineTicketServices;
import org.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.maxkey.authz.singlelogout.SamlSingleLogout;
import org.maxkey.authz.singlelogout.DefaultSingleLogout;
import org.maxkey.authz.singlelogout.LogoutType;
import org.maxkey.authz.singlelogout.SingleLogout;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsProtocols;
import org.maxkey.domain.apps.Apps;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -95,7 +105,26 @@ public class LogoutEndpoint {
_logger.debug("re Login URL : "+ reLoginUrl);
modelAndView.addObject("reloginUrl",reLoginUrl);
onlineTicketServices.remove(((SigninPrincipal)WebContext.getAuthentication().getPrincipal()).getOnlineTicket().getTicketId());
String onlineTicketId = ((SigninPrincipal)WebContext.getAuthentication().getPrincipal()).getOnlineTicket().getTicketId();
OnlineTicket onlineTicket = onlineTicketServices.get(onlineTicketId);
Set<Entry<String, Apps>> entrySet = onlineTicket.getAuthorizedApps().entrySet();
Iterator<Entry<String, Apps>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
Entry<String, Apps> mapEntry = iterator.next();
_logger.debug("App Id : "+ mapEntry.getKey()+ " , " +mapEntry.getValue());
if( mapEntry.getValue().getLogoutType() == LogoutType.BACK_CHANNEL){
SingleLogout singleLogout;
if(mapEntry.getValue().getProtocol().equalsIgnoreCase(ConstantsProtocols.CAS)) {
singleLogout =new SamlSingleLogout();
}else {
singleLogout = new DefaultSingleLogout();
}
singleLogout.sendRequest(onlineTicket.getAuthentication(), mapEntry.getValue());
}
}
onlineTicketServices.remove(onlineTicketId);
request.getSession().invalidate();
SecurityContextHolder.clearContext();