use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class XMLUserDatabase method getWikiNames.
/**
* Returns all WikiNames that are stored in the UserDatabase
* as an array of WikiPrincipal objects. If the database does not
* contain any profiles, this method will return a zero-length
* array.
* @return the WikiNames
* @throws WikiSecurityException In case things fail.
*/
public Principal[] getWikiNames() throws WikiSecurityException {
if (c_dom == null) {
throw new IllegalStateException("FATAL: database does not exist");
}
SortedSet<Principal> principals = new TreeSet<Principal>();
NodeList users = c_dom.getElementsByTagName(USER_TAG);
for (int i = 0; i < users.getLength(); i++) {
Element user = (Element) users.item(i);
String wikiName = user.getAttribute(WIKI_NAME);
if (wikiName == null) {
log.warn("Detected null wiki name in XMLUserDataBase. Check your user database.");
} else {
Principal principal = new WikiPrincipal(wikiName, WikiPrincipal.WIKI_NAME);
principals.add(principal);
}
}
return principals.toArray(new Principal[principals.size()]);
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class WebContainerLoginModule method login.
/**
* Logs in the user.
* @see javax.security.auth.spi.LoginModule#login()
*
* @return {@inheritDoc}
* @throws {@inheritDoc}
*/
public boolean login() throws LoginException {
HttpRequestCallback rcb = new HttpRequestCallback();
Callback[] callbacks = new Callback[] { rcb };
String userId = null;
try {
// First, try to extract a Principal object out of the request
// directly. If we find one, we're done.
m_handler.handle(callbacks);
HttpServletRequest request = rcb.getRequest();
if (request == null) {
throw new LoginException("No Http request supplied.");
}
HttpSession session = request.getSession(false);
String sid = (session == null) ? NULL : session.getId();
Principal principal = request.getUserPrincipal();
if (principal == null) {
// If no Principal in request, try the remoteUser
if (log.isDebugEnabled()) {
log.debug("No userPrincipal found for session ID=" + sid);
}
userId = request.getRemoteUser();
if (userId == null) {
if (log.isDebugEnabled()) {
log.debug("No remoteUser found for session ID=" + sid);
}
throw new FailedLoginException("No remote user found");
}
principal = new WikiPrincipal(userId, WikiPrincipal.LOGIN_NAME);
}
if (log.isDebugEnabled()) {
log.debug("Logged in container principal " + principal.getName() + ".");
}
m_principals.add(principal);
return true;
} catch (IOException e) {
log.error("IOException: " + e.getMessage());
return false;
} catch (UnsupportedCallbackException e) {
log.error("UnsupportedCallbackException: " + e.getMessage());
return false;
}
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class AclImplTest method testAlice.
@Test
public void testAlice() {
// Alice should be able to view but not edit or comment
Principal wup = new WikiPrincipal("Alice");
Assert.assertTrue("view", inArray(m_acl.findPrincipals(PagePermission.VIEW), wup));
Assert.assertFalse("edit", inArray(m_acl.findPrincipals(PagePermission.EDIT), wup));
Assert.assertFalse("comment", inArray(m_acl.findPrincipals(PagePermission.COMMENT), wup));
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class AclImplTest method testDave.
@Test
public void testDave() {
// Dave should be able to view and comment but not edit or delete
Principal wup = new WikiPrincipal("Dave");
Assert.assertTrue("view", inArray(m_acl.findPrincipals(PagePermission.VIEW), wup));
Assert.assertFalse("edit", inArray(m_acl.findPrincipals(PagePermission.EDIT), wup));
Assert.assertTrue("comment", inArray(m_acl.findPrincipals(PagePermission.COMMENT), wup));
Assert.assertFalse("delete", inArray(m_acl.findPrincipals(PagePermission.DELETE), wup));
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class AclImplTest method testGroups.
@Test
public void testGroups() {
Principal wup = new WikiPrincipal("Alice");
Assert.assertTrue("Alice view", inGroup(m_aclGroup.findPrincipals(PagePermission.VIEW), wup));
Assert.assertTrue("Alice edit", inGroup(m_aclGroup.findPrincipals(PagePermission.EDIT), wup));
Assert.assertTrue("Alice comment", inGroup(m_aclGroup.findPrincipals(PagePermission.COMMENT), wup));
Assert.assertFalse("Alice delete", inGroup(m_aclGroup.findPrincipals(PagePermission.DELETE), wup));
wup = new WikiPrincipal("Bob");
Assert.assertTrue("Bob view", inGroup(m_aclGroup.findPrincipals(PagePermission.VIEW), wup));
Assert.assertTrue("Bob edit", inGroup(m_aclGroup.findPrincipals(PagePermission.EDIT), wup));
Assert.assertTrue("Bob comment", inGroup(m_aclGroup.findPrincipals(PagePermission.COMMENT), wup));
Assert.assertFalse("Bob delete", inGroup(m_aclGroup.findPrincipals(PagePermission.DELETE), wup));
wup = new WikiPrincipal("Charlie");
Assert.assertTrue("Charlie view", inGroup(m_aclGroup.findPrincipals(PagePermission.VIEW), wup));
Assert.assertFalse("Charlie edit", inGroup(m_aclGroup.findPrincipals(PagePermission.EDIT), wup));
Assert.assertFalse("Charlie comment", inGroup(m_aclGroup.findPrincipals(PagePermission.COMMENT), wup));
Assert.assertFalse("Charlie delete", inGroup(m_aclGroup.findPrincipals(PagePermission.DELETE), wup));
wup = new WikiPrincipal("Dave");
Assert.assertFalse("Dave view", inGroup(m_aclGroup.findPrincipals(PagePermission.VIEW), wup));
Assert.assertFalse("Dave edit", inGroup(m_aclGroup.findPrincipals(PagePermission.EDIT), wup));
Assert.assertFalse("Dave comment", inGroup(m_aclGroup.findPrincipals(PagePermission.COMMENT), wup));
Assert.assertFalse("Dave delete", inGroup(m_aclGroup.findPrincipals(PagePermission.DELETE), wup));
}
Aggregations