Ignore:
Timestamp:
2013-03-13T14:13:21+13:00 (11 years ago)
Author:
sjm84
Message:

Reformatting this file ahead of some changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java

    r26914 r27075  
    128128
    129129    protected static DerbyWrapper _derbyWrapper = null;
    130         protected static boolean _derbyWrapperDoneForcedShutdown = false;
     130    protected static boolean _derbyWrapperDoneForcedShutdown = false;
    131131
    132132    protected String _recaptchaPrivateKey = null;
     
    138138    }
    139139
    140         public void cleanUp() {
    141 
    142         super.cleanUp();
    143 
    144         if (!_derbyWrapperDoneForcedShutdown) {     
    145 
    146         // This boolean is used to ensure we always shutdown the derby server, even if it is never
    147         // used by the Authentication server.  This is because the Tomcat greenstone3.xml
    148         // config file also specifies a connection to the database, which can result in the
    149         // server being initialized when the servlet is first accessed.  Note also,
    150         // Authentication is a ServiceRack, meaning cleanUp() is called for each service
    151         // supported, however we only need to shutdown the Derby server once.  Again
    152         // this boolean variable helps achieve this.
    153 
    154         logger.info("Authentication Service performing forced shutdown of Derby Server ...");
    155        
    156         DerbyWrapper.shutdownDatabaseServer();
    157         _derbyWrapper = null;
    158         _derbyWrapperDoneForcedShutdown = true;
    159         }
     140    public void cleanUp()
     141    {
     142
     143        super.cleanUp();
     144
     145        if (!_derbyWrapperDoneForcedShutdown)
     146        {
     147
     148            // This boolean is used to ensure we always shutdown the derby server, even if it is never
     149            // used by the Authentication server.  This is because the Tomcat greenstone3.xml
     150            // config file also specifies a connection to the database, which can result in the
     151            // server being initialized when the servlet is first accessed.  Note also,
     152            // Authentication is a ServiceRack, meaning cleanUp() is called for each service
     153            // supported, however we only need to shutdown the Derby server once.  Again
     154            // this boolean variable helps achieve this.
     155
     156            logger.info("Authentication Service performing forced shutdown of Derby Server ...");
     157
     158            DerbyWrapper.shutdownDatabaseServer();
     159            _derbyWrapper = null;
     160            _derbyWrapperDoneForcedShutdown = true;
     161        }
    160162
    161163    }
     
    282284        try
    283285        {
    284                 UserQueryResult userQueryResult = _derbyWrapper.findUser(username);
    285            
     286            UserQueryResult userQueryResult = _derbyWrapper.findUser(username);
     287
    286288            Vector<UserTermInfo> terms = userQueryResult.getUserTerms();
    287289
     
    314316            ex.printStackTrace();
    315317        }
    316 
    317318
    318319        closeDatabase();
     
    828829    private void checkAdminUserExists()
    829830    {
    830             openDatabase();
     831        openDatabase();
    831832
    832833        UserQueryResult userQueryResult = _derbyWrapper.findUser(null, null);
     
    856857    private boolean openDatabase()
    857858    {
    858         if (_derbyWrapper == null) {
    859         _derbyWrapper = new DerbyWrapper();
    860 
    861         // check the usersDb database, if it isn't existing, check the etc dir, create the etc dir if it isn't existing, then create the  user database and add a "admin" user
    862         String usersDB_dir = this.site_home + File.separatorChar + "etc" + File.separatorChar + "usersDB";
    863         File usersDB_file = new File(usersDB_dir);
    864         if (!usersDB_file.exists())
    865         {
    866             String etc_dir = this.site_home + File.separatorChar + "etc";
    867             File etc_file = new File(etc_dir);
    868             if (!etc_file.exists())
    869             {
    870                 boolean success = etc_file.mkdir();
    871                 if (!success)
    872                 {
    873                     logger.error("Couldn't create the etc dir under " + this.site_home + ".");
    874                     return false;
    875                 }
    876             }
    877             _derbyWrapper.connectDatabase(usersDB_dir, true);
    878             _derbyWrapper.createDatabase();
    879         }
    880         else
    881         {
    882             _derbyWrapper.connectDatabase(usersDB_dir, false);
    883         }
    884         }
    885         return true;
     859        if (_derbyWrapper == null)
     860        {
     861            _derbyWrapper = new DerbyWrapper();
     862
     863            // check the usersDb database, if it isn't existing, check the etc dir, create the etc dir if it isn't existing, then create the  user database and add a "admin" user
     864            String usersDB_dir = this.site_home + File.separatorChar + "etc" + File.separatorChar + "usersDB";
     865            File usersDB_file = new File(usersDB_dir);
     866            if (!usersDB_file.exists())
     867            {
     868                String etc_dir = this.site_home + File.separatorChar + "etc";
     869                File etc_file = new File(etc_dir);
     870                if (!etc_file.exists())
     871                {
     872                    boolean success = etc_file.mkdir();
     873                    if (!success)
     874                    {
     875                        logger.error("Couldn't create the etc dir under " + this.site_home + ".");
     876                        return false;
     877                    }
     878                }
     879                _derbyWrapper.connectDatabase(usersDB_dir, true);
     880                _derbyWrapper.createDatabase();
     881            }
     882            else
     883            {
     884                _derbyWrapper.connectDatabase(usersDB_dir, false);
     885            }
     886        }
     887        return true;
    886888    }
    887889
     
    896898
    897899    private int addUserInformationToNode(String username, Element serviceNode)
    898     {       
    899             openDatabase();
     900    {
     901        openDatabase();
    900902
    901903        UserQueryResult userQueryResult = _derbyWrapper.findUser(username, null);
     
    926928        if (success)
    927929        {
    928             closeDatabase();
    929             return NO_ERROR;
     930            closeDatabase();
     931            return NO_ERROR;
    930932        }
    931933
     
    936938    private int addUser(String newUsername, String newPassword, String newGroups, String newStatus, String newComment, String newEmail)
    937939    {
    938             openDatabase();
     940        openDatabase();
    939941
    940942        newGroups = newGroups.replaceAll(" ", "");
     
    965967    private boolean checkUserExists(String username)
    966968    {
    967             boolean check_status = false;
     969        boolean check_status = false;
    968970
    969971        openDatabase();
     
    981983        catch (Exception ex)
    982984        {
    983             // some error occurred accessing the database
    984             ex.printStackTrace();
     985            // some error occurred accessing the database
     986            ex.printStackTrace();
    985987        }
    986988
     
    991993    private String retrieveDataForUser(String username, String dataType)
    992994    {
    993             openDatabase();
     995        openDatabase();
    994996
    995997        String data = null;
Note: See TracChangeset for help on using the changeset viewer.