Commit 3bbc224a authored by michael.simon's avatar michael.simon
Browse files

add possiblity to store idp selection

parent 772e28b0
......@@ -22,6 +22,7 @@ import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import javax.servlet.http.Cookie;
import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.entity.FederationEntity;
......@@ -42,6 +43,7 @@ import edu.kit.scc.webreg.service.oidc.OidcOpConfigurationService;
import edu.kit.scc.webreg.service.oidc.OidcRpConfigurationService;
import edu.kit.scc.webreg.service.saml.FederationSingletonBean;
import edu.kit.scc.webreg.session.SessionManager;
import edu.kit.scc.webreg.util.CookieHelper;
import edu.kit.scc.webreg.util.FacesMessageGenerator;
@ManagedBean
......@@ -83,11 +85,16 @@ public class DiscoveryLoginBean implements Serializable {
@Inject
private OidcClientConfigurationService oidcClientConfigService;
@Inject
private CookieHelper cookieHelper;
private List<FederationEntity> federationList;
private List<SamlIdpMetadataEntity> idpList;
private FederationEntity selectedFederation;
private SamlIdpMetadataEntity selectedIdp;
private Boolean storeIdpSelection;
private List<OidcRpConfigurationEntity> oidcRpList;
private OidcRpConfigurationEntity selectedOidcRp;
......@@ -136,7 +143,18 @@ public class DiscoveryLoginBean implements Serializable {
messageGenerator.addErrorMessage("Das SAML Subsystem ist noch nicht konfiguriert");
return;
}
updateIdpList();
updateIdpList();
Cookie idpCookie = cookieHelper.getCookie("preselect_idp");
if (idpCookie != null) {
Long idpId = Long.parseLong(idpCookie.getValue());
if (idpId != null) {
SamlIdpMetadataEntity idp = idpService.findById(idpId);
if (idp != null) {
selectedIdp = idp;
storeIdpSelection = true;
}
}
}
initialized = true;
}
}
......@@ -156,6 +174,12 @@ public class DiscoveryLoginBean implements Serializable {
sessionManager.setSpId(spConfig.getId());
sessionManager.setIdpId(selectedIdp.getId());
if (storeIdpSelection) {
cookieHelper.setCookie("preselect_idp", selectedIdp.getId().toString(), 356 * 24 * 3600);
}
else {
cookieHelper.setCookie("preselect_idp", "", 0);
}
try {
externalContext.redirect("/Shibboleth.sso/Login");
} catch (IOException e) {
......@@ -318,4 +342,12 @@ public class DiscoveryLoginBean implements Serializable {
return clientConfig;
}
public Boolean getStoreIdpSelection() {
return storeIdpSelection;
}
public void setStoreIdpSelection(Boolean storeIdpSelection) {
this.storeIdpSelection = storeIdpSelection;
}
}
package edu.kit.scc.webreg.util;
import java.io.Serializable;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ApplicationScoped
public class CookieHelper implements Serializable {
private static final long serialVersionUID = 1L;
public void setCookie(String name, String value, int expiry) {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
Cookie cookie = null;
Cookie[] userCookies = request.getCookies();
if (userCookies != null && userCookies.length > 0) {
for (int i = 0; i < userCookies.length; i++) {
if (userCookies[i].getName().equals(name)) {
cookie = userCookies[i];
break;
}
}
}
if (cookie != null) {
cookie.setValue(value);
} else {
cookie = new Cookie(name, value);
cookie.setPath(request.getContextPath());
}
cookie.setMaxAge(expiry);
cookie.setPath("/");
cookie.setSecure(true);
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.addCookie(cookie);
}
public Cookie getCookie(String name) {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
Cookie cookie = null;
Cookie[] userCookies = request.getCookies();
if (userCookies != null && userCookies.length > 0) {
for (int i = 0; i < userCookies.length; i++) {
if (userCookies[i].getName().equals(name)) {
cookie = userCookies[i];
return cookie;
}
}
}
return null;
}
}
......@@ -73,6 +73,9 @@
var="idp" itemLabel="#{idp.displayName == null ? idp.orgName : idp.displayName}" itemValue="#{idp}"/>
<p:ajax event="dblclick" listener="#{discoveryLoginBean.login}" update=":form" />
</p:selectOneListbox>
<h:outputText value="#{messages.store_idp_selection}: " />
<h:selectBooleanCheckbox value="#{discoveryLoginBean.storeIdpSelection}" />
</h:panelGrid>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment