mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V2.2 to HEAD
7260: Basic JMX sys admin - to manage session/tickets and server modes such as read-only and single-user git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8242 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
216
source/java/org/alfresco/repo/admin/RepoServerMgmt.java
Normal file
216
source/java/org/alfresco/repo/admin/RepoServerMgmt.java
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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<String> userSet = authenticationService.getUsersWithTickets(true);
|
||||
return userSet.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.admin.RepoServerMgmtMBean#listUserNamesAll()
|
||||
*/
|
||||
public String[] listUserNamesAll()
|
||||
{
|
||||
Set<String> 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<String> allowedUsers = null;
|
||||
if (allowedUsername != null)
|
||||
{
|
||||
allowedUsers = new ArrayList<String>(0);
|
||||
allowedUsers.add(allowedUsername);
|
||||
|
||||
invalidateTicketsAll();
|
||||
}
|
||||
|
||||
authenticationService.setAllowedUsers(allowedUsers);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user