📄 standardservice.java
字号:
/*
* OPIAM Suite
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package opiam.admin.faare.service.services;
import opiam.admin.faare.MessageUtil;
import opiam.admin.faare.PropertiesManager;
import opiam.admin.faare.SearchResult;
import opiam.admin.faare.config.javabeans.JBLdapConfig;
import opiam.admin.faare.config.javabeans.JBProfile;
import opiam.admin.faare.config.javabeans.JBProfiles;
import opiam.admin.faare.config.javabeans.JBRessource;
import opiam.admin.faare.exception.AuthenticationFailureException;
import opiam.admin.faare.exception.InsufficientAccessRights;
import opiam.admin.faare.exception.PersistenceException;
import opiam.admin.faare.exception.ServiceException;
import opiam.admin.faare.persistence.LdapUtil;
import opiam.admin.faare.persistence.PersistenceLDAP;
import opiam.admin.faare.persistence.javabeans.JBTop;
import opiam.admin.faare.persistence.javabeans.JBUser;
import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.services.acl.AclsService;
import opiam.admin.faare.service.services.triggers.TriggersService;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
/**
* Basic service that contains the search functionalities,
* loading, modification, deletion and creation of business objects.
*
* This service can not be disabled, it is loaded by default.
*
*/
public final class StandardService extends Service
{
/** Utility class. */
private StandardService()
{
}
/** Instance of logger. */
private static Logger _logger = Logger.getLogger(StandardService.class);
/** Instance of the service. */
private static StandardService _instance = new StandardService();
/** Name of the service. */
private static final String SERVICE_NAME = "StandardService";
/**
* Initialization method of the service.
*
* @see Service.initialize().
*
* @throws ServiceException
*/
public static void initialize(String directory) throws ServiceException
{
//DW/2655/BeginPatch
//StandardService.setServiceEnabled(true);
_instance.setServiceEnabled(true);
//DW/2655/EndPatch
_logger.info(StandardService.class + " initialized");
}
//DW/2655/BeginPatch
/**
* This method indicates if the service is active or not.
*
* @return True if it is active, false otherwise.
*/
public static boolean isServiceEnabled()
{
return _instance.serviceEnabled;
}
//DW/2655/EndPatch
/**
* Loading method of a business object from its DN.
*
* @param dn DN of the entry to load.
* @param userContext Context of the user.
*
* @return The business object.
*
* @throws ServiceException if an error occurs, or one of the arguments is null.
*/
public static JBTop load(String dn, UserContext userContext)
throws ServiceException
{
if (dn == null)
{
throw new ServiceException(MessageUtil.formatMessage("MSG_ARGUMENT_NULL"));
}
if (userContext == null)
{
throw new ServiceException(MessageUtil.formatMessage("MSG_ARGUMENT_NULL"));
}
// DW/2639/BeginPatch
if (!userContext.isLoggedIn())
{
throw new ServiceException(MessageUtil.formatMessage("MSG_USERCONTEXT_INCORRECT"));
}
// DW/2639/EndPatch
JBTop jbTop = null;
try
{
// pas de PRE-OP trigger, puisqu'on n'a pas d'objet encore
jbTop = PersistenceLDAP.load(dn, userContext);
// check whether the user has the rights to visualize
if (!AclsService.isVisualisationEnabled(jbTop, userContext))
{
// have no rights to do this
throw new InsufficientAccessRights(MessageUtil.formatMessage("MSG_INSUFFICIENT_ACCESS_RIGHTS",
SERVICE_NAME
)
);
}
// trigger post-op
TriggersService.launchPostOp(TriggersService.TYPE_LOAD, jbTop,
userContext
);
}
catch (PersistenceException pe)
{
_logger.error(pe.getMessage());
if (_logger.isDebugEnabled())
{
_logger.debug("Trace", pe);
}
throw new ServiceException(pe.getMessage(), pe);
}
return jbTop;
}
/**
* Modification method of the <i>jbTop</i> business object.
*
* @param jbTop Business object to modify.
* @param userContext Context of the user.
*
* @throws ServiceException - if an error occurs,
* or the connected user has insufficient access rights.
*/
public static void modify(JBTop jbTop, UserContext userContext)
throws ServiceException
{
try
{
if (!AclsService.isModificationEnabled(jbTop, userContext))
{
_logger.error("modify not done, pb with ACL");
// have no rights to do this
throw new InsufficientAccessRights(MessageUtil.formatMessage("MSG_INSUFFICIENT_ACCESS_RIGHTS",
SERVICE_NAME
)
);
}
//TODO impl閙enter cette m閔ode dans PersistenceLDAP
TriggersService.launchPreOp(TriggersService.TYPE_MODIFY, jbTop,
userContext
);
PersistenceLDAP.modify(jbTop, userContext);
TriggersService.launchPostOp(TriggersService.TYPE_MODIFY, jbTop,
userContext
);
}
catch (PersistenceException pe)
{
_logger.error(pe.getMessage());
_logger.debug("Trace", pe);
throw new ServiceException(pe.getMessage(), pe);
}
}
/**
* Modification method of the LDAP attribute value of the <i>jbTop</i> business object.
*
* @param jbTop Business object to modify.
* @param attribute LDAP attribute to modify.
* @param userContext Context of the user.
*
* @throws ServiceException - if an error occurs,
* or the connected user has insufficient access rights.
*/
public static void modify(JBTop jbTop, String attribute,
UserContext userContext
) throws ServiceException
{
try
{
if (!AclsService.isModificationEnabled(jbTop, userContext))
{
// have no rights to do this
throw new InsufficientAccessRights(MessageUtil.formatMessage("MSG_INSUFFICIENT_ACCESS_RIGHTS",
SERVICE_NAME
)
);
}
_logger.debug("modify attribute : " + attribute);
TriggersService.launchPreOp(TriggersService.TYPE_MODIFY, jbTop,
userContext
);
List jbTopList = new ArrayList();
jbTopList.add(jbTop);
PersistenceLDAP.modify(jbTopList, attribute, userContext);
TriggersService.launchPostOp(TriggersService.TYPE_MODIFY, jbTop,
userContext
);
_logger.debug("modify END OK ");
}
catch (PersistenceException pe)
{
_logger.error(pe.getMessage());
_logger.debug("Trace", pe);
throw new ServiceException(pe.getMessage(), pe);
}
}
/**
* Modification method of hidden LDAP attribute.
*
* @param jbTop Business object to modify.
* @param value New value of the LDAP attribute.
* @param attribute Name of the LDAP attribute.
* @param userContext Context of the user.
*
* @throws ServiceException - if an error occurs,
* or the connected user has insufficient access rights.
*/
public static void modifyLDAPHiddenAttribute(JBTop jbTop, String value,
String attribute,
UserContext userContext
) throws ServiceException
{
try
{
if (!AclsService.isModificationEnabled(jbTop, userContext))
{
// have no rights to do this
throw new InsufficientAccessRights(MessageUtil.formatMessage("MSG_INSUFFICIENT_ACCESS_RIGHTS",
SERVICE_NAME
)
);
}
_logger.debug("modifyLDAPHiddenAttribute attribute : " + attribute);
PersistenceLDAP.modifyLDAPHiddenAttribute(jbTop.getDn(), value,
attribute, userContext
);
_logger.debug("modifyLDAPHiddenAttribute FIN OK ");
}
catch (PersistenceException pe)
{
_logger.error(pe.getMessage());
_logger.debug("Trace", pe);
throw new ServiceException(pe.getMessage(), pe);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -