Commit 23e502a7 authored by michael.simon's avatar michael.simon
Browse files

first connect page and bean from oidc account linking

parent 16e71954
......@@ -206,9 +206,28 @@ public class OidcClientCallbackServiceImpl implements OidcClientCallbackService
* 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
* Check account linking pin
*/
if (session.getIdentityId() != null) {
/*
* we are in account linking mode. Session with identity is established
*/
if (user != null) {
throw new OidcAuthenticationException("Linking two existing accounts is not supported yet");
}
else {
logger.info("New User for account linking to identity {} detected, sending to register Page", session.getIdentityId());
// Store OIDC Data temporarily in Session
logger.debug("Storing relevant Oidc data in session");
session.setSubjectId(claims.getSubject().getValue());
session.setAttributeMap(oidcTokenHelper.convertToAttributeMap(claims, userInfo));
httpServletResponse.sendRedirect("/user/connect-account-oidc.xhtml");
return;
}
}
if (user == null) {
logger.info("New User detected, sending to register Page");
......
/*******************************************************************************
* 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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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 com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
import com.nimbusds.openid.connect.sdk.claims.UserInfo;
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.entity.oidc.OidcUserEntity;
import edu.kit.scc.webreg.exc.UserUpdateException;
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.service.oidc.client.OidcTokenHelper;
import edu.kit.scc.webreg.service.oidc.client.OidcUserCreateService;
import edu.kit.scc.webreg.session.SessionManager;
import edu.kit.scc.webreg.util.FacesMessageGenerator;
@ManagedBean
@ViewScoped
public class ConnectAccountOidcBean 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;
@Inject
private OidcTokenHelper tokenHelper;
@Inject
private OidcRpConfigurationService rpConfigService;
@Inject
private OidcUserCreateService userCreateService;
@Inject
private UserService service;
private IdentityEntity identity;
private List<UserEntity> userList;
private OidcRpConfigurationEntity rpConfig;
private String pin;
private Boolean errorState = false;
private Map<String, String> printableAttributesMap;
private Map<String, String> unprintableAttributesMap;
private List<String> printableAttributesList;
private OidcUserEntity entity;
public void preRenderView(ComponentSystemEvent ev) {
if (identity == null) {
identity = identityService.findById(sessionManager.getIdentityId());
userList = userService.findByIdentity(identity);
}
if (sessionManager.getOidcRelyingPartyId() == null) {
errorState = true;
messageGenerator.addResolvedErrorMessage("page-not-directly-accessible", "page-not-directly-accessible-text", true);
return;
}
rpConfig = rpConfigService.findById(sessionManager.getOidcRelyingPartyId());
if (rpConfig == null) {
errorState = true;
messageGenerator.addResolvedErrorMessage("page-not-directly-accessible", "page-not-directly-accessible-text", true);
return;
}
printableAttributesMap = new HashMap<String, String>();
unprintableAttributesMap = new HashMap<String, String>();
printableAttributesList = new ArrayList<String>();
try {
entity = userCreateService.preCreateUser(rpConfig.getId(),
sessionManager.getLocale(), sessionManager.getAttributeMap());
} catch (UserUpdateException e) {
errorState = true;
messageGenerator.addResolvedErrorMessage("missing-mandatory-attributes", e.getMessage(), true);
return;
}
if (service.findByEppn(entity.getEppn()) != null) {
errorState = true;
messageGenerator.addResolvedErrorMessage("eppn-blocked", "eppn-blocked-detail", true);
}
IDTokenClaimsSet claims = tokenHelper.claimsFromMap(sessionManager.getAttributeMap());
UserInfo userInfo = tokenHelper.userInfoFromMap(sessionManager.getAttributeMap());
printableAttributesList.add("eppn");
printableAttributesMap.put("eppn", entity.getEppn());
printableAttributesList.add("email");
printableAttributesMap.put("email", entity.getEmail());
printableAttributesList.add("sur_name");
printableAttributesMap.put("sur_name", entity.getSurName());
printableAttributesList.add("given_name");
printableAttributesMap.put("given_name", entity.getGivenName());
printableAttributesList.add("subject_id");
printableAttributesMap.put("subject_id", entity.getSubjectId());
printableAttributesList.add("issuer");
printableAttributesMap.put("issuer", rpConfig.getServiceUrl());
}
public void save() {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
}
public IdentityEntity getIdentity() {
return identity;
}
public List<UserEntity> getUserList() {
return userList;
}
public String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin = pin;
}
public Map<String, String> getPrintableAttributesMap() {
return printableAttributesMap;
}
public List<String> getPrintableAttributesList() {
return printableAttributesList;
}
public OidcUserEntity getEntity() {
return entity;
}
public Map<String, String> getUnprintableAttributesMap() {
return unprintableAttributesMap;
}
public Boolean getErrorState() {
return errorState;
}
}
<?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="#{connectAccountOidcBean.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:messages id="messageBox" showDetail="true" />
<p:dataList var="user" value="#{connectAccountOidcBean.userList}">
#{user.id}
</p:dataList>
<h3><h:outputText value="#{messages.my_data}:"/></h3>
<div class="panel">
<p:dataTable var="key" value="#{connectAccountOidcBean.printableAttributesList}">
<p:column headerText="#{messages.name}">
#{resourceBundleHelper.resolveMessage(key)}
</p:column>
<p:column headerText="#{messages.value}">
#{connectAccountOidcBean.printableAttributesMap[key]}
</p:column>
</p:dataTable>
</div>
<div class="panel">
<p:dataList var="key" value="#{connectAccountOidcBean.unprintableAttributesMap.keySet().toArray()}">
#{key}: #{connectAccountOidcBean.unprintableAttributesMap[key]}
</p:dataList>
</div>
<p:commandButton id="save" action="#{connectAccountOidcBean.save}" value="#{messages.confirm}" ajax="false"
disabled="#{connectAccountOidcBean.errorState}"/>
</h:form>
</ui:define>
</ui:composition>
</f:view>
</body>
</html>
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