Commit 79677439 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

725: Migrate user profile page / information

Task-Url: https://minfba.de.dariah.eu/mantisbt/view.php?id=725
parent fd711f07
package eu.dariah.de.dariahsp.saml.model;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import org.opensaml.saml2.core.Assertion;
import org.opensaml.saml2.core.Attribute;
import org.opensaml.saml2.core.NameID;
import org.springframework.security.saml.SAMLCredential;
public class SAMLAggregatedCredential extends SAMLCredential {
private static final long serialVersionUID = -4550065741514736227L;
private final List<Attribute> aggregatedAttributes;
public List<Attribute> getAggregatedAttributes() { return aggregatedAttributes; }
public SAMLAggregatedCredential(NameID nameID, Assertion authenticationAssertion, String remoteEntityID, String localEntityID) {
super(nameID, authenticationAssertion, remoteEntityID, Collections.<Attribute>emptyList(), localEntityID);
this.aggregatedAttributes = null;
}
public SAMLAggregatedCredential(NameID nameID, Assertion authenticationAssertion, String remoteEntityID, List<Attribute> attributes, String localEntityID) {
super(nameID, authenticationAssertion, remoteEntityID, null, attributes, localEntityID);
this.aggregatedAttributes = null;
}
public SAMLAggregatedCredential(NameID nameID, Assertion authenticationAssertion, String remoteEntityID, String relayState, List<Attribute> attributes, String localEntityID) {
super(nameID, authenticationAssertion, remoteEntityID, relayState, attributes, localEntityID, null);
this.aggregatedAttributes = null;
}
public SAMLAggregatedCredential(NameID nameID, Assertion authenticationAssertion, String remoteEntityID, String relayState, List<Attribute> attributes, String localEntityID, Serializable additionalData) {
super(nameID, authenticationAssertion, remoteEntityID, relayState, attributes, localEntityID, additionalData);
this.aggregatedAttributes = null;
}
public SAMLAggregatedCredential(SAMLCredential baseCredential, List<Attribute> aggregatedAttributes) {
super(baseCredential.getNameID(), baseCredential.getAuthenticationAssertion(), baseCredential.getRemoteEntityID(), baseCredential.getRelayState(), baseCredential.getAttributes(), baseCredential.getLocalEntityID(), baseCredential.getAdditionalData());
this.aggregatedAttributes = aggregatedAttributes;
}
}
package eu.dariah.de.dariahsp.saml.model;
import java.util.List;
import eu.dariah.de.dariahsp.model.UserImpl;
import eu.dariah.de.dariahsp.saml.SAMLAttribute;
public class SAMLUserImpl extends UserImpl {
private static final long serialVersionUID = -906528575049375837L;
private List<SAMLAttribute> originalAttributes;
private List<SAMLAttribute> aggregatedAttributes;
public List<SAMLAttribute> getOriginalAttributes() { return originalAttributes; }
public void setOriginalAttributes(List<SAMLAttribute> originalAttributes) { this.originalAttributes = originalAttributes; }
public List<SAMLAttribute> getAggregatedAttributes() { return aggregatedAttributes; }
public void setAggregatedAttributes(List<SAMLAttribute> aggregatedAttributes) { this.aggregatedAttributes = aggregatedAttributes; }
}
\ No newline at end of file
......@@ -22,6 +22,9 @@ import eu.dariah.de.dariahsp.model.Role;
import eu.dariah.de.dariahsp.model.RoleImpl;
import eu.dariah.de.dariahsp.model.User;
import eu.dariah.de.dariahsp.model.UserImpl;
import eu.dariah.de.dariahsp.saml.SAMLAttribute;
import eu.dariah.de.dariahsp.saml.model.SAMLAggregatedCredential;
import eu.dariah.de.dariahsp.saml.model.SAMLUserImpl;
public abstract class BaseUserService implements UserService, SAMLUserDetailsService {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
......@@ -125,16 +128,42 @@ public abstract class BaseUserService implements UserService, SAMLUserDetailsSer
throw new UserCredentialsException(UserCredentialsExceptionTypes.ID_ATTRIBUTE_NOT_PROVIDED, "No reidentifiable entityId available for user's home IDP");
}
UserImpl u = new UserImpl();
SAMLUserImpl u = new SAMLUserImpl();
u.setEndpointId(fetchEndpoint);
u.setEndpointName(fetchEndpoint);
u.setUsername(fetchNameId.toLowerCase());
u.setHasAllAttributes(true);
u.setAuthorities(roles);
u.setAuthorities(roles);
u.setOriginalAttributes(this.convertAttributes(credential.getAttributes()));
if (credential instanceof SAMLAggregatedCredential) {
u.setAggregatedAttributes(this.convertAttributes(((SAMLAggregatedCredential)credential).getAggregatedAttributes()));
}
return u;
}
private List<SAMLAttribute> convertAttributes(List<Attribute> attributes) {
if (attributes==null) {
return null;
}
List<SAMLAttribute> result = new ArrayList<SAMLAttribute>();
SAMLAttribute a;
for (Attribute aIn : attributes) {
if (aIn.getAttributeValues()!=null) {
for (XMLObject xVal : aIn.getAttributeValues()) {
a = new SAMLAttribute();
a.setNameFormat(aIn.getNameFormat());
a.setName(aIn.getName());
a.setFriendlyName(aIn.getFriendlyName());
a.setValue(xVal.toString());
result.add(a);
}
}
}
return result;
}
private String getDistinctValue(List<XMLObject> attrValues) throws Exception {
if (attrValues.size() != 1) {
......
package eu.dariah.de.dariahsp.sample.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import eu.dariah.de.dariahsp.model.User;
import eu.dariah.de.dariahsp.service.UserService;
@Controller
@RequestMapping("/user")
public class UserProfileController {
@Autowired private UserService userService;
@RequestMapping(value="/", method=RequestMethod.GET)
public String showProfile(Model model) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
User user = null;
if (auth != null && auth.getDetails() instanceof User) {
user = (User)auth.getDetails();
if (user != null) {
model.addAttribute("user", userService.loadUserByUsername(user.getEndpointId(), user.getNameId()));
model.addAttribute("authorityList", user.getAuthorities());
return "user";
}
}
return null;
}
}
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<tiles:importAttribute name="fluidLayout" />
<div class="jumbotron">
<div class="container<c:if test="${fluidLayout==true}">-fluid</c:if>">
<div class="row">
<div class="xs-hidden sm-visible col-sm-3 col-lg-2 col-sm-offset-1">
<div class="pull-right dariah-flower-white-83">DARIAHSP Test App</div>
</div>
</div>
</div>
</div>
<div class="container<c:if test="${fluidLayout==true}">-fluid</c:if>">
<div class="row">
<div id="main-content-wrapper" class="col-sm-10 col-sm-offset-1">
<ul class="breadcrumb">
<li class="active">Home</li>
</ul>
<div id="main-content">
<h2>Home</h2>
<sf:form class="form-horizontal" style="clear: both;" modelAttribute="user" method="post" commandName="user" action="profile">
<fieldset>
<sf:hidden path="id" />
<legend>Your assigned privileges</legend>
<div class="control-group">
<label class="control-label" for="user_roles">Assigned roles: </label>
<div class="controls">
<select class="input-xlarge uneditable-input" multiple id="user_roles">
<c:forEach items="${authorityList}" var="authority">
<option>${authority.authority}</option>
</c:forEach>
</select>
</div>
</div>
<legend>Information from your identity providers</legend>
<div class="control-group">
<label class="control-label" for="user_endpoint">Original identity Provider: </label>
<div class="controls">
<sf:input disabled="true" class="input-xxlarge uneditable-input" path="endpointName" id="user_endpoint" />
<sf:errors path="endpointName" cssClass="error" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="user_username">Username: </label>
<div class="controls">
<sf:input disabled="true" class="input-xxlarge uneditable-input" path="username" id="user_username" />
<sf:errors path="username" cssClass="error" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="user_username">Attributes: </label>
<div class="controls">
<c:if test="${user.originalAttributes!=null}">
<ul>
<c:forEach items="${user.originalAttributes}" var="attr">
<li>${attr.friendlyName}</li>
</c:forEach>
</ul>
</c:if>
</div>
</div>
<div class="control-group">
<label class="control-label" for="user_username">Aggregated attributes: </label>
<div class="controls">
<c:if test="${user.aggregatedAttributes!=null}">
<ul>
<c:forEach items="${user.aggregatedAttributes}" var="attr">
<li>${attr.friendlyName}</li>
</c:forEach>
</ul>
</c:if>
</div>
</div>
</fieldset>
</sf:form>
</div>
</div>
</div>
</div>
......@@ -55,6 +55,11 @@
<put-attribute name="content" value="/WEB-INF/view/jsp/error.jsp" />
</definition>
<!-- User profile -->
<definition name="user" extends="template_simple">
<put-attribute name="content" value="/WEB-INF/view/jsp/user.jsp" />
</definition>
</tiles-definitions>
\ No newline at end of file
Supports Markdown
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