Commit 9393dcc1 authored by michael.simon's avatar michael.simon
Browse files

add first attribute to project implementation

parent 818972b8
package edu.kit.scc.webreg.entity.project;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import edu.kit.scc.webreg.entity.oidc.OidcRpConfigurationEntity;
@Entity(name = "ExternalOidcProjectEntity")
public class ExternalOidcProjectEntity extends ExternalProjectEntity {
private static final long serialVersionUID = 1L;
@ManyToOne(targetEntity = OidcRpConfigurationEntity.class)
private OidcRpConfigurationEntity rpConfig;
public OidcRpConfigurationEntity getRpConfig() {
return rpConfig;
}
public void setRpConfig(OidcRpConfigurationEntity rpConfig) {
this.rpConfig = rpConfig;
}
}
package edu.kit.scc.webreg.entity.project;
import javax.persistence.Column;
import javax.persistence.Entity;
@Entity(name = "ExternalProjectEntity")
public class ExternalProjectEntity extends ProjectEntity {
private static final long serialVersionUID = 1L;
@Column(name="external_name", length=1024)
private String externalName;
public String getExternalName() {
return externalName;
}
public void setExternalName(String externalName) {
this.externalName = externalName;
}
}
......@@ -14,11 +14,15 @@ import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.persistence.NoResultException;
import edu.kit.scc.webreg.dao.jpa.JpaBaseDao;
import edu.kit.scc.webreg.dao.project.ProjectDao;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
import edu.kit.scc.webreg.entity.oidc.OidcRpConfigurationEntity;
import edu.kit.scc.webreg.entity.project.ExternalOidcProjectEntity;
import edu.kit.scc.webreg.entity.project.ExternalProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminType;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectIdentityAdminEntity;
......@@ -65,7 +69,27 @@ public class JpaProjectDao extends JpaBaseDao<ProjectEntity, Long> implements Pr
return em.createQuery("select r from ProjectServiceEntity r where r.project = :project")
.setParameter("project", project).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<ExternalProjectEntity> findByExternalName(String externalName) {
return em.createQuery("select r from ExternalProjectEntity r where r.externalName = :externalName order by r.name")
.setParameter("externalName", externalName).getResultList();
}
@Override
public ExternalOidcProjectEntity findByExternalNameOidc(String externalName, OidcRpConfigurationEntity rpConfig) {
try {
return (ExternalOidcProjectEntity) em.createQuery("select r from ExternalOidcProjectEntity r "
+ "where r.externalName = :externalName and r.rpConfig = :rpConfig order by r.name")
.setParameter("externalName", externalName)
.setParameter("rpConfig", rpConfig)
.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
@Override
public ProjectIdentityAdminEntity addAdminToProject(ProjectEntity project, IdentityEntity identity, ProjectAdminType type) {
ProjectIdentityAdminEntity entity = new ProjectIdentityAdminEntity();
......
......@@ -15,6 +15,9 @@ import java.util.List;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
import edu.kit.scc.webreg.entity.oidc.OidcRpConfigurationEntity;
import edu.kit.scc.webreg.entity.project.ExternalOidcProjectEntity;
import edu.kit.scc.webreg.entity.project.ExternalProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminType;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectIdentityAdminEntity;
......@@ -44,4 +47,8 @@ public interface ProjectDao extends BaseDao<ProjectEntity, Long> {
List<ProjectIdentityAdminEntity> findAdminsForProject(ProjectEntity project);
List<ProjectServiceEntity> findServicesForProject(ProjectEntity project);
List<ExternalProjectEntity> findByExternalName(String externalName);
ExternalOidcProjectEntity findByExternalNameOidc(String externalName, OidcRpConfigurationEntity rpConfig);
}
......@@ -47,7 +47,7 @@ public class UserUpdateScriptHook implements UserUpdateHook, ScriptingWorkflow {
Invocable invocable = resolveScript(genericStore);
try {
invocable.invokeFunction("preUpdateUser", scriptingEnv, user, genericStore, attributeMap, service, logger, debugLog);
invocable.invokeFunction("postUpdateUser", scriptingEnv, user, genericStore, attributeMap, service, logger, debugLog);
} catch (NoSuchMethodException e) {
logger.info("No preUpdateUser Method. Skipping execution.");
} catch (ScriptException e) {
......
......@@ -12,6 +12,8 @@ import edu.kit.scc.webreg.dao.ScriptDao;
import edu.kit.scc.webreg.dao.ServiceDao;
import edu.kit.scc.webreg.dao.UserDao;
import edu.kit.scc.webreg.dao.project.ProjectDao;
import edu.kit.scc.webreg.service.project.ProjectCreater;
import edu.kit.scc.webreg.service.project.ProjectUpdater;
import edu.kit.scc.webreg.service.saml.SsoHelper;
@Named
......@@ -32,6 +34,12 @@ public class ScriptingEnv implements Serializable {
@Inject
private ProjectDao projectDao;
@Inject
private ProjectCreater projectCreater;
@Inject
private ProjectUpdater projectUpdater;
@Inject
private ServiceDao serviceDao;
......@@ -96,5 +104,21 @@ public class ScriptingEnv implements Serializable {
public void setProjectDao(ProjectDao projectDao) {
this.projectDao = projectDao;
}
public ProjectCreater getProjectCreater() {
return projectCreater;
}
public void setProjectCreater(ProjectCreater projectCreater) {
this.projectCreater = projectCreater;
}
public ProjectUpdater getProjectUpdater() {
return projectUpdater;
}
public void setProjectUpdater(ProjectUpdater projectUpdater) {
this.projectUpdater = projectUpdater;
}
}
package edu.kit.scc.webreg.service.project;
import java.util.UUID;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
......@@ -9,6 +11,7 @@ import edu.kit.scc.webreg.dao.GroupDao;
import edu.kit.scc.webreg.dao.project.LocalProjectGroupDao;
import edu.kit.scc.webreg.dao.project.ProjectDao;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
import edu.kit.scc.webreg.entity.project.ExternalOidcProjectEntity;
import edu.kit.scc.webreg.entity.project.LocalProjectGroupEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminType;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
......@@ -45,4 +48,22 @@ public class ProjectCreater {
return project;
}
public ExternalOidcProjectEntity createExternalOidcProject(String projectName, String externalName, String groupName, String shortName) {
ExternalOidcProjectEntity project = new ExternalOidcProjectEntity();
LocalProjectGroupEntity projectGroup = projectGroupDao.createNew();
projectGroup.setName(groupName);
projectGroup.setGidNumber(groupDao.getNextGID().intValue());
projectGroup = projectGroupDao.persist(projectGroup);
project.setProjectGroup(projectGroup);
project.setName(projectName);
project.setGroupName(groupName);
project.setExternalName(externalName);
project.setShortName(shortName);
project = (ExternalOidcProjectEntity) projectDao.persist(project);
return project;
}
}
......@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
......@@ -25,6 +26,9 @@ import edu.kit.scc.webreg.entity.ServiceGroupFlagEntity;
import edu.kit.scc.webreg.entity.ServiceGroupStatus;
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.entity.project.ExternalOidcProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectMembershipEntity;
import edu.kit.scc.webreg.entity.project.ProjectMembershipType;
......@@ -61,6 +65,35 @@ public class ProjectUpdater {
@Inject
private EventSubmitter eventSubmitter;
@Inject
private ProjectCreater projectCreater;
public void syncExternalOidcProject(String projectName, String externalName, String groupName, String shortName, OidcUserEntity user) {
OidcRpConfigurationEntity rpConfig = user.getIssuer();
logger.debug("Inspecting {}", projectName);
ExternalOidcProjectEntity project = dao.findByExternalNameOidc(externalName, rpConfig);
if (shortName == null) {
// generate short name, if none is set
shortName = "p_" + (UUID.randomUUID().toString().replaceAll("-", "").substring(0, 24));
}
if (project == null) {
project = projectCreater.createExternalOidcProject(projectName, externalName, groupName, shortName);
}
project.setName(projectName);
project.setGroupName(groupName);
project.getProjectGroup().setName(groupName);
project.setShortName(shortName);
project.setRpConfig(rpConfig);
dao.addMemberToProject(project, user.getIdentity(), ProjectMembershipType.MEMBER);
syncAllMembersToGroup(project, "idty-" + user.getIdentity());
triggerGroupUpdate(project, "idty-" + user.getIdentity());
}
public void updateProjectMemberList(ProjectEntity project, Set<IdentityEntity> memberList, String executor) {
project = dao.merge(project);
......
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