diff --git a/SpagoBIDAO/src/it/eng/spagobi/commons/utilities/UserUtilities.java b/SpagoBIDAO/src/it/eng/spagobi/commons/utilities/UserUtilities.java index b02ca2c2e..f6fb4d63e 100644 --- a/SpagoBIDAO/src/it/eng/spagobi/commons/utilities/UserUtilities.java +++ b/SpagoBIDAO/src/it/eng/spagobi/commons/utilities/UserUtilities.java @@ -19,6 +19,7 @@ import it.eng.spagobi.commons.dao.DAOFactory; import it.eng.spagobi.commons.dao.IRoleDAO; import it.eng.spagobi.commons.metadata.SbiTenant; +import it.eng.spagobi.dao.exception.DAORuntimeException; import it.eng.spagobi.services.common.SsoServiceFactory; import it.eng.spagobi.services.common.SsoServiceInterface; import it.eng.spagobi.services.security.bo.SpagoBIUserProfile; @@ -675,29 +676,38 @@ private static void checkTenant(SpagoBIUserProfile profile) { /* * Method copied from SecurityServiceSupplierFactory for DAO refactoring + * + * is this method in the right place? */ public static ISecurityServiceSupplier createISecurityServiceSupplier(){ logger.debug("IN"); - SingletonConfig configSingleton = SingletonConfig.getInstance(); - String engUserProfileFactorySB = configSingleton.getConfigValue("SPAGOBI.SECURITY.USER-PROFILE-FACTORY-CLASS.className"); - if (engUserProfileFactorySB==null){ - logger.warn("SPAGOBI.SECURITY.USER-PROFILE-FACTORY-CLASS ... NOT FOUND"); - } - String engUserProfileFactoryClass = engUserProfileFactorySB; - engUserProfileFactoryClass = engUserProfileFactoryClass.trim(); + + ISecurityServiceSupplier securityServiceSupplier = null; + String engUserProfileFactoryClass = null; + try { - return (ISecurityServiceSupplier)Class.forName(engUserProfileFactoryClass).newInstance(); - } catch (InstantiationException e) { - logger.warn("InstantiationException",e); - } catch (IllegalAccessException e) { - logger.warn("IllegalAccessException",e); - } catch (ClassNotFoundException e) { - logger.warn("ClassNotFoundException",e); - }finally{ - logger.debug("OUT"); + SingletonConfig configSingleton = SingletonConfig.getInstance(); + engUserProfileFactoryClass = configSingleton.getConfigValue("SPAGOBI.SECURITY.USER-PROFILE-FACTORY-CLASS.className"); + if (engUserProfileFactoryClass != null) { + engUserProfileFactoryClass = engUserProfileFactoryClass.trim(); + try { + securityServiceSupplier = (ISecurityServiceSupplier)Class.forName(engUserProfileFactoryClass).newInstance(); + } catch (Throwable t) { + throw new DAORuntimeException("Impossible to instatiate supplier class [" + engUserProfileFactoryClass+ "]", t); + } + } else{ + throw new DAORuntimeException("Impossible read from configuartion the property [SPAGOBI.SECURITY.USER-PROFILE-FACTORY-CLASS] that contains the name of the class used as securityServiceSupplier"); + } + } catch(Throwable t) { + if(t instanceof DAORuntimeException) throw (DAORuntimeException)t; + else throw new DAORuntimeException("Impossible to instatiate supplier class [" + engUserProfileFactoryClass+ "]", t); } - return null; + + + + + return securityServiceSupplier; } } diff --git a/SpagoBIDAO/src/it/eng/spagobi/dao/exception/DAORuntimeException.java b/SpagoBIDAO/src/it/eng/spagobi/dao/exception/DAORuntimeException.java new file mode 100644 index 000000000..ed620de52 --- /dev/null +++ b/SpagoBIDAO/src/it/eng/spagobi/dao/exception/DAORuntimeException.java @@ -0,0 +1,84 @@ +/* SpagoBI, the Open Source Business Intelligence suite + + * Copyright (C) 2012 Engineering Ingegneria Informatica S.p.A. - SpagoBI Competency Center + * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0, without the "Incompatible With Secondary Licenses" notice. + * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package it.eng.spagobi.dao.exception; + +import java.io.PrintWriter; +import java.io.StringWriter; + +public class DAORuntimeException extends RuntimeException { + + /** + * Keep compiler happy + */ + private static final long serialVersionUID = 1L; + + /* + * User oriented description of the exception. It is usually prompted to the user. + * Instead the message passed to the constructor is developer oriented and it should be just logged. + */ + private String description; + + + /** + * Builds a SpagoBIRuntimeException. + * + * @param message Text of the exception + */ + public DAORuntimeException(String message) { + super(message); + } + + /** + * Builds a SpagoBIRuntimeException. + * + * @param message Text of the exception + * @param ex previous Throwable object + */ + public DAORuntimeException(String message, Throwable ex) { + super(message, ex); + } + + /** + * Builds a SpagoBIRuntimeException. + * + * @param ex previous Throwable object + */ + public DAORuntimeException(Throwable ex) { + super(ex); + } + + public String getRootCause() { + String rootCause; + Throwable rootException; + + rootException = this; + while(rootException.getCause() != null) { + rootException = rootException.getCause(); + } + + rootCause = rootException.getMessage()!=null + ? rootException.getClass().getName() + ": " + rootException.getMessage() + : rootException.getClass().getName(); + + return rootCause; + } + + public String getStackTraceDump() { + StringWriter buffer = new StringWriter(); + this.printStackTrace(new PrintWriter(buffer)); + return buffer.toString(); + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} +