Search in sources :

Example 16 with NoSuchPrincipalException

use of org.apache.wiki.auth.NoSuchPrincipalException 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);
    }
}
Also used : WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) NoSuchPrincipalException(org.apache.wiki.auth.NoSuchPrincipalException)

Aggregations

NoSuchPrincipalException (org.apache.wiki.auth.NoSuchPrincipalException)16 WikiSecurityException (org.apache.wiki.auth.WikiSecurityException)9 IOException (java.io.IOException)5 Date (java.util.Date)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 NamingException (javax.naming.NamingException)4 NoRequiredPropertyException (org.apache.wiki.api.exceptions.NoRequiredPropertyException)4 UserManager (org.apache.wiki.auth.UserManager)4 WikiPrincipal (org.apache.wiki.auth.WikiPrincipal)4 UserDatabase (org.apache.wiki.auth.user.UserDatabase)4 UserProfile (org.apache.wiki.auth.user.UserProfile)3 Principal (java.security.Principal)2 ResultSet (java.sql.ResultSet)2 Timestamp (java.sql.Timestamp)2 GroupPrincipal (org.apache.wiki.auth.GroupPrincipal)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 DateFormat (java.text.DateFormat)1