/* * Copyright (C) 2005-2007 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * As a special exception to the terms and conditions of version 2.0 of * the GPL, you may redistribute this Program in connection with Free/Libre * and Open Source Software ("FLOSS") applications as described in Alfresco's * FLOSS exception. You should have recieved a copy of the text describing * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ package org.alfresco.repo.admin; import java.util.ArrayList; import java.util.List; import java.util.Set; import org.alfresco.repo.security.authentication.AuthenticationServiceImpl; import org.alfresco.repo.transaction.TransactionServiceImpl; import org.alfresco.service.license.LicenseService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; public class RepoServerMgmt implements RepoServerMgmtMBean, ApplicationContextAware { private static final Log log = LogFactory.getLog(RepoServerMgmt.class); private ApplicationContext ctx; // to get license component, if installed private TransactionServiceImpl transactionService; private AuthenticationServiceImpl authenticationService; public void setTransactionService(TransactionServiceImpl transactionService) { this.transactionService = transactionService; } public void setAuthenticationService(AuthenticationServiceImpl authenticationService) { this.authenticationService = authenticationService; } public void setApplicationContext(ApplicationContext ctx) { this.ctx = ctx; } /* * (non-Javadoc) * @see org.alfresco.repo.admin.RepoServerMgmtMBean#setReadOnly(boolean) */ public void setReadOnly(boolean readOnly) { if (readOnly && isReadOnly()) { log.info("Alfresco Repository is already READONLY"); return; } if (!readOnly && !isReadOnly()) { log.info("Alfresco Repository is already WRITABLE"); return; } if (!readOnly) { LicenseService licenseService = null; try { licenseService = (LicenseService)ctx.getBean("org.alfresco.license.LicenseComponent"); // verify license, but only if license component is installed licenseService.verifyLicense(); } catch (NoSuchBeanDefinitionException e) { // ignore } } transactionService.setAllowWrite(!readOnly); if (readOnly) { log.info("Alfresco Repository set to READONLY"); } else { log.info("Alfresco Repository set to WRITABLE"); } } /* * (non-Javadoc) * @see org.alfresco.mbeans.RepoServerMgmtMBean#isReadOnly(java.lang.Boolean) */ public boolean isReadOnly() { return transactionService.isReadOnly(); } // Note: implementing counts as managed attributes (without params) means that // certain JMX consoles can create graphs /* * (non-Javadoc) * @see org.alfresco.mbeans.RepoServerMgmtMBean#getTicketCountNonExpired() */ public int getTicketCountNonExpired() { return authenticationService.countTickets(true); } /* * (non-Javadoc) * @see org.alfresco.mbeans.RepoServerMgmtMBean#getTicketCountAll() */ public int getTicketCountAll() { return authenticationService.countTickets(false); } /* * (non-Javadoc) * @see org.alfresco.mbeans.RepoServerMgmtMBean#getUserCountNonExpired() */ public int getUserCountNonExpired() { return authenticationService.getUsersWithTickets(true).size(); } /* * (non-Javadoc) * @see org.alfresco.mbeans.RepoServerMgmtMBean#getUserCountAll() */ public int getUserCountAll() { return authenticationService.getUsersWithTickets(false).size(); } // Note: implement operations without boolean/Boolean parameter, due to problem with some JMX consoles (e.g. MC4J 1.9 Beta) /* * (non-Javadoc) * @see org.alfresco.repo.admin.RepoServerMgmtMBean#listUserNamesNonExpired() */ public String[] listUserNamesNonExpired() { Set userSet = authenticationService.getUsersWithTickets(true); return userSet.toArray(new String[0]); } /* * (non-Javadoc) * @see org.alfresco.repo.admin.RepoServerMgmtMBean#listUserNamesAll() */ public String[] listUserNamesAll() { Set userSet = authenticationService.getUsersWithTickets(false); return userSet.toArray(new String[0]); } /* * (non-Javadoc) * @see org.alfresco.mbeans.RepoServerMgmtMBean#invalidateTicketsExpired() */ public int invalidateTicketsExpired() { return authenticationService.invalidateTickets(true); } /* * (non-Javadoc) * @see org.alfresco.mbeans.RepoServerMgmtMBean#invalidateTicketsAll() */ public int invalidateTicketsAll() { return authenticationService.invalidateTickets(false); } /* * (non-Javadoc) * @see org.alfresco.mbeans.RepoServerMgmtMBean#allowSingleUserOnly(java.lang.String) */ public void allowSingleUserOnly(String allowedUsername) { List allowedUsers = null; if (allowedUsername != null) { allowedUsers = new ArrayList(0); allowedUsers.add(allowedUsername); invalidateTicketsAll(); } authenticationService.setAllowedUsers(allowedUsers); } }