Commit 551f83b9 authored by michael.simon's avatar michael.simon
Browse files

get Display Infos from SP in Metadata

parent 09ffea52
......@@ -10,11 +10,13 @@
******************************************************************************/
package edu.kit.scc.webreg.dao;
import java.util.List;
import edu.kit.scc.webreg.entity.SamlIdpConfigurationEntity;
public interface SamlIdpConfigurationDao extends BaseDao<SamlIdpConfigurationEntity, Long> {
SamlIdpConfigurationEntity findByHostname(String hostname);
List<SamlIdpConfigurationEntity> findByHostname(String hostname);
SamlIdpConfigurationEntity findByEntityId(String entityId);
......
......@@ -10,6 +10,8 @@
******************************************************************************/
package edu.kit.scc.webreg.dao.jpa;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.persistence.NoResultException;
......@@ -43,7 +45,7 @@ public class JpaSamlIdpConfigurationDao extends JpaBaseDao<SamlIdpConfigurationE
}
@Override
public SamlIdpConfigurationEntity findByHostname(String hostname) {
public List<SamlIdpConfigurationEntity> findByHostname(String hostname) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SamlIdpConfigurationEntity> criteria = builder.createQuery(SamlIdpConfigurationEntity.class);
Root<SamlIdpConfigurationEntity> root = criteria.from(SamlIdpConfigurationEntity.class);
......@@ -54,7 +56,7 @@ public class JpaSamlIdpConfigurationDao extends JpaBaseDao<SamlIdpConfigurationE
builder.equal(elementJoin.as(String.class), hostname));
try {
return em.createQuery(criteria).getSingleResult();
return em.createQuery(criteria).getResultList();
}
catch (NoResultException e) {
return null;
......
......@@ -18,7 +18,7 @@ import edu.kit.scc.webreg.entity.ServiceSamlSpEntity;
public interface SamlIdpConfigurationService extends BaseService<SamlIdpConfigurationEntity, Long> {
SamlIdpConfigurationEntity findByHostname(String hostname);
List<SamlIdpConfigurationEntity> findByHostname(String hostname);
SamlIdpConfigurationEntity findByEntityId(String entityId);
......
......@@ -251,32 +251,10 @@ public class FederationServiceImpl extends BaseServiceImpl<FederationEntity, Lon
sp.getFederations().add(entity);
sp.setStatus(SamlMetadataEntityStatus.ACTIVE);
// metadataHelper.fillDisplayData(ed, sp);
// sp.setEntityCategoryList(metadataHelper.getEntityCategoryList(ed));
metadataHelper.fillDisplayData(ed, sp);
sp = spDao.persist(sp);
// Set<SamlIdpScopeEntity> scopes = metadataHelper.getScopes(ed, idp);
//
// List<SamlIdpScopeEntity> oldScopes;
// if (newIdp)
// oldScopes = new ArrayList<SamlIdpScopeEntity>();
// else
// oldScopes = idpScopeService.findByIdp(idp);
//
// Set<SamlIdpScopeEntity> deleteScopes = new HashSet<SamlIdpScopeEntity>(oldScopes);
// deleteScopes.removeAll(scopes);
// for (SamlIdpScopeEntity scope : deleteScopes) {
// logger.info("Deleting idp scope {}", scope.getScope());
// idpScopeService.delete(scope);
// }
//
// scopes.removeAll(oldScopes);
// for (SamlIdpScopeEntity scope : scopes) {
// logger.info("Creating new idp scope {}", scope.getScope());
// idpScopeService.save(scope);
// }
updatedList.add(sp);
}
......@@ -284,7 +262,7 @@ public class FederationServiceImpl extends BaseServiceImpl<FederationEntity, Lon
for (SamlSpMetadataEntity sp : oldList) {
sp.getFederations().remove(entity);
entity.getIdps().remove(sp);
entity.getSps().remove(sp);
if (sp.getFederations().size() == 0) {
//SP is orphaned, set Status to DELETED
......
......@@ -40,7 +40,7 @@ public class SamlIdpConfigurationServiceImpl extends BaseServiceImpl<SamlIdpConf
}
@Override
public SamlIdpConfigurationEntity findByHostname(String hostname) {
public List<SamlIdpConfigurationEntity> findByHostname(String hostname) {
return dao.findByHostname(hostname);
}
......
......@@ -56,6 +56,7 @@ import org.w3c.dom.Document;
import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.entity.SamlIdpMetadataEntity;
import edu.kit.scc.webreg.entity.SamlIdpScopeEntity;
import edu.kit.scc.webreg.entity.SamlSpMetadataEntity;
import net.shibboleth.utilities.java.support.xml.BasicParserPool;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
......@@ -294,6 +295,32 @@ public class MetadataHelper implements Serializable {
}
}
public void fillDisplayData(EntityDescriptor entityDesc, SamlSpMetadataEntity sp) {
SPSSODescriptor spsso = entityDesc.getSPSSODescriptor(SAMLConstants.SAML20P_NS);
if (spsso != null) {
Extensions extensions = spsso.getExtensions();
if (extensions != null) {
List<XMLObject> uiInfoList = extensions.getUnknownXMLObjects(UIInfo.DEFAULT_ELEMENT_NAME);
if (uiInfoList.size() > 0) {
XMLObject xmlObject = uiInfoList.get(0);
if (xmlObject instanceof UIInfo) {
UIInfo uiInfo = (UIInfo) xmlObject;
if (uiInfo.getDescriptions().size() > 0) {
sp.setDescription(uiInfo.getDescriptions().get(0).getValue());
}
if (uiInfo.getDisplayNames().size() > 0) {
sp.setDisplayName(uiInfo.getDisplayNames().get(0).getValue());
}
if (uiInfo.getInformationURLs().size() > 0) {
sp.setInformationUrl(uiInfo.getInformationURLs().get(0).getValue());
}
}
}
}
}
}
public SingleSignOnService getSSO(EntityDescriptor entityDesc, String binding) {
IDPSSODescriptor idpSsoDesc = entityDesc.getIDPSSODescriptor(SAMLConstants.SAML20P_NS);
if (idpSsoDesc != null) {
......
......@@ -11,6 +11,7 @@
package edu.kit.scc.webreg.sec;
import java.io.IOException;
import java.util.List;
import javax.faces.bean.ApplicationScoped;
import javax.inject.Inject;
......@@ -64,8 +65,16 @@ public class Saml2IdpRedirectHandler {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
SamlIdpConfigurationEntity idpConfig = idpConfigService.findByHostname(request.getServerName());
if (! request.getRequestURI().equals(idpConfig.getRedirect())) {
List<SamlIdpConfigurationEntity> idpConfigList = idpConfigService.findByHostname(request.getServerName());
SamlIdpConfigurationEntity idpConfig = null;
for (SamlIdpConfigurationEntity tempIdpConfig : idpConfigList) {
if (request.getRequestURI().equals(tempIdpConfig.getRedirect())) {
idpConfig = tempIdpConfig;
break;
}
}
if (idpConfig == null) {
throw new ServletException("Unknown redirect uri");
}
......
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