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)
|
+ (", passwordChangeRequired=" + passwordChangeRequired)
|
||||||
+ (", loginCount=" + loginCount) + (", status=" + status)
|
+ (", loginCount=" + loginCount) + (", status=" + status)
|
||||||
+ (", externalAuthId=" + externalAuthId)
|
+ (", externalAuthId=" + externalAuthId)
|
||||||
|
+ (", rootUser=" + rootUser)
|
||||||
+ (", permissionSetUris=" + permissionSetUris) + "]";
|
+ (", permissionSetUris=" + permissionSetUris) + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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() {
|
||||||
|
@ -201,11 +202,10 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,10 +238,15 @@ 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>();
|
||||||
for (String uri : account.getPermissionSetUris()) {
|
|
||||||
PermissionSet pSet = userAccountsDao.getPermissionSetByUri(uri);
|
if (account.isRootUser()) {
|
||||||
if (pSet != null) {
|
labels.add("ROOT");
|
||||||
labels.add(pSet.getLabel());
|
} else {
|
||||||
|
for (String uri : account.getPermissionSetUris()) {
|
||||||
|
PermissionSet pSet = userAccountsDao.getPermissionSetByUri(uri);
|
||||||
|
if (pSet != null) {
|
||||||
|
labels.add(pSet.getLabel());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return labels;
|
return labels;
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -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" ;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue