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

add generic store and callback hook for oidc

parent 3d233f3b
package edu.kit.scc.webreg.entity.oidc;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.MapKeyColumn;
import javax.persistence.Table;
import edu.kit.scc.webreg.entity.AbstractBaseEntity;
......@@ -33,6 +38,12 @@ public class OidcRpConfigurationEntity extends AbstractBaseEntity {
@Column(name = "callback_url", length = 1024)
private String callbackUrl;
@ElementCollection
@JoinTable(name = "oidc_rp_configuration_generic_store")
@MapKeyColumn(name = "key_data", length = 128)
@Column(name = "value_data", length = 2048)
private Map<String, String> genericStore;
public String getName() {
return name;
}
......@@ -88,4 +99,12 @@ public class OidcRpConfigurationEntity extends AbstractBaseEntity {
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}
public Map<String, String> getGenericStore() {
return genericStore;
}
public void setGenericStore(Map<String, String> genericStore) {
this.genericStore = genericStore;
}
}
......@@ -73,12 +73,16 @@ import edu.kit.scc.webreg.event.UserEvent;
import edu.kit.scc.webreg.exc.EventSubmitException;
import edu.kit.scc.webreg.exc.RegisterException;
import edu.kit.scc.webreg.exc.UserUpdateException;
import edu.kit.scc.webreg.hook.UserUpdateHook;
import edu.kit.scc.webreg.hook.UserUpdateHookException;
import edu.kit.scc.webreg.script.ScriptingEnv;
import edu.kit.scc.webreg.service.SerialService;
import edu.kit.scc.webreg.service.ServiceService;
import edu.kit.scc.webreg.service.UserServiceHook;
import edu.kit.scc.webreg.service.impl.AttributeMapHelper;
import edu.kit.scc.webreg.service.impl.HookManager;
import edu.kit.scc.webreg.service.reg.AttributeSourceQueryService;
import edu.kit.scc.webreg.service.reg.ScriptingWorkflow;
import edu.kit.scc.webreg.service.reg.impl.Registrator;
@ApplicationScoped
......@@ -134,6 +138,9 @@ public class OidcUserUpdater implements Serializable {
@Inject
private OidcOpMetadataSingletonBean opMetadataBean;
@Inject
private ScriptingEnv scriptingEnv;
public OidcUserEntity updateUserFromOP(OidcUserEntity user, String executor)
throws UserUpdateException {
user = userDao.merge(user);
......@@ -242,7 +249,30 @@ public class OidcUserUpdater implements Serializable {
auditor.startAuditTrail(executor);
auditor.setName(getClass().getName() + "-UserUpdate-Audit");
auditor.setDetail("Update OIDC user " + user.getSubjectId());
UserUpdateHook updateHook = null;
if (user.getIssuer().getGenericStore().containsKey("user_update_hook")) {
String hookClass = user.getIssuer().getGenericStore().get("user_update_hook");
try {
updateHook = (UserUpdateHook) Class.forName(hookClass).getDeclaredConstructor().newInstance();
if (updateHook instanceof ScriptingWorkflow)
((ScriptingWorkflow) updateHook).setScriptingEnv(scriptingEnv);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException
| ClassNotFoundException e) {
logger.warn("Cannot instantiate updateHook class. This is probably a misconfiguration.");
}
}
if (updateHook != null) {
try {
updateHook.preUpdateUser(user, user.getIssuer().getGenericStore(), attributeMap, executor, service, null);
} catch (UserUpdateHookException e) {
logger.warn("An exception happened while calling UserUpdateHook!", e);
}
}
// List to store parent services, that are not registered. Need to be registered
// later, when attribute map is populated
List<ServiceEntity> delayedRegisterList = new ArrayList<ServiceEntity>();
......@@ -347,7 +377,15 @@ public class OidcUserUpdater implements Serializable {
logger.warn("Parent registrytion didn't work out like it should", e);
}
}
if (updateHook != null) {
try {
updateHook.postUpdateUser(user, user.getIssuer().getGenericStore(), attributeMap, executor, service, null);
} catch (UserUpdateHookException e) {
logger.warn("An exception happened while calling UserUpdateHook!", e);
}
}
user.setLastUpdate(new Date());
user.setLastFailedUpdate(null);
user.setScheduledUpdate(getNextScheduledUpdate());
......
......@@ -12,13 +12,10 @@ package edu.kit.scc.webreg.bean.admin.oidc;
import java.io.Serializable;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Named;
import edu.kit.scc.webreg.entity.oidc.OidcRpConfigurationEntity;
import edu.kit.scc.webreg.service.oidc.OidcRpConfigurationService;
......@@ -29,8 +26,6 @@ public class ShowOidcRpConfigurationBean implements Serializable {
private static final long serialVersionUID = 1L;
private static Logger logger = LoggerFactory.getLogger(ShowOidcRpConfigurationBean.class);
@Inject
private OidcRpConfigurationService service;
......@@ -38,13 +33,29 @@ public class ShowOidcRpConfigurationBean implements Serializable {
private Long id;
private String newKey;
private String newValue;
public void preRenderView(ComponentSystemEvent ev) {
if (entity == null) {
entity = service.findById(id);
}
}
public void addGenericStore() {
getEntity().getGenericStore().put(newKey, newValue);
entity = service.save(getEntity());
newKey = "";
newValue = "";
}
public void removeGenericStore(String key) {
newKey = key;
newValue = getEntity().getGenericStore().remove(key);
entity = service.save(getEntity());
}
public OidcRpConfigurationEntity getEntity() {
if (entity == null) {
entity = service.findByIdWithAttrs(id, "genericStore");
}
return entity;
}
......@@ -59,4 +70,20 @@ public class ShowOidcRpConfigurationBean implements Serializable {
public void setId(Long id) {
this.id = id;
}
public String getNewKey() {
return newKey;
}
public void setNewKey(String newKey) {
this.newKey = newKey;
}
public String getNewValue() {
return newValue;
}
public void setNewValue(String newValue) {
this.newValue = newValue;
}
}
......@@ -71,6 +71,7 @@ public class OidcClientCallbackHandlerServlet implements Servlet {
try {
callbackService.callback(requestURL.toString(), request, response);
} catch (OidcAuthenticationException e) {
logger.info("Problems encountered, while OIDC login", e);
throw new ServletException("Problems encountered: " + e.getMessage());
}
}
......
......@@ -24,41 +24,64 @@
<h:form id="form">
<h2><h:outputText value="#{messages.rp_config}: #{showOidcRpConfigurationBean.entity.name}"/></h2>
<div id="panelInline">
<p:panel header="#{messages.rp_config}">
<p:panelGrid id="baseData" columns="2">
<h:outputText value="#{messages.id}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.id}"/>
<p:panel header="#{messages.rp_config}" id="mainPanel">
<p:panelGrid id="baseData" columns="2">
<h:outputText value="#{messages.name}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.name}"/>
<h:outputText value="#{messages.id}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.id}"/>
<h:outputText value="#{messages.displayName}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.displayName}"/>
<h:outputText value="#{messages.clientId}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.clientId}"/>
<h:outputText value="#{messages.secret}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.secret}"/>
<h:outputText value="#{messages.scopes}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.scopes}"/>
<h:outputText value="#{messages.serviceUrl}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.serviceUrl}"/>
<h:outputText value="#{messages.callbackUrl}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.callbackUrl}"/>
</p:panelGrid>
<h:link outcome="edit-rp-config.xhtml" value="#{messages.edit}">
<f:param name="id" value="#{showOidcRpConfigurationBean.entity.id}"/>
</h:link>
</p:panel>
</div>
<h:outputText value="#{messages.name}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.name}"/>
<h:outputText value="#{messages.displayName}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.displayName}"/>
<h:outputText value="#{messages.clientId}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.clientId}"/>
<h:outputText value="#{messages.secret}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.secret}"/>
<h:outputText value="#{messages.scopes}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.scopes}"/>
<h:outputText value="#{messages.serviceUrl}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.serviceUrl}"/>
<h:outputText value="#{messages.callbackUrl}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.callbackUrl}"/>
<h:outputText value="#{messages.generic_store}:"/>
<h:panelGroup>
<ul>
<ui:repeat var="key" value="#{showOidcRpConfigurationBean.entity.genericStore.keySet().toArray()}">
<li>
<h:panelGrid id="newPropTable" columns="3" columnClasses="labelColumn, elementColumn">
<h:outputText value="#{key}:"/>
<h:outputText value="#{showOidcRpConfigurationBean.entity.genericStore.get(key)}"/>
<h:commandLink value="(#{messages.delete})" action="#{showOidcRpConfigurationBean.removeGenericStore(key)}">
<f:ajax render=":form:mainPanel" />
</h:commandLink>
</h:panelGrid>
</li>
</ui:repeat>
</ul>
<h:panelGrid id="newPropTable" columns="3" columnClasses="labelColumn, elementColumn">
<h:inputText id="key_input" value="#{showOidcRpConfigurationBean.newKey}"/>
<h:inputText id="value_input" value="#{showOidcRpConfigurationBean.newValue}"/>
<h:commandLink value="#{messages.add}" action="#{showOidcRpConfigurationBean.addGenericStore()}">
<f:ajax execute=":form:mainPanel" render=":form:mainPanel" />
</h:commandLink>
</h:panelGrid>
</h:panelGroup>
</p:panelGrid>
<h:link outcome="edit-rp-config.xhtml" value="#{messages.edit}">
<f:param name="id" value="#{showOidcRpConfigurationBean.entity.id}"/>
</h:link>
</p:panel>
</h:form>
</ui:define>
......
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