Commit 77bbfe28 authored by michael.simon's avatar michael.simon
Browse files

edit personal details data page

parent abf133f8
......@@ -18,12 +18,12 @@ import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import org.slf4j.Logger;
import com.nimbusds.openid.connect.sdk.claims.ClaimsSet;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.entity.SamlIdpMetadataEntity;
import edu.kit.scc.webreg.entity.SamlUserEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
import edu.kit.scc.webreg.entity.oidc.OidcUserEntity;
......@@ -46,14 +46,15 @@ public class UserPropertiesBean implements Serializable {
private List<UserEntity> userList;
private UserEntity user;
private SamlIdpMetadataEntity idpEntity;
private List<RoleEntity> roleList;
private List<GroupEntity> groupList;
private ClaimsSet claims;
@Inject
private Logger logger;
@Inject
private UserService userService;
......@@ -70,57 +71,61 @@ public class UserPropertiesBean implements Serializable {
private SessionManager sessionManager;
public void preRenderView(ComponentSystemEvent ev) {
if (identity == null) {
identity = identityService.findById(sessionManager.getIdentityId());
userList = userService.findByIdentity(identity);
user = userService.findByIdWithStore(userList.get(0).getId());
roleList = roleService.findByUser(user);
groupList = groupService.findByUser(user);
if (user instanceof SamlUserEntity) {
idpEntity = ((SamlUserEntity) user).getIdp();
}
else if (user instanceof OidcUserEntity) {
JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
try {
JSONObject jo = parser.parse(user.getAttributeStore().get("claims"), JSONObject.class);
claims = new ClaimsSet(jo);
} catch (ParseException e) {
System.out.println("" + e);
}
}
}
}
public SamlIdpMetadataEntity getIdpEntity() {
return idpEntity;
}
public List<RoleEntity> getRoleList() {
roleList = roleService.findByUser(getUser());
return roleList;
}
public List<GroupEntity> getGroupList() {
groupList = groupService.findByUser(getUser());
return groupList;
}
public IdentityEntity getIdentity() {
if (identity == null) {
identity = identityService.findById(sessionManager.getIdentityId());
}
return identity;
}
public List<UserEntity> getUserList() {
if (userList == null) {
userList = userService.findByIdentity(getIdentity());
}
return userList;
}
public UserEntity getUser() {
if (user == null) {
user = userService.findByIdWithStore(getUserList().get(0).getId());
}
return user;
}
public void setUser(UserEntity user) {
this.user = user;
if (user != null && (! user.equals(this.user))) {
this.user = userService.findByIdWithStore(user.getId());
claims = null;
}
}
public ClaimsSet getClaims() {
if (claims == null) {
if (getUser() instanceof OidcUserEntity) {
JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
try {
if (getUser().getAttributeStore().containsKey("claims")) {
JSONObject jo = parser.parse(getUser().getAttributeStore().get("claims"), JSONObject.class);
claims = new ClaimsSet(jo);
}
} catch (ParseException e) {
logger.warn("Wrong JSON in claims attribute", e);
}
}
}
return claims;
}
}
......@@ -27,14 +27,20 @@
<p:panel rendered="#{userPropertiesBean.userList.size() gt 1}">
<p:outputLabel for="@next" value="Choose account: " />
<p:selectOneMenu id="userSelect" value="#{userPropertiesBean.user}" converter="#{userConverter}">
<p:selectOneListbox id="userSelect" var="u" value="#{userPropertiesBean.user}" converter="#{userConverter}" class="full">
<f:selectItems value="#{userPropertiesBean.userList}" var="user" itemLabel="#{user.eppn}" itemValue="#{user}" />
</p:selectOneMenu>
<p:column>
<h:outputText value="#{u.eppn} - " />
<h:outputText value="#{u.idp.displayName}" rendered="#{u.class.simpleName eq 'SamlUserEntity'}" />
<h:outputText value="#{u.issuer.displayName}" rendered="#{u.class.simpleName eq 'OidcUserEntity'}" />
</p:column>
<f:ajax render=":form:tabVw" execute="@this" />
</p:selectOneListbox>
</p:panel>
<p:tabView id="tabVw" dynamic="true" cache="true">
<p:tab id="tab1" title="#{messages.my_data}">
<p:tabView id="tabVw" dynamic="true">
<p:tab id="tab1" title="#{messages.my_data}" rendered="#{userPropertiesBean.user.class.simpleName eq 'SamlUserEntity'}">
<div class="panel">#{messages.my_data_explanation}</div>
<div class="panel">#{messages.data_from}: <b>#{userPropertiesBean.idpEntity.orgName}</b></div>
<div class="panel">#{messages.data_from}: <b>#{userPropertiesBean.user.idp.orgName}</b></div>
<p:panelGrid id="baseData" columns="2">
<bw:outputText label="#{messages.name}" value="#{userPropertiesBean.user.surName}, #{userPropertiesBean.user.givenName}"/>
<bw:outputText label="#{messages.email}" value="#{userPropertiesBean.user.email}"/>
......@@ -43,8 +49,8 @@
<bw:outputText label="#{messages.uid_number}" value="#{userPropertiesBean.user.uidNumber}"/>
<bw:outputText label="#{messages.primary_group}" value="#{userPropertiesBean.user.primaryGroup.name} (#{userPropertiesBean.user.primaryGroup.gidNumber})"/>
<bw:outputText label="#{messages.idp}" value="#{userPropertiesBean.idpEntity.displayName}"
rendered="#{not empty userPropertiesBean.idpEntity and not empty userPropertiesBean.idpEntity.displayName}"/>
<bw:outputText label="#{messages.idp}" value="#{userPropertiesBean.user.idp.displayName}"
rendered="#{not empty userPropertiesBean.user.idp and not empty userPropertiesBean.user.idp.displayName}"/>
</p:panelGrid>
<div style="margin-top: 0.8em;">#{messages.my_data_delete_all}
......
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