Commit 9df0b0a6 authored by michael.simon's avatar michael.simon
Browse files

add account linking page

parent dc1448e4
......@@ -200,6 +200,15 @@ public class OidcClientCallbackServiceImpl implements OidcClientCallbackService
MDC.put("userId", "" + user.getId());
}
/**
* TODO check more states here!
* Check session.getIdentityId. If it is set, user is already logged in. This should only happen with account linking
* There are two possiblities for account linking: user is null and user is not null. Not null means, user
* already exists.
*
* Check account linkin pin
*/
if (user == null) {
logger.info("New User detected, sending to register Page");
......
......@@ -62,6 +62,8 @@ public class SessionManager implements Serializable {
// identityId of the actual user
private Long identityId;
private String accountLinkingPin;
private Map<String, List<Object>> attributeMap;
private String originalRequestPath;
......@@ -352,4 +354,12 @@ public class SessionManager implements Serializable {
public void setOidcAuthnClientConfigId(Long oidcAuthnClientConfigId) {
this.oidcAuthnClientConfigId = oidcAuthnClientConfigId;
}
public String getAccountLinkingPin() {
return accountLinkingPin;
}
public void setAccountLinkingPin(String accountLinkingPin) {
this.accountLinkingPin = accountLinkingPin;
}
}
/*******************************************************************************
* 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.bean;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
import edu.kit.scc.webreg.entity.oidc.OidcRpConfigurationEntity;
import edu.kit.scc.webreg.service.UserService;
import edu.kit.scc.webreg.service.identity.IdentityService;
import edu.kit.scc.webreg.service.oidc.OidcRpConfigurationService;
import edu.kit.scc.webreg.session.SessionManager;
import edu.kit.scc.webreg.util.FacesMessageGenerator;
@ManagedBean
@ViewScoped
public class ConnectAccountBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private UserService userService;
@Inject
private IdentityService identityService;
@Inject
private SessionManager sessionManager;
@Inject
private OidcRpConfigurationService oidcRpService;
@Inject
private FacesMessageGenerator messageGenerator;
private IdentityEntity identity;
private List<UserEntity> userList;
private List<OidcRpConfigurationEntity> oidcRpList;
private OidcRpConfigurationEntity selectedOidcRp;
private String pin;
public void preRenderView(ComponentSystemEvent ev) {
if (identity == null) {
identity = identityService.findById(sessionManager.getIdentityId());
userList = userService.findByIdentity(identity);
}
}
public void startConnect() {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
if (selectedOidcRp != null && pin != null && pin.matches("^[a-zA-Z0-9]{4,32}$")) {
sessionManager.setOidcRelyingPartyId(selectedOidcRp.getId());
sessionManager.setAccountLinkingPin(pin);
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 IdentityEntity getIdentity() {
return identity;
}
public List<UserEntity> getUserList() {
return userList;
}
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 String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin = pin;
}
}
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:bw="http://www.scc.kit.edu/bwfacelets"
xmlns:p="http://primefaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<head>
<title></title>
</head>
<body>
<f:view>
<f:metadata>
<f:event type="javax.faces.event.PreRenderViewEvent"
listener="#{connectAccountBean.preRenderView}" />
</f:metadata>
<ui:composition template="/template/default.xhtml">
<ui:param name="title" value="#{messages.title}"/>
<ui:define name="content">
<h:form id="form" prependId="false" class="full form">
<h3><h:outputText value="#{messages.connect_account}" /></h3>
<div>
<h:outputText value="#{messages.connect_account_text}" />
</div>
<p:dataList var="user" value="#{connectAccountBean.userList}">
#{user.id}
</p:dataList>
<h:panelGrid id="oidcBaseData" columns="3" style="margin-top: 8px;">
<p:outputLabel value="#{messages.home_org}:" for="oidcBox" />
<p:selectOneListbox id="oidcBox" value="#{connectAccountBean.selectedOidcRp}" scrollHeight="120" style="width:300px;"
converter="#{oidcRpConfigurationConverter}">
<f:selectItems value="#{connectAccountBean.oidcRpList}"
var="rp" itemLabel="#{rp.displayName}" itemValue="#{rp}"/>
</p:selectOneListbox>
<p:message for="oidcBox"/>
<p:outputLabel value="#{messages.connect_account_pin}" for="pinBox"/>
<p:inputText id="pinBox" value="#{connectAccountBean.pin}">
<f:validateLength minimum="4"/>
<f:validateRegex pattern="^[a-zA-Z0-9]{4,32}$"/>
</p:inputText>
<p:message for="pinBox"/>
</h:panelGrid>
<p:commandButton id="oidcLogin" action="#{connectAccountBean.startConnect()}" value="#{messages.proceed}"
validateClient="true" update=":form"/>
</h:form>
</ui:define>
</ui:composition>
</f:view>
</body>
</html>
......@@ -82,7 +82,7 @@
<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="idpBox" />
<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}"
......
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