NIHVIVO-2716 Detect root users in the UserAccountsSelector, so we can do a special display in the Accounts List page.

This commit is contained in:
j2blake 2011-06-16 16:35:59 +00:00
parent a0be04054a
commit f436ef194e
5 changed files with 39 additions and 11 deletions

View file

@ -206,6 +206,7 @@ public class UserAccount {
+ (", passwordChangeRequired=" + passwordChangeRequired) + (", passwordChangeRequired=" + passwordChangeRequired)
+ (", loginCount=" + loginCount) + (", status=" + status) + (", loginCount=" + loginCount) + (", status=" + status)
+ (", externalAuthId=" + externalAuthId) + (", externalAuthId=" + externalAuthId)
+ (", rootUser=" + rootUser)
+ (", permissionSetUris=" + permissionSetUris) + "]"; + (", permissionSetUris=" + permissionSetUris) + "]";
} }
} }

View file

@ -39,7 +39,7 @@ public class UserAccountsSelector {
+ "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \n" + "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \n"
+ "PREFIX auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#> \n"; + "PREFIX auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#> \n";
private static final String ALL_VARIABLES = "?uri ?email ?firstName ?lastName ?pwd ?expire ?count ?status"; private static final String ALL_VARIABLES = "?uri ?email ?firstName ?lastName ?pwd ?expire ?count ?status ?isRoot";
private static final String COUNT_VARIABLE = "?uri"; private static final String COUNT_VARIABLE = "?uri";
@ -169,7 +169,8 @@ public class UserAccountsSelector {
+ " OPTIONAL { ?uri auth:md5password ?pwd } \n" + " OPTIONAL { ?uri auth:md5password ?pwd } \n"
+ " OPTIONAL { ?uri auth:passwordChangeExpires ?expire } \n" + " OPTIONAL { ?uri auth:passwordChangeExpires ?expire } \n"
+ " OPTIONAL { ?uri auth:loginCount ?count } \n" + " OPTIONAL { ?uri auth:loginCount ?count } \n"
+ " OPTIONAL { ?uri auth:status ?status }"; + " OPTIONAL { ?uri auth:status ?status } \n"
+ " OPTIONAL { ?uri ?isRoot auth:RootUserAccount }";
} }
private String filterClauses() { private String filterClauses() {
@ -203,9 +204,8 @@ public class UserAccountsSelector {
/** /**
* Escape any regex special characters in the string. * Escape any regex special characters in the string.
* *
* Note that the SPARQL * Note that the SPARQL parser requires two backslashes, in order to pass a
* parser requires two backslashes, in order to pass a single backslash to * single backslash to the REGEX function.
* the REGEX function.
*/ */
private String escapeForRegex(String raw) { private String escapeForRegex(String raw) {
StringBuilder clean = new StringBuilder(); StringBuilder clean = new StringBuilder();
@ -327,6 +327,7 @@ public class UserAccountsSelector {
user.setPasswordLinkExpires(ifLongPresent(solution, "expire", 0L)); user.setPasswordLinkExpires(ifLongPresent(solution, "expire", 0L));
user.setLoginCount(ifIntPresent(solution, "count", 0)); user.setLoginCount(ifIntPresent(solution, "count", 0));
user.setStatus(parseStatus(solution, "status", null)); user.setStatus(parseStatus(solution, "status", null));
user.setRootUser(solution.contains("isRoot"));
return user; return user;
} }

View file

@ -238,12 +238,17 @@ public class UserAccountsListPage extends UserAccountsPage {
private List<String> findPermissionSetLabels(UserAccount account) { private List<String> findPermissionSetLabels(UserAccount account) {
List<String> labels = new ArrayList<String>(); List<String> labels = new ArrayList<String>();
if (account.isRootUser()) {
labels.add("ROOT");
} else {
for (String uri : account.getPermissionSetUris()) { for (String uri : account.getPermissionSetUris()) {
PermissionSet pSet = userAccountsDao.getPermissionSetByUri(uri); PermissionSet pSet = userAccountsDao.getPermissionSetByUri(uri);
if (pSet != null) { if (pSet != null) {
labels.add(pSet.getLabel()); labels.add(pSet.getLabel());
} }
} }
}
return labels; return labels;
} }

View file

@ -12,7 +12,6 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -91,6 +90,27 @@ public class UserAccountsSelectorTest extends AbstractTestClass {
Collections Collections
.singleton("http://vivo.mydomain.edu/individual/role2"), .singleton("http://vivo.mydomain.edu/individual/role2"),
acct.getPermissionSetUris()); acct.getPermissionSetUris());
assertEquals("rootUser", false, acct.isRootUser());
}
@Test
public void checkFieldsForRootUser() {
selectOnCriteria(1, 8, DEFAULT_ORDERING, "", "");
assertSelectedUris(10, "user08");
UserAccount acct = selection.getUserAccounts().get(0);
assertEquals("uri", "http://vivo.mydomain.edu/individual/user08",
acct.getUri());
assertEquals("email", "email@henry.edu", acct.getEmailAddress());
assertEquals("firstName", "Mary", acct.getFirstName());
assertEquals("lastName", "McInerney", acct.getLastName());
assertEquals("password", "garbage", acct.getMd5Password());
assertEquals("expires", 0L, acct.getPasswordLinkExpires());
assertEquals("loginCount", 7, acct.getLoginCount());
assertEquals("status", UserAccount.Status.ACTIVE, acct.getStatus());
assertEqualSets("permissions", Collections.<String> emptySet(),
acct.getPermissionSetUris());
assertEquals("rootUser", true, acct.isRootUser());
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

View file

@ -101,6 +101,7 @@ mydomain:user07
mydomain:user08 mydomain:user08
a auth:UserAccount ; a auth:UserAccount ;
a auth:RootUserAccount ;
auth:emailAddress "email@henry.edu" ; auth:emailAddress "email@henry.edu" ;
auth:firstName "Mary" ; auth:firstName "Mary" ;
auth:lastName "McInerney" ; auth:lastName "McInerney" ;