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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
HttpServletRequest req) {
|
||||
Collection<Individual> individuals = new ArrayList<Individual>();
|
||||
|
@ -109,7 +115,6 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
|
|||
log.debug("No Associated Individuals: not logged in.");
|
||||
return individuals;
|
||||
}
|
||||
String emailAddress = user.getEmailAddress();
|
||||
|
||||
WebappDaoFactory wdf = (WebappDaoFactory) context
|
||||
.getAttribute("webappDaoFactory");
|
||||
|
@ -121,22 +126,8 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
|
|||
IndividualDao indDao = wdf.getIndividualDao();
|
||||
|
||||
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(req);
|
||||
String uri = sec.getIndividualUriFromUsername(indDao, emailAddress);
|
||||
if (uri == null) {
|
||||
log.debug("Could not find an Individual with a netId of "
|
||||
+ emailAddress);
|
||||
return individuals;
|
||||
}
|
||||
individuals.addAll(sec.getAssociatedIndividuals(indDao, user));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.beans;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
@ -64,7 +67,9 @@ public class SelfEditingConfiguration {
|
|||
}
|
||||
|
||||
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);
|
||||
return new SelfEditingConfiguration(selfEditingIdMatchingProperty);
|
||||
}
|
||||
|
@ -87,26 +92,39 @@ public class SelfEditingConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO JB This should move to UserAccountsDao.
|
||||
public String getIndividualUriFromUsername(IndividualDao indDao,
|
||||
String username) {
|
||||
/**
|
||||
* Get all Individuals associated with this user through the matching
|
||||
* 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) {
|
||||
log.warn("No IndividualDao");
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (username == null) {
|
||||
log.debug("username is null");
|
||||
return null;
|
||||
if (externalAuthId == null) {
|
||||
log.debug("externalAuthId is null");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (selfEditingIdMatchingProperty == null) {
|
||||
log.debug("selfEditingMatchingProperty is null");
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String uri = indDao.getIndividualURIFromNetId(username,
|
||||
selfEditingIdMatchingProperty);
|
||||
log.debug("Username=" + username + ", individual URI=" + uri);
|
||||
return uri;
|
||||
return indDao.getIndividualsByDataProperty(
|
||||
selfEditingIdMatchingProperty, externalAuthId);
|
||||
}
|
||||
|
||||
@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.AuthenticationSource;
|
||||
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.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.edit.Authenticate;
|
||||
|
@ -46,7 +47,7 @@ public class BasicAuthenticator extends Authenticator {
|
|||
}
|
||||
return userAccountsDao.getUserAccountByEmail(emailAddress);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UserAccount getAccountForExternalAuth(String externalAuthId) {
|
||||
UserAccountsDao userAccountsDao = getUserAccountsDao();
|
||||
|
@ -103,7 +104,6 @@ public class BasicAuthenticator extends Authenticator {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getAssociatedIndividualUris(UserAccount userAccount) {
|
||||
List<String> uris = new ArrayList<String>();
|
||||
|
@ -195,22 +195,22 @@ public class BasicAuthenticator extends Authenticator {
|
|||
}
|
||||
|
||||
private List<String> getUrisAssociatedBySelfEditorConfig(UserAccount user) {
|
||||
List<String> uris = new ArrayList<String>();
|
||||
if (user == null) {
|
||||
return Collections.emptyList();
|
||||
return uris;
|
||||
}
|
||||
|
||||
IndividualDao iDao = getIndividualDao();
|
||||
if (iDao == null) {
|
||||
return Collections.emptyList();
|
||||
return uris;
|
||||
}
|
||||
|
||||
String selfEditorUri = SelfEditingConfiguration.getBean(request)
|
||||
.getIndividualUriFromUsername(iDao, user.getExternalAuthId());
|
||||
if (selfEditorUri == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return Collections.singletonList(selfEditorUri);
|
||||
List<Individual> associatedIndividuals = SelfEditingConfiguration
|
||||
.getBean(request).getAssociatedIndividuals(iDao, user);
|
||||
for (Individual ind : associatedIndividuals) {
|
||||
uris.add(ind.getURI());
|
||||
}
|
||||
return uris;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -238,15 +238,15 @@ public class BasicAuthenticator extends Authenticator {
|
|||
if (wadf == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
UserAccountsDao userAccountsDao = wadf.getUserAccountsDao();
|
||||
if (userAccountsDao == null) {
|
||||
log.error("getUserAccountsDao: no UserAccountsDao");
|
||||
}
|
||||
|
||||
|
||||
return userAccountsDao;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a reference to the IndividualDao, or null.
|
||||
*/
|
||||
|
|
|
@ -455,8 +455,10 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
netIdStr = vreq.getParameter("netid");
|
||||
if ( netIdStr != null ){
|
||||
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(vreq);
|
||||
uri = sec.getIndividualUriFromUsername(iwDao, netIdStr);
|
||||
return iwDao.getIndividualByURI(uri);
|
||||
List<Individual> assocInds = sec.getAssociatedIndividuals(iwDao, netIdStr);
|
||||
if (!assocInds.isEmpty()) {
|
||||
return assocInds.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
* 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);
|
||||
|
||||
|
@ -128,9 +124,6 @@ public interface IndividualDao extends ObjectSourceIface {
|
|||
|
||||
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 getStatus(String entityURI);
|
||||
|
|
|
@ -85,16 +85,6 @@ class IndividualDaoFiltering extends BaseFiltering implements IndividualDao{
|
|||
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) {
|
||||
return filterAndWrap(innerIndividualDao.getIndividualsByDataProperty(dataPropertyUri,value),
|
||||
filters);
|
||||
|
|
|
@ -650,27 +650,6 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
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
|
||||
* you do not care about the datatype or lang of the literal. Use this
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue