NIHVIVO-2299 Match external Auth ID against the matching property.
This commit is contained in:
parent
72314d3598
commit
734067f1b4
9 changed files with 57 additions and 90 deletions
|
@ -100,6 +100,12 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Individuals associated with the current user.
|
||||||
|
*
|
||||||
|
* TODO Currently only uses the matching property. Should also use
|
||||||
|
* "mayEditAs" type of association.
|
||||||
|
*/
|
||||||
private Collection<Individual> getAssociatedIndividuals(
|
private Collection<Individual> getAssociatedIndividuals(
|
||||||
HttpServletRequest req) {
|
HttpServletRequest req) {
|
||||||
Collection<Individual> individuals = new ArrayList<Individual>();
|
Collection<Individual> individuals = new ArrayList<Individual>();
|
||||||
|
@ -109,7 +115,6 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
|
||||||
log.debug("No Associated Individuals: not logged in.");
|
log.debug("No Associated Individuals: not logged in.");
|
||||||
return individuals;
|
return individuals;
|
||||||
}
|
}
|
||||||
String emailAddress = user.getEmailAddress();
|
|
||||||
|
|
||||||
WebappDaoFactory wdf = (WebappDaoFactory) context
|
WebappDaoFactory wdf = (WebappDaoFactory) context
|
||||||
.getAttribute("webappDaoFactory");
|
.getAttribute("webappDaoFactory");
|
||||||
|
@ -121,22 +126,8 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
|
||||||
IndividualDao indDao = wdf.getIndividualDao();
|
IndividualDao indDao = wdf.getIndividualDao();
|
||||||
|
|
||||||
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(req);
|
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(req);
|
||||||
String uri = sec.getIndividualUriFromUsername(indDao, emailAddress);
|
individuals.addAll(sec.getAssociatedIndividuals(indDao, user));
|
||||||
if (uri == null) {
|
|
||||||
log.debug("Could not find an Individual with a netId of "
|
|
||||||
+ emailAddress);
|
|
||||||
return individuals;
|
|
||||||
}
|
|
||||||
|
|
||||||
Individual ind = indDao.getIndividualByURI(uri);
|
|
||||||
if (ind == null) {
|
|
||||||
log.warn("Found a URI for the netId " + emailAddress
|
|
||||||
+ " but could not build Individual");
|
|
||||||
return individuals;
|
|
||||||
}
|
|
||||||
log.debug("Found an Individual for netId " + emailAddress + " URI: " + uri);
|
|
||||||
|
|
||||||
individuals.add(ind);
|
|
||||||
return individuals;
|
return individuals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.beans;
|
package edu.cornell.mannlib.vitro.webapp.beans;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
@ -64,7 +67,9 @@ public class SelfEditingConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SelfEditingConfiguration buildBean(HttpSession session) {
|
private static SelfEditingConfiguration buildBean(HttpSession session) {
|
||||||
String selfEditingIdMatchingProperty = ConfigurationProperties.getBean(session)
|
ConfigurationProperties config = ConfigurationProperties
|
||||||
|
.getBean(session);
|
||||||
|
String selfEditingIdMatchingProperty = config
|
||||||
.getProperty(PROPERTY_SELF_EDITING_ID_MATCHING_PROPERTY);
|
.getProperty(PROPERTY_SELF_EDITING_ID_MATCHING_PROPERTY);
|
||||||
return new SelfEditingConfiguration(selfEditingIdMatchingProperty);
|
return new SelfEditingConfiguration(selfEditingIdMatchingProperty);
|
||||||
}
|
}
|
||||||
|
@ -87,26 +92,39 @@ public class SelfEditingConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO JB This should move to UserAccountsDao.
|
/**
|
||||||
public String getIndividualUriFromUsername(IndividualDao indDao,
|
* Get all Individuals associated with this user through the matching
|
||||||
String username) {
|
* property. Never returns null.
|
||||||
|
*/
|
||||||
|
public List<Individual> getAssociatedIndividuals(IndividualDao indDao,
|
||||||
|
UserAccount user) {
|
||||||
|
if (user == null) {
|
||||||
|
log.debug("user is null");
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return getAssociatedIndividuals(indDao, user.getExternalAuthId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Individuals associated with this externalAuthId through the
|
||||||
|
* matching property. Never returns null.
|
||||||
|
*/
|
||||||
|
public List<Individual> getAssociatedIndividuals(IndividualDao indDao,
|
||||||
|
String externalAuthId) {
|
||||||
if (indDao == null) {
|
if (indDao == null) {
|
||||||
log.warn("No IndividualDao");
|
log.warn("No IndividualDao");
|
||||||
return null;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
if (username == null) {
|
if (externalAuthId == null) {
|
||||||
log.debug("username is null");
|
log.debug("externalAuthId is null");
|
||||||
return null;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
if (selfEditingIdMatchingProperty == null) {
|
if (selfEditingIdMatchingProperty == null) {
|
||||||
log.debug("selfEditingMatchingProperty is null");
|
log.debug("selfEditingMatchingProperty is null");
|
||||||
return null;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
return indDao.getIndividualsByDataProperty(
|
||||||
String uri = indDao.getIndividualURIFromNetId(username,
|
selfEditingIdMatchingProperty, externalAuthId);
|
||||||
selfEditingIdMatchingProperty);
|
|
||||||
log.debug("Username=" + username + ", individual URI=" + uri);
|
|
||||||
return uri;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource;
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.edit.Authenticate;
|
import edu.cornell.mannlib.vitro.webapp.controller.edit.Authenticate;
|
||||||
|
@ -46,7 +47,7 @@ public class BasicAuthenticator extends Authenticator {
|
||||||
}
|
}
|
||||||
return userAccountsDao.getUserAccountByEmail(emailAddress);
|
return userAccountsDao.getUserAccountByEmail(emailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserAccount getAccountForExternalAuth(String externalAuthId) {
|
public UserAccount getAccountForExternalAuth(String externalAuthId) {
|
||||||
UserAccountsDao userAccountsDao = getUserAccountsDao();
|
UserAccountsDao userAccountsDao = getUserAccountsDao();
|
||||||
|
@ -103,7 +104,6 @@ public class BasicAuthenticator extends Authenticator {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAssociatedIndividualUris(UserAccount userAccount) {
|
public List<String> getAssociatedIndividualUris(UserAccount userAccount) {
|
||||||
List<String> uris = new ArrayList<String>();
|
List<String> uris = new ArrayList<String>();
|
||||||
|
@ -195,22 +195,22 @@ public class BasicAuthenticator extends Authenticator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getUrisAssociatedBySelfEditorConfig(UserAccount user) {
|
private List<String> getUrisAssociatedBySelfEditorConfig(UserAccount user) {
|
||||||
|
List<String> uris = new ArrayList<String>();
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return Collections.emptyList();
|
return uris;
|
||||||
}
|
}
|
||||||
|
|
||||||
IndividualDao iDao = getIndividualDao();
|
IndividualDao iDao = getIndividualDao();
|
||||||
if (iDao == null) {
|
if (iDao == null) {
|
||||||
return Collections.emptyList();
|
return uris;
|
||||||
}
|
}
|
||||||
|
|
||||||
String selfEditorUri = SelfEditingConfiguration.getBean(request)
|
List<Individual> associatedIndividuals = SelfEditingConfiguration
|
||||||
.getIndividualUriFromUsername(iDao, user.getExternalAuthId());
|
.getBean(request).getAssociatedIndividuals(iDao, user);
|
||||||
if (selfEditorUri == null) {
|
for (Individual ind : associatedIndividuals) {
|
||||||
return Collections.emptyList();
|
uris.add(ind.getURI());
|
||||||
} else {
|
|
||||||
return Collections.singletonList(selfEditorUri);
|
|
||||||
}
|
}
|
||||||
|
return uris;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -238,15 +238,15 @@ public class BasicAuthenticator extends Authenticator {
|
||||||
if (wadf == null) {
|
if (wadf == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserAccountsDao userAccountsDao = wadf.getUserAccountsDao();
|
UserAccountsDao userAccountsDao = wadf.getUserAccountsDao();
|
||||||
if (userAccountsDao == null) {
|
if (userAccountsDao == null) {
|
||||||
log.error("getUserAccountsDao: no UserAccountsDao");
|
log.error("getUserAccountsDao: no UserAccountsDao");
|
||||||
}
|
}
|
||||||
|
|
||||||
return userAccountsDao;
|
return userAccountsDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a reference to the IndividualDao, or null.
|
* Get a reference to the IndividualDao, or null.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -455,8 +455,10 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
netIdStr = vreq.getParameter("netid");
|
netIdStr = vreq.getParameter("netid");
|
||||||
if ( netIdStr != null ){
|
if ( netIdStr != null ){
|
||||||
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(vreq);
|
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(vreq);
|
||||||
uri = sec.getIndividualUriFromUsername(iwDao, netIdStr);
|
List<Individual> assocInds = sec.getAssociatedIndividuals(iwDao, netIdStr);
|
||||||
return iwDao.getIndividualByURI(uri);
|
if (!assocInds.isEmpty()) {
|
||||||
|
return assocInds.get(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -108,10 +108,6 @@ public interface IndividualDao extends ObjectSourceIface {
|
||||||
/**
|
/**
|
||||||
* Returns a list of individuals with the given value for the given dataProperty. If
|
* Returns a list of individuals with the given value for the given dataProperty. If
|
||||||
* there are no Indiviuals that fit the criteria then an empty list is returned.
|
* there are no Indiviuals that fit the criteria then an empty list is returned.
|
||||||
*
|
|
||||||
* @param dataPropertyUri
|
|
||||||
* @param value
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public List<Individual> getIndividualsByDataProperty(String dataPropertyUri, String value);
|
public List<Individual> getIndividualsByDataProperty(String dataPropertyUri, String value);
|
||||||
|
|
||||||
|
@ -128,9 +124,6 @@ public interface IndividualDao extends ObjectSourceIface {
|
||||||
|
|
||||||
List<Keyword> getKeywordObjectsForIndividual(String individualURI);
|
List<Keyword> getKeywordObjectsForIndividual(String individualURI);
|
||||||
|
|
||||||
/** In most cases, it's best to let ExternalAuthHelper call this for you. */
|
|
||||||
String getIndividualURIFromNetId(String netIdStr, String netidMatchingPropertyUri);
|
|
||||||
|
|
||||||
String getNetId(String entityURI);
|
String getNetId(String entityURI);
|
||||||
|
|
||||||
String getStatus(String entityURI);
|
String getStatus(String entityURI);
|
||||||
|
|
|
@ -85,16 +85,6 @@ class IndividualDaoFiltering extends BaseFiltering implements IndividualDao{
|
||||||
innerIndividualDao.fillVClassForIndividual(individual);
|
innerIndividualDao.fillVClassForIndividual(individual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getIndividualURIFromNetId(String netIdStr, String netidMatchingPropertyUri) {
|
|
||||||
String uri = innerIndividualDao.getIndividualURIFromNetId(netIdStr, netidMatchingPropertyUri);
|
|
||||||
if( uri == null ) return null;
|
|
||||||
Individual ent = getIndividualByURI(uri);
|
|
||||||
if( ent != null && filters.getIndividualFilter().fn(ent) )
|
|
||||||
return uri;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public List<Individual> getIndividualsByDataProperty(String dataPropertyUri, String value) {
|
public List<Individual> getIndividualsByDataProperty(String dataPropertyUri, String value) {
|
||||||
return filterAndWrap(innerIndividualDao.getIndividualsByDataProperty(dataPropertyUri,value),
|
return filterAndWrap(innerIndividualDao.getIndividualsByDataProperty(dataPropertyUri,value),
|
||||||
filters);
|
filters);
|
||||||
|
|
|
@ -650,27 +650,6 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
||||||
return keywords;
|
return keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIndividualURIFromNetId(String netIdStr, String netidMatchingPropertyUri) {
|
|
||||||
if (netidMatchingPropertyUri == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Property prop = getOntModel().getProperty(netidMatchingPropertyUri);
|
|
||||||
Literal netid = getOntModel().createLiteral(netIdStr);
|
|
||||||
|
|
||||||
ResIterator stmts = null;
|
|
||||||
try{
|
|
||||||
stmts = getOntModel().listResourcesWithProperty(prop, netid);
|
|
||||||
if (stmts.hasNext()) {
|
|
||||||
return stmts.nextResource().getURI();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} finally{
|
|
||||||
if( stmts != null ) stmts.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In Jena it can be difficult to get an object with a given dataproperty if
|
* In Jena it can be difficult to get an object with a given dataproperty if
|
||||||
* you do not care about the datatype or lang of the literal. Use this
|
* you do not care about the datatype or lang of the literal. Use this
|
||||||
|
|
|
@ -205,13 +205,6 @@ public class IndividualDaoStub implements IndividualDao {
|
||||||
"IndividualDaoStub.getKeywordObjectsForIndividual() not implemented.");
|
"IndividualDaoStub.getKeywordObjectsForIndividual() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIndividualURIFromNetId(String netIdStr,
|
|
||||||
String netidMatchingPropertyUri) {
|
|
||||||
throw new RuntimeException(
|
|
||||||
"IndividualDaoStub.getIndividualURIFromNetId() not implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNetId(String entityURI) {
|
public String getNetId(String entityURI) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
|
|
|
@ -14,6 +14,7 @@ ${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/showAuth.css" /
|
||||||
<tr><th>First name:</th><td>${currentUser.firstName}</td></tr>
|
<tr><th>First name:</th><td>${currentUser.firstName}</td></tr>
|
||||||
<tr><th>Last name:</th><td>${currentUser.lastName}</td></tr>
|
<tr><th>Last name:</th><td>${currentUser.lastName}</td></tr>
|
||||||
<tr><th>Email:</th><td>${currentUser.emailAddress}</td></tr>
|
<tr><th>Email:</th><td>${currentUser.emailAddress}</td></tr>
|
||||||
|
<tr><th>External Auth ID:</th><td>${currentUser.externalAuthId}</td></tr>
|
||||||
<tr><th>Login count:</th><td>${currentUser.loginCount}</td></tr>
|
<tr><th>Login count:</th><td>${currentUser.loginCount}</td></tr>
|
||||||
<#list currentUser.permissionSetUris as role>
|
<#list currentUser.permissionSetUris as role>
|
||||||
<tr><th>Role:</th><td>${role}</td></tr>
|
<tr><th>Role:</th><td>${role}</td></tr>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue