Commit 288ecc13 authored by michael.simon's avatar michael.simon
Browse files

Add configuration for idp service

parent 6936fed1
/*******************************************************************************
* 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.dao;
import edu.kit.scc.webreg.entity.SamlIdpConfigurationEntity;
public interface SamlIdpConfigurationDao extends BaseDao<SamlIdpConfigurationEntity, Long> {
SamlIdpConfigurationEntity findByHostname(String hostname);
SamlIdpConfigurationEntity findByEntityId(String entityId);
}
/*******************************************************************************
* 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.dao.jpa;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.persistence.NoResultException;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.SamlIdpConfigurationDao;
import edu.kit.scc.webreg.entity.SamlIdpConfigurationEntity;
@Named
@ApplicationScoped
public class JpaSamlIdpConfigurationDao extends JpaBaseDao<SamlIdpConfigurationEntity, Long> implements SamlIdpConfigurationDao {
@Override
public SamlIdpConfigurationEntity findByEntityId(String entityId) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SamlIdpConfigurationEntity> criteria = builder.createQuery(SamlIdpConfigurationEntity.class);
Root<SamlIdpConfigurationEntity> root = criteria.from(SamlIdpConfigurationEntity.class);
criteria.where(
builder.equal(root.get("entityId"), entityId));
criteria.select(root);
try {
return em.createQuery(criteria).getSingleResult();
}
catch (NoResultException e) {
return null;
}
}
@Override
public SamlIdpConfigurationEntity findByHostname(String hostname) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SamlIdpConfigurationEntity> criteria = builder.createQuery(SamlIdpConfigurationEntity.class);
Root<SamlIdpConfigurationEntity> root = criteria.from(SamlIdpConfigurationEntity.class);
ListJoin<SamlIdpConfigurationEntity, String> elementJoin = root.joinList("hostNameList");
criteria.select(root);
criteria.where(
builder.equal(elementJoin.as(String.class), hostname));
try {
return em.createQuery(criteria).getSingleResult();
}
catch (NoResultException e) {
return null;
}
}
@Override
public Class<SamlIdpConfigurationEntity> getEntityClass() {
return SamlIdpConfigurationEntity.class;
}
}
/*******************************************************************************
* 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.entity;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "idpconfig")
public class SamlIdpConfigurationEntity extends SamlConfigurationEntity {
private static final long serialVersionUID = 1L;
@Column(name = "redirect", length = 2048)
private String redirect;
@ElementCollection
private List<String> hostNameList = new ArrayList<String>();
public List<String> getHostNameList() {
return hostNameList;
}
public void setHostNameList(List<String> hostNameList) {
this.hostNameList = hostNameList;
}
public String getRedirect() {
return redirect;
}
public void setRedirect(String redirect) {
this.redirect = redirect;
}
}
package edu.kit.scc.webreg.entity;
import javax.annotation.Generated;
import javax.persistence.metamodel.ListAttribute;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(SamlIdpConfigurationEntity.class)
public abstract class SamlIdpConfigurationEntity_ extends edu.kit.scc.webreg.entity.SamlConfigurationEntity_ {
public static volatile SingularAttribute<SamlIdpConfigurationEntity, String> redirect;
public static volatile ListAttribute<SamlIdpConfigurationEntity, String> hostNameList;
}
/*******************************************************************************
* 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.service;
import edu.kit.scc.webreg.entity.SamlIdpConfigurationEntity;
public interface SamlIdpConfigurationService extends BaseService<SamlIdpConfigurationEntity, Long> {
SamlIdpConfigurationEntity findByHostname(String hostname);
SamlIdpConfigurationEntity findByEntityId(String entityId);
}
/*******************************************************************************
* 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.service.impl;
import javax.ejb.Stateless;
import javax.inject.Inject;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.SamlIdpConfigurationDao;
import edu.kit.scc.webreg.entity.SamlIdpConfigurationEntity;
import edu.kit.scc.webreg.service.SamlIdpConfigurationService;
@Stateless
public class SamlIdpConfigurationServiceImpl extends BaseServiceImpl<SamlIdpConfigurationEntity, Long> implements SamlIdpConfigurationService {
private static final long serialVersionUID = 1L;
@Inject
private SamlIdpConfigurationDao dao;
@Override
public SamlIdpConfigurationEntity findByEntityId(String entityId) {
return dao.findByEntityId(entityId);
}
@Override
public SamlIdpConfigurationEntity findByHostname(String hostname) {
return dao.findByHostname(hostname);
}
@Override
protected BaseDao<SamlIdpConfigurationEntity, Long> getDao() {
return dao;
}
}
/*******************************************************************************
* 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.SamlIdpConfigurationEntity;
import edu.kit.scc.webreg.service.SamlIdpConfigurationService;
@Named("addSamlIdpConfigurationBean")
@RequestScoped
public class AddSamlIdpConfigurationBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private SamlIdpConfigurationService service;
private SamlIdpConfigurationEntity entity;
@PostConstruct
public void init() {
entity = service.createNew();
}
public String save() {
entity = service.save(entity);
return "show-idp-config.xhtml?faces-redirect=true&id=" + entity.getId();
}
public SamlIdpConfigurationEntity getEntity() {
return entity;
}
public void setEntity(SamlIdpConfigurationEntity 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.SamlIdpConfigurationEntity;
import edu.kit.scc.webreg.service.SamlIdpConfigurationService;
@ManagedBean
@ViewScoped
public class EditSamlIdpConfigurationBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private SamlIdpConfigurationService service;
private SamlIdpConfigurationEntity 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-idp-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 SamlIdpConfigurationEntity getEntity() {
return entity;
}
public void setEntity(SamlIdpConfigurationEntity 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;
}
}
......@@ -19,8 +19,10 @@ import javax.inject.Inject;
import javax.inject.Named;
import edu.kit.scc.webreg.entity.SamlAAConfigurationEntity;
import edu.kit.scc.webreg.entity.SamlIdpConfigurationEntity;
import edu.kit.scc.webreg.entity.SamlSpConfigurationEntity;
import edu.kit.scc.webreg.service.SamlAAConfigurationService;
import edu.kit.scc.webreg.service.SamlIdpConfigurationService;
import edu.kit.scc.webreg.service.SamlSpConfigurationService;
@Named("listSamlConfigurationBean")
......@@ -31,6 +33,7 @@ public class ListSamlConfigurationBean implements Serializable {
private List<SamlSpConfigurationEntity> spList;
private List<SamlAAConfigurationEntity> aaList;
private List<SamlIdpConfigurationEntity> idpList;
@Inject
private SamlSpConfigurationService spService;
......@@ -38,10 +41,14 @@ public class ListSamlConfigurationBean implements Serializable {
@Inject
private SamlAAConfigurationService aaService;
@Inject
private SamlIdpConfigurationService idpService;
@PostConstruct
public void init() {
spList = spService.findAll();
aaList = aaService.findAll();
idpList = idpService.findAll();
}
public List<SamlSpConfigurationEntity> getSpList() {
......@@ -52,4 +59,8 @@ public class ListSamlConfigurationBean implements Serializable {
return aaList;
}
public List<SamlIdpConfigurationEntity> getIdpList() {
return idpList;
}
}
/*******************************************************************************
* 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.SamlIdpConfigurationEntity;
import edu.kit.scc.webreg.service.SamlIdpConfigurationService;
import edu.kit.scc.webreg.service.saml.CryptoHelper;
@ManagedBean
@ViewScoped
public class ShowSamlIdpConfigurationBean implements Serializable {
private static final long serialVersionUID = 1L;
private static Logger logger = LoggerFactory.getLogger(ShowSamlIdpConfigurationBean.class);
@Inject
private SamlIdpConfigurationService service;
@Inject
private CryptoHelper cryptoHelper;
private SamlIdpConfigurationEntity entity;
private Long id;
private X509Certificate certificate;
private X509Certificate standbyCertificate;
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;
}
}
if (entity != null && entity.getStandbyCertificate() != null &&
(! entity.getStandbyCertificate().equals(""))) {
try {
standbyCertificate = cryptoHelper.getCertificate(entity.getStandbyCertificate());
} catch (IOException e) {
logger.info("No valid X509 Cert", e);
certificate = null;
}
}
}
}
public SamlIdpConfigurationEntity getEntity() {
return entity;
}
public void setEntity(SamlIdpConfigurationEntity 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;
}
public X509Certificate getStandbyCertificate() {
return standbyCertificate;
}
public void setStandbyCertificate(X509Certificate standbyCertificate) {
this.standbyCertificate = standbyCertificate;
}
}
/*******************************************************************************
* 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.ByteArrayInputStream;
import java.io.Serializable;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import org.apache.commons.codec.binary.Base64;
import org.opensaml.saml.saml2.metadata.EntityDescriptor;
import org.opensaml.saml.saml2.metadata.IDPSSODescriptor;
import org.opensaml.saml.saml2.metadata.KeyDescriptor;
import org.opensaml.xmlsec.signature.KeyInfo;
import org.opensaml.xmlsec.signature.X509Certificate;
import org.opensaml.xmlsec.signature.X509Data;
import org.slf4j.Logger;
import edu.kit.scc.webreg.entity.SamlSpMetadataEntity;
import edu.kit.scc.webreg.service.SamlSpMetadataService;
import edu.kit.scc.webreg.service.saml.SamlHelper;
@ManagedBean
@RequestScoped
public class ShowSpBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private Logger logger;
@Inject
private SamlSpMetadataService service;
@Inject