use of org.apache.wiki.auth.WikiSecurityException in project jspwiki by apache.
the class GroupManager method getGroupDatabase.
/**
* Returns the current external {@link GroupDatabase} in use. This method
* is guaranteed to return a properly-initialized GroupDatabase, unless
* it could not be initialized. In that case, this method throws
* a {@link org.apache.wiki.api.exceptions.WikiException}. The GroupDatabase
* is lazily initialized.
* @throws org.apache.wiki.auth.WikiSecurityException if the GroupDatabase could
* not be initialized
* @return the current GroupDatabase
* @since 2.3
*/
public GroupDatabase getGroupDatabase() throws WikiSecurityException {
if (m_groupDatabase != null) {
return m_groupDatabase;
}
String dbClassName = "<unknown>";
String dbInstantiationError = null;
Throwable cause = null;
try {
Properties props = m_engine.getWikiProperties();
dbClassName = props.getProperty(PROP_GROUPDATABASE);
if (dbClassName == null) {
dbClassName = XMLGroupDatabase.class.getName();
}
log.info("Attempting to load group database class " + dbClassName);
Class<?> dbClass = ClassUtil.findClass("org.apache.wiki.auth.authorize", dbClassName);
m_groupDatabase = (GroupDatabase) dbClass.newInstance();
m_groupDatabase.initialize(m_engine, m_engine.getWikiProperties());
log.info("Group database initialized.");
} catch (ClassNotFoundException e) {
log.error("GroupDatabase class " + dbClassName + " cannot be found.", e);
dbInstantiationError = "Failed to locate GroupDatabase class " + dbClassName;
cause = e;
} catch (InstantiationException e) {
log.error("GroupDatabase class " + dbClassName + " cannot be created.", e);
dbInstantiationError = "Failed to create GroupDatabase class " + dbClassName;
cause = e;
} catch (IllegalAccessException e) {
log.error("You are not allowed to access group database class " + dbClassName + ".", e);
dbInstantiationError = "Access GroupDatabase class " + dbClassName + " denied";
cause = e;
} catch (NoRequiredPropertyException e) {
log.error("Missing property: " + e.getMessage() + ".");
dbInstantiationError = "Missing property: " + e.getMessage();
cause = e;
}
if (dbInstantiationError != null) {
throw new WikiSecurityException(dbInstantiationError + " Cause: " + (cause != null ? cause.getMessage() : ""), cause);
}
return m_groupDatabase;
}
use of org.apache.wiki.auth.WikiSecurityException in project jspwiki by apache.
the class JDBCGroupDatabase method delete.
/**
* Looks up and deletes a {@link Group} from the group database. If the
* group database does not contain the supplied Group. this method throws a
* {@link NoSuchPrincipalException}. The method commits the results of the
* delete to persistent storage.
*
* @param group the group to remove
* @throws WikiSecurityException if the database does not contain the
* supplied group (thrown as {@link NoSuchPrincipalException})
* or if the commit did not succeed
*/
public void delete(Group group) throws WikiSecurityException {
if (!exists(group)) {
throw new NoSuchPrincipalException("Not in database: " + group.getName());
}
String groupName = group.getName();
Connection conn = null;
PreparedStatement ps = null;
try {
// Open the database connection
conn = m_ds.getConnection();
if (m_supportsCommits) {
conn.setAutoCommit(false);
}
ps = conn.prepareStatement(m_deleteGroup);
ps.setString(1, groupName);
ps.execute();
ps.close();
ps = conn.prepareStatement(m_deleteGroupMembers);
ps.setString(1, groupName);
ps.execute();
// Commit and close connection
if (m_supportsCommits) {
conn.commit();
}
} catch (SQLException e) {
closeQuietly(conn, ps, null);
throw new WikiSecurityException("Could not delete group " + groupName + ": " + e.getMessage(), e);
} finally {
closeQuietly(conn, ps, null);
}
}
use of org.apache.wiki.auth.WikiSecurityException in project jspwiki by apache.
the class JDBCGroupDatabase method groups.
/**
* Returns all wiki groups that are stored in the GroupDatabase as an array
* of Group objects. If the database does not contain any groups, this
* method will return a zero-length array. This method causes back-end
* storage to load the entire set of group; thus, it should be called
* infrequently (e.g., at initialization time).
*
* @return the wiki groups
* @throws WikiSecurityException if the groups cannot be returned by the
* back-end
*/
public Group[] groups() throws WikiSecurityException {
Set<Group> groups = new HashSet<Group>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// Open the database connection
conn = m_ds.getConnection();
ps = conn.prepareStatement(m_findAll);
rs = ps.executeQuery();
while (rs.next()) {
String groupName = rs.getString(m_name);
if (groupName == null) {
log.warn("Detected null group name in JDBCGroupDataBase. Check your group database.");
} else {
Group group = new Group(groupName, m_engine.getApplicationName());
group.setCreated(rs.getTimestamp(m_created));
group.setCreator(rs.getString(m_creator));
group.setLastModified(rs.getTimestamp(m_modified));
group.setModifier(rs.getString(m_modifier));
populateGroup(group);
groups.add(group);
}
}
} catch (SQLException e) {
closeQuietly(conn, ps, rs);
throw new WikiSecurityException(e.getMessage(), e);
} finally {
closeQuietly(conn, ps, rs);
}
return groups.toArray(new Group[groups.size()]);
}
Aggregations