Commit 0d6e3a31 authored by michael.simon's avatar michael.simon
Browse files

webapp interface step to attribute-authority

parent 2f08bee4
......@@ -37,5 +37,6 @@ public interface BaseDao<T extends BaseEntity<PK>, PK extends Serializable> {
boolean isPersisted(T entity);
T findByIdWithAttrs(PK id, String... attrs);
}
......@@ -18,10 +18,12 @@ import java.util.Map.Entry;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
......@@ -130,6 +132,28 @@ public abstract class JpaBaseDao<T extends BaseEntity<PK>, PK extends Serializab
return em.contains(entity);
}
@Override
public T findByIdWithAttrs(PK id, String... attrs) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<T> criteria = builder.createQuery(getEntityClass());
Root<T> entity = criteria.from(getEntityClass());
criteria.where(builder.and(
builder.equal(entity.get("id"), id)
));
criteria.select(entity);
criteria.distinct(true);
for (String attr : attrs)
entity.fetch(attr, JoinType.LEFT);
try {
return em.createQuery(criteria).getSingleResult();
}
catch (NoResultException e) {
return null;
}
}
protected List<Predicate> predicatesFromFilterMap(CriteriaBuilder builder, Root<T> root, Map<String, Object> filterMap) {
List<Predicate> predicates = new ArrayList<Predicate>(filterMap.size());
......
......@@ -25,7 +25,7 @@ import edu.kit.scc.webreg.entity.SamlSpConfigurationEntity;
@ApplicationScoped
public class JpaSamlSpConfigurationDao extends JpaBaseDao<SamlSpConfigurationEntity, Long> implements SamlSpConfigurationDao {
@Override
@Override
public SamlSpConfigurationEntity findByEntityId(String entityId) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SamlSpConfigurationEntity> criteria = builder.createQuery(SamlSpConfigurationEntity.class);
......
......@@ -29,6 +29,8 @@ public interface BaseService<T extends BaseEntity<PK>, PK extends Serializable>
T findById(PK id);
T findByIdWithAttrs(PK id, String... attrs);
List<T> findAllPaging(int first, int pageSize, String sortField,
GenericSortOrder sortOrder, Map<String, Object> filterMap);
......
......@@ -60,4 +60,9 @@ public abstract class BaseServiceImpl<T extends BaseEntity<PK>, PK extends Seria
public T findById(PK id) {
return getDao().findById(id);
}
@Override
public T findByIdWithAttrs(PK id, String...attrs) {
return getDao().findByIdWithAttrs(id, attrs);
}
}
......@@ -51,6 +51,12 @@ public class CryptoHelper implements Serializable {
PEMParser pemReader = new PEMParser(new StringReader(certString));
X509CertificateHolder certHolder = (X509CertificateHolder) pemReader.readObject();
pemReader.close();
if (certHolder == null) {
logger.warn("Invalid Certificate. CertHoler is null.");
return null;
}
X509Certificate cert;
try {
cert = new JcaX509CertificateConverter().setProvider("BC")
......
/*******************************************************************************
* 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.admin.saml;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import edu.kit.scc.webreg.entity.SamlAAConfigurationEntity;
import edu.kit.scc.webreg.service.SamlAAConfigurationService;
@Named("addSamlAAConfigurationBean")
@RequestScoped
public class AddSamlAAConfigurationBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private SamlAAConfigurationService service;
private SamlAAConfigurationEntity entity;
@PostConstruct
public void init() {
entity = service.createNew();
}
public String save() {
entity = service.save(entity);
return "show-aa-config.xhtml?faces-redirect=true&id=" + entity.getId();
}
public SamlAAConfigurationEntity getEntity() {
return entity;
}
public void setEntity(SamlAAConfigurationEntity entity) {
this.entity = entity;
}
}
/*******************************************************************************
* 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.admin.saml;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import edu.kit.scc.webreg.entity.SamlAAConfigurationEntity;
import edu.kit.scc.webreg.service.SamlAAConfigurationService;
@ManagedBean
@ViewScoped
public class EditSamlAAConfigurationBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private SamlAAConfigurationService service;
private SamlAAConfigurationEntity entity;
private Long id;
private List<String> hostNameList;
private String hostName;
public void preRenderView(ComponentSystemEvent ev) {
if (entity == null) {
entity = service.findByIdWithAttrs(id, "hostNameList");
hostNameList = new ArrayList<String>(entity.getHostNameList());
}
}
public String save() {
entity.setHostNameList(hostNameList);
service.save(entity);
return "show-aa-config.xhtml?faces-redirect=true&id=" + entity.getId();
}
public void addHost() {
if (hostName != null) {
hostNameList.add(hostName);
hostName = null;
}
}
public void removeHost(String key) {
setHostName(key);
hostNameList.remove(key);
}
public SamlAAConfigurationEntity getEntity() {
return entity;
}
public void setEntity(SamlAAConfigurationEntity entity) {
this.entity = entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<String> getHostNameList() {
return hostNameList;
}
public void setHostNameList(List<String> hostNameList) {
this.hostNameList = hostNameList;
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
}
......@@ -41,7 +41,7 @@ public class EditSamlSpConfigurationBean implements Serializable {
public void preRenderView(ComponentSystemEvent ev) {
if (entity == null) {
entity = service.findById(id);
entity = service.findByIdWithAttrs(id, "hostNameList");
hostNameList = new ArrayList<String>(entity.getHostNameList());
}
}
......
......@@ -18,27 +18,38 @@ import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import edu.kit.scc.webreg.entity.SamlAAConfigurationEntity;
import edu.kit.scc.webreg.entity.SamlSpConfigurationEntity;
import edu.kit.scc.webreg.service.SamlAAConfigurationService;
import edu.kit.scc.webreg.service.SamlSpConfigurationService;
@Named("listSamlSpConfigurationBean")
@Named("listSamlConfigurationBean")
@RequestScoped
public class ListSamlSpConfigurationBean implements Serializable {
public class ListSamlConfigurationBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<SamlSpConfigurationEntity> list;
private List<SamlSpConfigurationEntity> spList;
private List<SamlAAConfigurationEntity> aaList;
@Inject
private SamlSpConfigurationService service;
private SamlSpConfigurationService spService;
@Inject
private SamlAAConfigurationService aaService;
@PostConstruct
public void init() {
list = service.findAll();
spList = spService.findAll();
aaList = aaService.findAll();
}
public List<SamlSpConfigurationEntity> getSpList() {
return spList;
}
public List<SamlAAConfigurationEntity> getAaList() {
return aaList;
}
public List<SamlSpConfigurationEntity> getEntityList() {
return list;
}
}
/*******************************************************************************
* 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.admin.saml;
import java.io.IOException;
import java.io.Serializable;
import java.security.cert.X509Certificate;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.kit.scc.webreg.entity.SamlAAConfigurationEntity;
import edu.kit.scc.webreg.service.SamlAAConfigurationService;
import edu.kit.scc.webreg.service.saml.CryptoHelper;
@ManagedBean
@ViewScoped
public class ShowSamlAAConfigurationBean implements Serializable {
private static final long serialVersionUID = 1L;
private static Logger logger = LoggerFactory.getLogger(ShowSamlAAConfigurationBean.class);
@Inject
private SamlAAConfigurationService service;
@Inject
private CryptoHelper cryptoHelper;
private SamlAAConfigurationEntity entity;
private Long id;
private X509Certificate certificate;
public void preRenderView(ComponentSystemEvent ev) {
if (entity == null) {
entity = service.findByIdWithAttrs(id, "hostNameList");
if (entity != null && entity.getCertificate() != null) {
try {
certificate = cryptoHelper.getCertificate(entity.getCertificate());
} catch (IOException e) {
logger.info("No valid X509 Cert", e);
certificate = null;
}
}
}
}
public SamlAAConfigurationEntity getEntity() {
return entity;
}
public void setEntity(SamlAAConfigurationEntity entity) {
this.entity = entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public X509Certificate getCertificate() {
return certificate;
}
public void setCertificate(X509Certificate certificate) {
this.certificate = certificate;
}
}
......@@ -48,7 +48,7 @@ public class ShowSamlSpConfigurationBean implements Serializable {
public void preRenderView(ComponentSystemEvent ev) {
if (entity == null) {
entity = service.findById(id);
entity = service.findByIdWithAttrs(id, "hostNameList");
if (entity != null && entity.getCertificate() != null) {
try {
certificate = cryptoHelper.getCertificate(entity.getCertificate());
......
......@@ -72,19 +72,25 @@ public class Saml2DispatcherServlet implements Servlet {
logger.debug("Dispatching request context '{}' path '{}'", context, path);
SamlSpConfigurationEntity spConfig = spConfigService.findByHostname(request.getServerName());
SamlAAConfigurationEntity aaConfig = aaConfigService.findByHostname(request.getServerName());
if (spConfig.getAcs().endsWith(context + path)) {
if (spConfig != null && spConfig.getAcs() != null &&
spConfig.getAcs().endsWith(context + path)) {
logger.debug("Executing POST Handler for entity {}", spConfig.getEntityId());
postHandlerServlet.service(servletRequest, servletResponse, spConfig);
return;
}
else if (aaConfig.getAq().endsWith(context + path)) {
SamlAAConfigurationEntity aaConfig = aaConfigService.findByHostname(request.getServerName());
if (aaConfig != null && aaConfig.getAq() != null &&
aaConfig.getAq().endsWith(context + path)) {
logger.debug("Executing AttributeQuery Handler for entity {}", aaConfig.getEntityId());
attributeQueryServlet.service(servletRequest, servletResponse, aaConfig);
return;
}
else {
logger.info("No matching servlet for context '{}' path '{}'", context, path);
}
logger.info("No matching servlet for context '{}' path '{}'", context, path);
}
@Override
......
<!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">
<head>
<title></title>
</head>
<body>
<f:view>
<ui:composition template="/template/default-admin.xhtml">
<ui:param name="title" value="#{messages.title}"/>
<ui:define name="content">
<h:form id="form">
<h2><h:outputText value="#{messages.add_aa_config}"/></h2>
<h:panelGrid id="baseData" columns="2" columnClasses="labelColumn, elementColumn">
<h:outputText value="#{messages.entity_id}:" />
<h:inputText value="#{addSamlAAConfigurationBean.entity.entityId}" />
<h:outputLabel for="private_key" value="#{messages.private_key}:"/>
<h:inputTextarea id="private_key" rows="12" cols="80" maxlength="2048"
value="#{addSamlAAConfigurationBean.entity.privateKey}"/>
<h:outputLabel for="certificate" value="#{messages.certificate}:"/>
<h:inputTextarea id="certificate" rows="12" cols="80" maxlength="2048"
value="#{addSamlAAConfigurationBean.entity.certificate}"/>
</h:panelGrid>
<h:commandButton id="save" action="#{addSamlAAConfigurationBean.save}" value="#{messages.save}"/>
</h:form>
</ui:define>
</ui:composition>
</f:view>
</body>
</html>
<!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">
<head>
<title></title>
</head>
<body>
<f:view>
<f:metadata>
<f:viewParam name="id" value="#{editSamlAAConfigurationBean.id}"/>
<f:event type="javax.faces.event.PreRenderViewEvent"
listener="#{editSamlAAConfigurationBean.preRenderView}" />
</f:metadata>
<ui:composition template="/template/default-admin.xhtml">
<ui:param name="title" value="#{messages.title}"/>
<ui:define name="content">
<h:form id="form">
<h2><h:outputText value="#{messages.sp_config}: #{editSamlAAConfigurationBean.entity.entityId}"/></h2>
<div id="panelInline">
<p:panel header="#{messages.sp_config}">
<p:panelGrid id="baseData" columns="2">
<h:outputText value="#{messages.id}:"/>
<h:outputText value="#{editSamlAAConfigurationBean.entity.id}"/>
<bw:inputText id="entityIdField" label="#{messages.entity_id}"
value="#{editSamlAAConfigurationBean.entity.entityId}" required="true" />
<bw:inputText id="acsField" label="#{messages.aq_endpoint}"
value="#{editSamlAAConfigurationBean.entity.aq}" required="true" />
<h:outputText value="#{messages.host_names}:"/>
<p:dataTable id="propTable" var="key"
value="#{editSamlAAConfigurationBean.hostNameList}">
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.host_name}" />
</f:facet>
<h:outputText value="#{key}" />
</p:column>
<p:column>
<h:commandLink value="#{messages.delete}" action="#{editSamlAAConfigurationBean.removeHost(key)}">
<f:ajax render="@form" />
</h:commandLink>
</p:column>
</p:dataTable>
<h:outputText value="#{messages.new_host_name}:"/>
<h:panelGrid id="newPropTable" columns="2">
<h:inputText id="key_input" value="#{editSamlAAConfigurationBean.hostName}"/>
<h:commandLink value="#{messages.add}" action="#{editSamlAAConfigurationBean.addHost()}">
<f:ajax execute="form" render="form" />
</h:commandLink>
</h:panelGrid>
<h:outputLabel for="private_key" value="#{messages.private_key}:"/>
<p:inputTextarea id="private_key" rows="12" cols="80" autoResize="false"
value="#{editSamlAAConfigurationBean.entity.privateKey}"/>
<h:outputLabel for="certificate" value="#{messages.certificate}:"/>
<p:inputTextarea id="certificate" rows="12" cols="80" autoResize="false"
value="#{editSamlAAConfigurationBean.entity.certificate}"/>
</p:panelGrid>
<h:commandButton id="save" action="#{editSamlAAConfigurationBean.save}" value="#{messages.save}"/>
</p:panel>
</div>
</h:form>
</ui:define>
</ui:composition>
</f:view>
</body>
</html>
......@@ -18,7 +18,7 @@
<h:form id="form">
<p:dataTable id="dataTable" var="entity" value="#{listSamlSpConfigurationBean.entityList}">
<p:dataTable id="spDataTable" var="entity" value="#{listSamlConfigurationBean.spList}">
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.id}" />
......@@ -35,7 +35,25 @@
</p:column>
</p:dataTable>
<h:link outcome="add-sp-config.xhtml" value="#{messages.add_sp_config}"/>
<p:dataTable id="aaDataTable" var="entity" value="#{listSamlConfigurationBean.aaList}"