Commit 390fc43a authored by michael.simon's avatar michael.simon
Browse files

change layout of discovery page

parent b4999beb
......@@ -79,6 +79,15 @@ public class ApplicationConfig implements Serializable {
return appConfig.getConfigOptions().get(key);
}
public String getConfigValueOrDefault(String key, String defaultValue) {
if (appConfig.getConfigOptions().containsKey(key)) {
return getConfigValue(key);
}
else {
return defaultValue;
}
}
public String deleteConfigValue(String key) {
String value = appConfig.getConfigOptions().remove(key);
appConfig = dao.persist(appConfig);
......
......@@ -90,17 +90,14 @@ public class DiscoveryLoginBean implements Serializable {
@Inject
private CookieHelper cookieHelper;
private List<FederationEntity> federationList;
private List<SamlIdpMetadataEntity> idpList;
private FederationEntity selectedFederation;
private SamlIdpMetadataEntity selectedIdp;
private List<Object> federationList;
private List<Object> idpList;
private Object selectedFederation;
private Object selectedIdp;
private Boolean storeIdpSelection;
private Boolean preSelectedIdp;
private List<OidcRpConfigurationEntity> oidcRpList;
private OidcRpConfigurationEntity selectedOidcRp;
private String filter;
/*
......@@ -141,6 +138,10 @@ public class DiscoveryLoginBean implements Serializable {
}
if (! initialized) {
if (idpList == null) {
idpList = new ArrayList<Object>();
}
preSelectedIdp = false;
if (appConfig.getConfigValue("preselect_store_idp_select") != null &&
......@@ -151,12 +152,19 @@ public class DiscoveryLoginBean implements Serializable {
storeIdpSelection = false;
}
federationList = federationBean.getFederationList();
getFederationList().addAll(federationBean.getFederationList());
if (federationList == null || federationList.size() == 0) {
messageGenerator.addErrorMessage("Das SAML Subsystem ist noch nicht konfiguriert");
return;
}
updateIdpList();
if (appConfig.getConfigValueOrDefault("show_oidc_login", "false").equalsIgnoreCase("true")) {
idpList.addAll(oidcRpService.findAll());
}
Cookie idpCookie = cookieHelper.getCookie("preselect_idp");
if (idpCookie != null) {
Long idpId = Long.parseLong(idpCookie.getValue());
......@@ -178,54 +186,50 @@ public class DiscoveryLoginBean implements Serializable {
if (selectedIdp != null) {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
String hostname = externalContext.getRequestServerName();
SamlSpConfigurationEntity spConfig;
spConfig = spService.findByHostname(hostname);
if (spConfig == null) {
messageGenerator.addErrorMessage("Es ist keine Host Konfiguration vorhanden",
"Betroffener Host: " + hostname);
return;
}
sessionManager.setSpId(spConfig.getId());
sessionManager.setIdpId(selectedIdp.getId());
if (storeIdpSelection != null && 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) {
messageGenerator.addErrorMessage("Ein Fehler ist aufgetreten",
e.toString());
}
}
else {
messageGenerator.addWarningMessage("Keine Auswahl getroffen",
"Bitte wählen Sie Ihre Heimatorganisation");
}
}
public void oidcLogin() {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
if (selectedOidcRp != null) {
sessionManager.setOidcRelyingPartyId(selectedOidcRp.getId());
try {
externalContext.redirect("/rpoidc/login");
} catch (IOException e) {
messageGenerator.addErrorMessage("Ein Fehler ist aufgetreten",
e.toString());
if (selectedIdp instanceof SamlIdpMetadataEntity) {
SamlIdpMetadataEntity idp = (SamlIdpMetadataEntity) selectedIdp;
SamlSpConfigurationEntity spConfig;
spConfig = spService.findByHostname(hostname);
if (spConfig == null) {
messageGenerator.addErrorMessage("Es ist keine Host Konfiguration vorhanden",
"Betroffener Host: " + hostname);
return;
}
sessionManager.setSpId(spConfig.getId());
sessionManager.setIdpId(idp.getId());
if (storeIdpSelection != null && storeIdpSelection) {
cookieHelper.setCookie("preselect_idp", idp.getId().toString(), 356 * 24 * 3600);
}
else {
cookieHelper.setCookie("preselect_idp", "", 0);
}
try {
externalContext.redirect("/Shibboleth.sso/Login");
} catch (IOException e) {
messageGenerator.addErrorMessage("Ein Fehler ist aufgetreten",
e.toString());
}
}
else if (selectedIdp instanceof OidcRpConfigurationEntity) {
OidcRpConfigurationEntity rp = (OidcRpConfigurationEntity) selectedIdp;
sessionManager.setOidcRelyingPartyId(rp.getId());
try {
externalContext.redirect("/rpoidc/login");
} catch (IOException e) {
messageGenerator.addErrorMessage("Ein Fehler ist aufgetreten",
e.toString());
}
}
}
else {
messageGenerator.addWarningMessage("Keine Auswahl getroffen",
"Bitte wählen Sie Ihre Heimatorganisation");
}
}
public void updateIdpList() {
if (selectedFederation == null) {
if (sessionManager.getOidcAuthnOpConfigId() != null &&
......@@ -235,7 +239,7 @@ public class DiscoveryLoginBean implements Serializable {
*/
opConfig = oidcOpConfigService.findById(sessionManager.getOidcAuthnOpConfigId());
clientConfig = oidcClientConfigService.findById(sessionManager.getOidcAuthnClientConfigId());
idpList = federationBean.getAllIdpList();
getIdpList().addAll(federationBean.getAllIdpList());
}
else if (sessionManager.getAuthnRequestIdpConfigId() != null &&
sessionManager.getAuthnRequestSpMetadataId() != null) {
......@@ -245,7 +249,7 @@ public class DiscoveryLoginBean implements Serializable {
idpConfig = idpConfigService.findById(sessionManager.getAuthnRequestIdpConfigId());
spMetadata = spMetadataService.findById(sessionManager.getAuthnRequestSpMetadataId());
List<ServiceSamlSpEntity> serviceSamlList = idpConfigService.findBySamlSpAndIdp(idpConfig, spMetadata);
idpList = new ArrayList<SamlIdpMetadataEntity>();
idpList = new ArrayList<Object>();
for (ServiceSamlSpEntity serviceSaml : serviceSamlList) {
if (serviceSaml.getScript() != null) {
......@@ -257,11 +261,13 @@ public class DiscoveryLoginBean implements Serializable {
/*
* reg-app login directly called
*/
idpList = federationBean.getAllIdpList();
getIdpList().addAll(federationBean.getAllIdpList());
}
}
else {
idpList = federationBean.getIdpList(selectedFederation);
if (selectedFederation instanceof FederationEntity) {
getIdpList().addAll(federationBean.getIdpList((FederationEntity) selectedFederation));
}
}
}
......@@ -269,45 +275,60 @@ public class DiscoveryLoginBean implements Serializable {
setPreSelectedIdp(false);
}
public List<FederationEntity> getFederationList() {
public List<Object> getFederationList() {
if (federationList == null) {
federationList = new ArrayList<Object>();
}
return federationList;
}
public FederationEntity getSelectedFederation() {
public Object getSelectedFederation() {
return selectedFederation;
}
public void setSelectedFederation(FederationEntity selectedFederation) {
public void setSelectedFederation(Object selectedFederation) {
this.selectedFederation = selectedFederation;
updateIdpList();
}
public SamlIdpMetadataEntity getSelectedIdp() {
public Object getSelectedIdp() {
return selectedIdp;
}
public void setSelectedIdp(SamlIdpMetadataEntity selectedIdp) {
public void setSelectedIdp(Object selectedIdp) {
this.selectedIdp = selectedIdp;
}
public List<SamlIdpMetadataEntity> getIdpList() {
public List<Object> getIdpList() {
if (filter == null)
return idpList;
List<SamlIdpMetadataEntity> filteredList = new ArrayList<SamlIdpMetadataEntity>();
List<Object> filteredList = new ArrayList<Object>();
for (SamlIdpMetadataEntity idp : idpList) {
if (idp.getOrgName() != null &&
Pattern.compile(
Pattern.quote(filter), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)
.matcher(idp.getOrgName()).find()) {
filteredList.add(idp);
for (Object o : idpList) {
if (o instanceof SamlIdpMetadataEntity) {
SamlIdpMetadataEntity idp = (SamlIdpMetadataEntity) o;
if (idp.getOrgName() != null &&
Pattern.compile(
Pattern.quote(filter), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)
.matcher(idp.getOrgName()).find()) {
filteredList.add(idp);
}
else if (idp.getDisplayName() != null &&
Pattern.compile(
Pattern.quote(filter), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)
.matcher(idp.getDisplayName()).find()) {
filteredList.add(idp);
}
}
else if (idp.getDisplayName() != null &&
Pattern.compile(
Pattern.quote(filter), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)
.matcher(idp.getDisplayName()).find()) {
filteredList.add(idp);
else if (o instanceof OidcRpConfigurationEntity) {
OidcRpConfigurationEntity rp = (OidcRpConfigurationEntity) o;
if (rp.getDisplayName() != null &&
Pattern.compile(
Pattern.quote(filter), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)
.matcher(rp.getDisplayName()).find()) {
filteredList.add(rp);
}
}
}
......@@ -326,21 +347,6 @@ public class DiscoveryLoginBean implements Serializable {
this.filter = filter;
}
public List<OidcRpConfigurationEntity> getOidcRpList() {
if (oidcRpList == null) {
oidcRpList = oidcRpService.findAll();
}
return oidcRpList;
}
public OidcRpConfigurationEntity getSelectedOidcRp() {
return selectedOidcRp;
}
public void setSelectedOidcRp(OidcRpConfigurationEntity selectedOidcRp) {
this.selectedOidcRp = selectedOidcRp;
}
public ApplicationConfig getAppConfig() {
return appConfig;
}
......
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.converter;
import java.io.Serializable;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.inject.Inject;
import javax.inject.Named;
import edu.kit.scc.webreg.entity.BaseEntity;
import edu.kit.scc.webreg.entity.SamlIdpMetadataEntity;
import edu.kit.scc.webreg.service.SamlIdpMetadataService;
import edu.kit.scc.webreg.service.oidc.OidcRpConfigurationService;
@Named("loginObjectConverter")
public class LoginObjectConverter implements Converter, Serializable {
private static final long serialVersionUID = 1L;
@Inject
private SamlIdpMetadataService idpService;
@Inject
private OidcRpConfigurationService rpService;
@Override
public Object getAsObject(FacesContext ctx, UIComponent component, String value)
throws ConverterException {
if (value == null || value.length() < 3) {
return null;
}
Long id = Long.decode(value.substring(2));
Object o;
if (value.startsWith("i_")) {
o = idpService.findById(id);
}
else {
o = rpService.findById(id);
}
return o;
}
@SuppressWarnings("unchecked")
@Override
public String getAsString(FacesContext ctx, UIComponent component, Object value)
throws ConverterException {
if (value == null) {
return "";
}
if (value instanceof SamlIdpMetadataEntity) {
return "i_" + ((BaseEntity<Long>)value).getId().toString();
}
else {
return "o_" + ((BaseEntity<Long>)value).getId().toString();
}
}
}
......@@ -107,7 +107,7 @@
<p:outputLabel value="#{messages.home_org}:" for="idpBox" />
<p:selectOneListbox id="idpBox" value="#{discoveryLoginBean.selectedIdp}" scrollHeight="360" style="width:auto;"
converter="#{samlIdpMetadataConverter}">
converter="#{loginObjectConverter}">
<f:selectItems value="#{discoveryLoginBean.idpList}"
var="idp" itemLabel="#{idp.displayName == null ? idp.orgName : idp.displayName}" itemValue="#{idp}"/>
<p:ajax event="dblclick" listener="#{discoveryLoginBean.login}" update=":form" />
......@@ -118,21 +118,6 @@
<p:commandButton id="login" action="#{discoveryLoginBean.login}" value="#{messages.proceed}"
update=":form" />
</p:panel>
<p:panel header="OIDC Test" rendered="#{'true'.equalsIgnoreCase(discoveryLoginBean.appConfig.getConfigValue('show_oidc_login'))}" styleClass="full">
<h:panelGrid id="oidcBaseData" columns="2" style="margin-top: 8px;">
<p:outputLabel value="#{messages.home_org}:" for="oidcBox" />
<p:selectOneListbox id="oidcBox" value="#{discoveryLoginBean.selectedOidcRp}" scrollHeight="120" style="width:300px;"
converter="#{oidcRpConfigurationConverter}">
<f:selectItems value="#{discoveryLoginBean.oidcRpList}"
var="rp" itemLabel="#{rp.displayName}" itemValue="#{rp}"/>
<p:ajax event="dblclick" listener="#{discoveryLoginBean.oidcLogin()}" update=":form" />
</p:selectOneListbox>
</h:panelGrid>
<p:commandButton id="oidcLogin" action="#{discoveryLoginBean.oidcLogin()}" value="#{messages.proceed}"
update=":form"/>
</p:panel>
</h:form>
</ui:define>
......
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