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:
parent
a0be04054a
commit
f436ef194e
5 changed files with 39 additions and 11 deletions
|
@ -206,6 +206,7 @@ public class UserAccount {
|
|||
+ (", passwordChangeRequired=" + passwordChangeRequired)
|
||||
+ (", loginCount=" + loginCount) + (", status=" + status)
|
||||
+ (", externalAuthId=" + externalAuthId)
|
||||
+ (", rootUser=" + rootUser)
|
||||
+ (", permissionSetUris=" + permissionSetUris) + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class UserAccountsSelector {
|
|||
+ "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \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";
|
||||
|
||||
|
@ -169,7 +169,8 @@ public class UserAccountsSelector {
|
|||
+ " OPTIONAL { ?uri auth:md5password ?pwd } \n"
|
||||
+ " OPTIONAL { ?uri auth:passwordChangeExpires ?expire } \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() {
|
||||
|
@ -203,9 +204,8 @@ public class UserAccountsSelector {
|
|||
/**
|
||||
* Escape any regex special characters in the string.
|
||||
*
|
||||
* Note that the SPARQL
|
||||
* parser requires two backslashes, in order to pass a single backslash to
|
||||
* the REGEX function.
|
||||
* Note that the SPARQL parser requires two backslashes, in order to pass a
|
||||
* single backslash to the REGEX function.
|
||||
*/
|
||||
private String escapeForRegex(String raw) {
|
||||
StringBuilder clean = new StringBuilder();
|
||||
|
@ -327,6 +327,7 @@ public class UserAccountsSelector {
|
|||
user.setPasswordLinkExpires(ifLongPresent(solution, "expire", 0L));
|
||||
user.setLoginCount(ifIntPresent(solution, "count", 0));
|
||||
user.setStatus(parseStatus(solution, "status", null));
|
||||
user.setRootUser(solution.contains("isRoot"));
|
||||
return user;
|
||||
}
|
||||
|
||||
|
|
|
@ -238,12 +238,17 @@ public class UserAccountsListPage extends UserAccountsPage {
|
|||
|
||||
private List<String> findPermissionSetLabels(UserAccount account) {
|
||||
List<String> labels = new ArrayList<String>();
|
||||
|
||||
if (account.isRootUser()) {
|
||||
labels.add("ROOT");
|
||||
} else {
|
||||
for (String uri : account.getPermissionSetUris()) {
|
||||
PermissionSet pSet = userAccountsDao.getPermissionSetByUri(uri);
|
||||
if (pSet != null) {
|
||||
labels.add(pSet.getLabel());
|
||||
}
|
||||
}
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -91,6 +90,27 @@ public class UserAccountsSelectorTest extends AbstractTestClass {
|
|||
Collections
|
||||
.singleton("http://vivo.mydomain.edu/individual/role2"),
|
||||
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());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -101,6 +101,7 @@ mydomain:user07
|
|||
|
||||
mydomain:user08
|
||||
a auth:UserAccount ;
|
||||
a auth:RootUserAccount ;
|
||||
auth:emailAddress "email@henry.edu" ;
|
||||
auth:firstName "Mary" ;
|
||||
auth:lastName "McInerney" ;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue