Package com.ecyrd.jspwiki.auth.user

Examples of com.ecyrd.jspwiki.auth.user.UserDatabase


     * Verifies that the user datbase was initialized properly, and that
     * user add and delete operations work as they should.
     */
    protected final void verifyUserDatabase()
    {
        UserDatabase db = m_engine.getUserManager().getUserDatabase();

        // Check for obvious error conditions
        if ( db == null )
        {
            m_session.addMessage( ERROR_DB, "UserDatabase is null; JSPWiki could not " +
                    "initialize it. Check the error logs." );
            return;
        }

        if ( db instanceof UserManager.DummyUserDatabase )
        {
            m_session.addMessage( ERROR_DB, "UserDatabase is DummyUserDatabase; JSPWiki " +
                    "may not have been able to initialize the database you supplied in " +
                    "jspwiki.properties, or you left the 'jspwiki.userdatabase' property " +
                    "blank. Check the error logs." );
        }

        // Tell user what class of database this is.
        m_session.addMessage( INFO_DB, "UserDatabase is of type '" + db.getClass().getName() +
                "'. It appears to be initialized properly." );

        // Now, see how many users we have.
        int oldUserCount = 0;
        try
        {
            Principal[] users = db.getWikiNames();
            oldUserCount = users.length;
            m_session.addMessage( INFO_DB, "The user database contains " + oldUserCount + " users." );
        }
        catch ( WikiSecurityException e )
        {
            m_session.addMessage( ERROR_DB, "Could not obtain a list of current users: " + e.getMessage() );
            return;
        }

        // Try adding a bogus user with random name
        String loginName = "TestUser" + String.valueOf( System.currentTimeMillis() );
        try
        {
            UserProfile profile = db.newProfile();
            profile.setEmail( "testuser@testville.com" );
            profile.setLoginName( loginName );
            profile.setFullname( "FullName"+loginName );
            profile.setPassword( "password" );
            db.save(profile);

            // Make sure the profile saved successfully
            if ( db.getWikiNames().length == oldUserCount )
            {
                m_session.addMessage( ERROR_DB, "Could not add a test user to the database." );
                return;
            }
            m_session.addMessage( INFO_DB, "The user database allows new users to be created, as it should." );
        }
        catch ( WikiSecurityException e )
        {
            m_session.addMessage( ERROR_DB, "Could not add a test user to the database: " + e.getMessage() );
            return;
        }

        // Now delete the profile; should be back to old count
        try
        {
            db.deleteByLoginName( loginName );
            if ( db.getWikiNames().length != oldUserCount )
            {
                m_session.addMessage( ERROR_DB, "Could not delete a test user from the database." );
                return;
            }
            m_session.addMessage( INFO_DB, "The user database allows users to be deleted, as it should." );
View Full Code Here


            log.info("Refresh principals failed because WikiSession had no user Principal; maybe not logged in?");
            return;
        }

        // Look up the user and go get the new Principals
        UserDatabase database = m_engine.getUserManager().getUserDatabase();
        if ( database == null )
        {
            throw new IllegalStateException( "User database cannot be null." );
        }
        try
        {
            UserProfile profile = database.find( searchId );
            Principal[] principals = database.getPrincipals( profile.getLoginName() );
            for ( Principal principal : principals )
            {
                // Add the Principal to the Subject
                m_subject.getPrincipals().add( principal );
               
View Full Code Here

        }

        // Ok, no luck---this must be a user principal
        Principal[] principals = null;
        UserProfile profile = null;
        UserDatabase db = m_engine.getUserManager().getUserDatabase();
        try
        {
            profile = db.find( name );
            principals = db.getPrincipals( profile.getLoginName() );
            for (int i = 0; i < principals.length; i++)
            {
                principal = principals[i];
                if ( principal.getName().equals( name ) )
                {
View Full Code Here

        Callback[] callbacks = new Callback[]
        { ucb, ncb, pcb };
        try
        {
            m_handler.handle( callbacks );
            UserDatabase db = ucb.getUserDatabase();
            String username = ncb.getName();
            String password = new String( pcb.getPassword() );

            // Look up the user and compare the password hash
            if ( db == null )
            {
                throw new FailedLoginException( "No user database: check the callback handler code!" );
            }
            UserProfile profile = db.findByLoginName( username );
            String storedPassword = profile.getPassword();
            if ( storedPassword != null && db.validatePassword( username, password ) )
            {
                if ( log.isDebugEnabled() )
                {
                    log.debug( "Logged in user database user " + username );
                }
View Full Code Here

            // See if admin users exists
            boolean adminExists = false;
            try
            {
                UserManager userMgr = m_engine.getUserManager();
                UserDatabase userDb = userMgr.getUserDatabase();
                userDb.findByLoginName( Installer.ADMIN_ID );
                adminExists = true;
            }
            catch ( NoSuchPrincipalException e )
            {
                return DUMMY_PERMISSION;
View Full Code Here

     */
    public boolean adminExists()
    {
        // See if the admin user exists already
        UserManager userMgr = m_engine.getUserManager();
        UserDatabase userDb = userMgr.getUserDatabase();
       
        try
        {
            userDb.findByLoginName( ADMIN_ID );
            return true;
        }
        catch ( NoSuchPrincipalException e )
        {
            return false;
View Full Code Here

            return null;
        }
       
        // See if the admin user exists already
        UserManager userMgr = m_engine.getUserManager();
        UserDatabase userDb = userMgr.getUserDatabase();
        String password = null;
       
        try
        {
            userDb.findByLoginName( ADMIN_ID );
        }
        catch ( NoSuchPrincipalException e )
        {
            // Create a random 12-character password
            password = TextUtil.generateRandomPassword();
            UserProfile profile = userDb.newProfile();
            profile.setLoginName( ADMIN_ID );
            profile.setFullname( ADMIN_NAME );
            profile.setPassword( password );
            userDb.save( profile );
        }
       
        // Create a new admin group
        GroupManager groupMgr = m_engine.getGroupManager();
        Group group = null;
View Full Code Here

TOP

Related Classes of com.ecyrd.jspwiki.auth.user.UserDatabase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.