@Service
public class NewRelicWrapper {

  private static final Log log = LogFactoryUtil.getLog(NewRelicWrapper.class);

  public NewRelicWrapper() {
    log.debug("NewRelicWrapper");
  }

  public String getBrowserTimingHeader() {
    log.debug("getBrowserTimingHeader");

    String newRelicSnippet = NewRelic.getBrowserTimingHeader();
    log.debug("newRelicSnippet: " + newRelicSnippet);

    return newRelicSnippet;
  }

  public String getBrowserTimingFooter() {
    log.debug("getBrowserTimingFooter");

    String newRelicSnippet = NewRelic.getBrowserTimingFooter();
    log.debug("newRelicSnippet: " + newRelicSnippet);

    return newRelicSnippet;
  }
}
Exemplo n.º 2
0
public class EprintOpenSearchImpl extends HitsOpenSearchImpl {
  private static final Log log = LogFactoryUtil.getLog(EprintOpenSearchImpl.class);

  protected String getURL(
      ThemeDisplay themeDisplay, long groupId, Document result, PortletURL portletURL)
      throws Exception {

    portletURL.setParameter("jspPage", "/html/eprintview/detail.jsp");
    long eprintId = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK));
    portletURL.setParameter("eprintId", String.valueOf(eprintId));
    return super.getURL(themeDisplay, groupId, result, portletURL);
  }

  @Override
  public String getPortletId() {

    return "EprintAdmin_WAR_EprintAdmin";
  }

  @Override
  public String getSearchPath() {
    return "/c/library/open_search";
  }

  @Override
  public String getTitle(String keywords) {
    return "Eprint Open Search for " + keywords;
  }
}
/** @author Brian Wing Shun Chan */
public class GarbageCollectorAction extends SessionAction {

  public void run(HttpSession session) {
    Runtime runtime = Runtime.getRuntime();

    NumberFormat nf = NumberFormat.getInstance();

    if (_log.isDebugEnabled()) {
      _log.debug(
          "Before:\t\t"
              + nf.format(runtime.freeMemory())
              + "\t"
              + nf.format(runtime.totalMemory())
              + "\t"
              + nf.format(runtime.maxMemory()));
    }

    System.gc();

    if (_log.isDebugEnabled()) {
      _log.debug(
          "After:\t\t"
              + nf.format(runtime.freeMemory())
              + "\t"
              + nf.format(runtime.totalMemory())
              + "\t"
              + nf.format(runtime.maxMemory()));
    }
  }

  private static Log _log = LogFactoryUtil.getLog(GarbageCollectorAction.class);
}
/** @author Charles May */
public class UserGroupGroupChecker extends RowChecker {

  public UserGroupGroupChecker(RenderResponse renderResponse, Group group) {
    super(renderResponse);

    _group = group;
  }

  @Override
  public boolean isChecked(Object obj) {
    UserGroup userGroup = (UserGroup) obj;

    try {
      return UserGroupLocalServiceUtil.hasGroupUserGroup(
          _group.getGroupId(), userGroup.getUserGroupId());
    } catch (Exception e) {
      _log.error(e, e);

      return false;
    }
  }

  private static Log _log = LogFactoryUtil.getLog(UserGroupGroupChecker.class);

  private Group _group;
}
/** @author Brian Wing Shun Chan */
public class PermissionCheckerUtil {

  public static void setThreadValues(User user) {
    if (user == null) {
      PrincipalThreadLocal.setName(null);
      PermissionThreadLocal.setPermissionChecker(null);

      return;
    }

    long userId = user.getUserId();

    String name = String.valueOf(userId);

    PrincipalThreadLocal.setName(name);

    try {
      PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

      if (permissionChecker == null) {
        permissionChecker =
            (PermissionChecker) Class.forName(PropsValues.PERMISSIONS_CHECKER).newInstance();
      }

      permissionChecker.init(user);

      PermissionThreadLocal.setPermissionChecker(permissionChecker);
    } catch (Exception e) {
      _log.error(e, e);
    }
  }

  private static Log _log = LogFactoryUtil.getLog(PermissionCheckerUtil.class);
}
/** @author Brian Wing Shun Chan */
public class GroupRoleChecker extends RowChecker {

  public GroupRoleChecker(RenderResponse renderResponse, Role role) {
    super(renderResponse);

    _role = role;
  }

  @Override
  public boolean isChecked(Object obj) {
    Group group = (Group) obj;

    try {
      return GroupLocalServiceUtil.hasRoleGroup(_role.getRoleId(), group.getGroupId());
    } catch (Exception e) {
      _log.error(e, e);

      return false;
    }
  }

  private static Log _log = LogFactoryUtil.getLog(GroupRoleChecker.class);

  private Role _role;
}
/** @author Philip Jones */
@Component(
    immediate = true,
    property = {"portal.settings.authentication.tabs.name=opensso"},
    service = DynamicInclude.class)
public class PortalSettingsOpenSSOAuthenticationDynamicInclude extends BaseJSPDynamicInclude {

  @Override
  protected String getJspPath() {
    return "/com.liferay.portal.settings.web/opensso.jsp";
  }

  @Override
  protected Log getLog() {
    return _log;
  }

  @Reference(
      target = "(osgi.web.symbolicname=com.liferay.portal.security.sso.opensso)",
      unbind = "-")
  protected void setServletContext(ServletContext servletContext) {
    super.setServletContext(servletContext);
  }

  private static final Log _log =
      LogFactoryUtil.getLog(PortalSettingsOpenSSOAuthenticationDynamicInclude.class);
}
/** @author Shuyang Zhou */
public class LoggingProcessCallable implements ProcessCallable<String> {

  public LoggingProcessCallable(byte[] bytes) {
    this(bytes, false);
  }

  public LoggingProcessCallable(byte[] bytes, boolean error) {
    _bytes = bytes;
    _error = error;
  }

  @Override
  public String call() {
    try {
      if (_error) {
        System.err.write(_bytes);
      } else {
        System.out.write(_bytes);
      }
    } catch (IOException ioe) {
      _log.error("Unable to output log message: " + new String(_bytes), ioe);
    }

    return StringPool.BLANK;
  }

  private static final long serialVersionUID = 1L;

  private static Log _log = LogFactoryUtil.getLog(LoggingProcessCallable.class);

  private final byte[] _bytes;
  private final boolean _error;
}
public class PasswordUpdater extends SimpleAction {

  @Override
  public void run(String[] arg0) throws ActionException {
    Properties props = new Properties();
    try {
      props.load(
          this.getClass().getClassLoader().getResourceAsStream("password.changer.properties"));
      String type = props.getProperty("type");
      String virtualHost = props.getProperty("virtualhost");
      Company c = CompanyUtil.fetchByVirtualHost(virtualHost);
      User u = null;
      String name = null;
      if ("screenname".equals(type)) {
        String screenName = props.getProperty("screenname");
        u = UserLocalServiceUtil.getUserByScreenName(c.getCompanyId(), screenName);
        name = screenName;
      } else if ("e-mail".equals(type)) {
        String emailAddress = props.getProperty("emailaddress");
        u = UserLocalServiceUtil.getUserByEmailAddress(c.getCompanyId(), emailAddress);
        name = emailAddress;
      } else {
        _log.error(
            "You should set type to screenname or e-mail if you want to use the password updater.");
      }
      String password = props.getProperty("password");
      UserLocalServiceUtil.updatePasswordManually(u.getUserId(), password, false, true, new Date());
      _log.info("Password for " + name + " was updated.");
    } catch (Exception e) {
      _log.error(e);
    }
  }

  private static Log _log = LogFactoryUtil.getLog(PasswordUpdater.class);
}
/** @author Pei-Jung Lan */
@Component(
    property = {
      "javax.portlet.name=" + LoginPortletKeys.FAST_LOGIN,
      "javax.portlet.name=" + LoginPortletKeys.LOGIN,
      "mvc.command.name=/login/captcha"
    },
    service = MVCResourceCommand.class)
public class CaptchaMVCResourceCommand implements MVCResourceCommand {

  @Override
  public boolean serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) {

    try {
      CaptchaUtil.serveImage(resourceRequest, resourceResponse);

      return false;
    } catch (Exception e) {
      _log.error(e, e);

      return true;
    }
  }

  private static final Log _log = LogFactoryUtil.getLog(CaptchaMVCResourceCommand.class);
}
/** @author Renato Rego */
public class SelectDDMFormFieldValueAccessor extends DDMFormFieldValueAccessor<JSONArray> {

  public SelectDDMFormFieldValueAccessor(Locale locale) {
    super(locale);
  }

  @Override
  public JSONArray get(DDMFormFieldValue ddmFormFieldValue) {
    try {
      Value value = ddmFormFieldValue.getValue();

      return JSONFactoryUtil.createJSONArray(value.getString(locale));
    } catch (JSONException jsone) {
      _log.error("Unable to parse JSON array", jsone);

      return _EMPTY_JSON_ARRAY;
    }
  }

  @Override
  public Class<JSONArray> getAttributeClass() {
    return JSONArray.class;
  }

  private static final JSONArray _EMPTY_JSON_ARRAY = JSONFactoryUtil.createJSONArray();

  private static final Log _log = LogFactoryUtil.getLog(SelectDDMFormFieldValueAccessor.class);
}
Exemplo n.º 12
0
/** @author Brian Wing Shun Chan */
public class RegExpToolkit extends BasicToolkit {

  public RegExpToolkit() {
    _pattern = PropsUtil.get(PropsKeys.PASSWORDS_REGEXPTOOLKIT_PATTERN);
    _charset = PropsUtil.get(PropsKeys.PASSWORDS_REGEXPTOOLKIT_CHARSET);
    _length = GetterUtil.getInteger(PropsUtil.get(PropsKeys.PASSWORDS_REGEXPTOOLKIT_LENGTH));
  }

  @Override
  public String generate(PasswordPolicy passwordPolicy) {
    return PwdGenerator.getSecurePassword(_charset, _length);
  }

  @Override
  public void validate(
      long userId, String password1, String password2, PasswordPolicy passwordPolicy)
      throws PortalException {

    boolean value = password1.matches(_pattern);

    if (!value) {
      if (_log.isWarnEnabled()) {
        _log.warn("User " + userId + " attempted an invalid password");
      }

      throw new UserPasswordException(UserPasswordException.PASSWORD_INVALID);
    }
  }

  private static Log _log = LogFactoryUtil.getLog(RegExpToolkit.class);

  private String _charset;
  private int _length;
  private String _pattern;
}
Exemplo n.º 13
0
/** @author Jorge Ferrer */
public class UserGroupRoleUserChecker extends RowChecker {

  public UserGroupRoleUserChecker(RenderResponse renderResponse, Group group, Role role) {

    super(renderResponse);

    _group = group;
    _role = role;
  }

  @Override
  public boolean isChecked(Object obj) {
    User user = (User) obj;

    try {
      return UserGroupRoleLocalServiceUtil.hasUserGroupRole(
          user.getUserId(), _group.getGroupId(), _role.getRoleId());
    } catch (Exception e) {
      _log.error(e, e);

      return false;
    }
  }

  private static Log _log = LogFactoryUtil.getLog(UserGroupRoleUserChecker.class);

  private Group _group;
  private Role _role;
}
/**
 * A separate instance of this class is created every time <code>
 * renderRequest.getAttribute(PortletRequest.USER_INFO)</code> is called. It is safe to cache
 * attributes in this instance because you can assume that all calls to this instance belong to the
 * same user.
 *
 * @author Brian Wing Shun Chan
 */
public class DefaultCustomUserAttributes implements CustomUserAttributes {

  @Override
  public Object clone() {
    return new DefaultCustomUserAttributes();
  }

  public String getValue(String name, Map<String, String> userInfo) {
    if (name == null) {
      return null;
    }

    if (_log.isDebugEnabled()) {
      String companyId = userInfo.get(UserAttributes.LIFERAY_COMPANY_ID);
      String userId = userInfo.get(UserAttributes.LIFERAY_USER_ID);

      _log.debug("Company id " + companyId);
      _log.debug("User id " + userId);
    }

    if (name.equals("user.name.random")) {
      String[] names = new String[] {"Aaa", "Bbb", "Ccc"};

      return names[Randomizer.getInstance().nextInt(3)];
    } else {
      return null;
    }
  }

  private static Log _log = LogFactoryUtil.getLog(DefaultCustomUserAttributes.class);
}
/** @author Brian Wing Shun Chan */
public class ArrayApplicationContext extends ClassPathXmlApplicationContext {

  public ArrayApplicationContext(String[] configLocations) {
    super(configLocations);
  }

  @Override
  protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) {
    String[] configLocations = getConfigLocations();

    if (configLocations == null) {
      return;
    }

    for (String configLocation : configLocations) {
      try {
        reader.loadBeanDefinitions(configLocation);
      } catch (Exception e) {
        Throwable cause = e.getCause();

        if (cause instanceof FileNotFoundException) {
          if (_log.isWarnEnabled()) {
            _log.warn(cause.getMessage());
          }
        } else {
          _log.error(e, e);
        }
      }
    }
  }

  private static Log _log = LogFactoryUtil.getLog(ArrayApplicationContext.class);
}
/** @author Brian Wing Shun Chan */
public class OrganizationRoleChecker extends EmptyOnClickRowChecker {

  public OrganizationRoleChecker(RenderResponse renderResponse, Role role) {
    super(renderResponse);

    _role = role;
  }

  @Override
  public boolean isChecked(Object obj) {
    Organization organization = (Organization) obj;

    try {
      Group group = organization.getGroup();

      return GroupLocalServiceUtil.hasRoleGroup(_role.getRoleId(), group.getGroupId());
    } catch (Exception e) {
      _log.error(e, e);

      return false;
    }
  }

  private static final Log _log = LogFactoryUtil.getLog(OrganizationRoleChecker.class);

  private final Role _role;
}
Exemplo n.º 17
0
public class FacesPortlet extends com.sun.faces.portlet.FacesPortlet {

  private static final Log logger = LogFactoryUtil.getLog(FacesPortlet.class);

  public FacesPortlet() {
    super();
    // logger.info("init");
  }

  @Override
  public void processAction(ActionRequest request, ActionResponse response)
      throws IOException, PortletException {

    ActionRequest myRequest = request;

    if (FileUploadUtil.isMultipart(request)) {
      // logger.info("multipart!");
      try {
        myRequest = new FileUploadActionRequestWrapper(request);
      } catch (FileUploadException e) {
        logger.error(e.getMessage());
      }
    }

    super.processAction(myRequest, response);
  }
}
/** @author Tina Tian */
@Component(immediate = true, service = PortalCacheBootstrapLoaderFactory.class)
public class EhcachePortalCacheBootstrapLoaderFactory implements PortalCacheBootstrapLoaderFactory {

  @Override
  public PortalCacheBootstrapLoader create(Properties properties) {
    String className =
        properties.getProperty(EhcacheConstants.BOOTSTRAP_CACHE_LOADER_FACTORY_CLASS_NAME);

    if (Validator.isNull(className)) {
      return null;
    }

    try {
      BootstrapCacheLoaderFactory<?> bootstrapCacheLoaderFactory =
          (BootstrapCacheLoaderFactory<?>) InstanceFactory.newInstance(getClassLoader(), className);

      return new EhcachePortalCacheBootstrapLoaderAdapter(
          bootstrapCacheLoaderFactory.createBootstrapCacheLoader(properties));
    } catch (Exception e) {
      throw new SystemException(
          "Unable to instantiate bootstrap cache loader factory " + className, e);
    }
  }

  protected ClassLoader getClassLoader() {
    Class<?> clazz = getClass();

    return clazz.getClassLoader();
  }

  private static final Log _log =
      LogFactoryUtil.getLog(EhcachePortalCacheBootstrapLoaderFactory.class);
}
Exemplo n.º 19
0
/**
 * This class provides a SOAP utility for the {@link com.liferay.portal.service.ThemeServiceUtil}
 * service utility. The static methods of this class calls the same methods of the service utility.
 * However, the signatures are different because it is difficult for SOAP to support certain types.
 *
 * <p>The benefits of using the SOAP utility is that it is cross platform compatible. SOAP allows
 * different languages like Java, .NET, C++, PHP, and even Perl, to call the generated services. One
 * drawback of SOAP is that it is slow because it needs to serialize all calls into a text format
 * (XML).
 *
 * <p>You can see a list of services at http://localhost:8080/tunnel-web/secure/axis. Set the
 * property <b>tunnel.servlet.hosts.allowed</b> in portal.properties to configure security.
 *
 * <p>The SOAP utility is only generated for remote services.
 *
 * @author Brian Wing Shun Chan
 * @see ThemeServiceHttp
 * @see com.liferay.portal.service.ThemeServiceUtil
 * @generated
 */
public class ThemeServiceSoap {
  public static java.util.List getThemes(long companyId) throws RemoteException {
    try {
      java.util.List<com.liferay.portal.model.Theme> returnValue =
          ThemeServiceUtil.getThemes(companyId);

      return returnValue;
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }

  public static com.liferay.portal.kernel.json.JSONArray getWARThemes() throws RemoteException {
    try {
      com.liferay.portal.kernel.json.JSONArray returnValue = ThemeServiceUtil.getWARThemes();

      return returnValue;
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }

  private static Log _log = LogFactoryUtil.getLog(ThemeServiceSoap.class);
}
/** Portlet implementation class MyHelloWorldMVCPortlet */
public class MyHelloWorldMVCPortlet extends MVCPortlet {

  private static Log _log = LogFactoryUtil.getLog(MyHelloWorldMVCPortlet.class);

  public void saveName(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {
    _log.debug("saveName started");
    final String name =
        ParamUtil.get(actionRequest, MyHelloWorldMVCUtil.REQUEST_PARAM_NAME, StringPool.BLANK);
    final PortletPreferences portletPreferences = actionRequest.getPreferences();
    if (Validator.isBlank(name)) {
      _log.error("Name is blank. You must introduce valid value for name parameter.");
    } else {
      portletPreferences.setValue(MyHelloWorldMVCUtil.PORTLET_PREFERENCES_PARAM_NAME, name);
      _log.info(
          "saving new value ("
              + name
              + ") of "
              + MyHelloWorldMVCUtil.PORTLET_PREFERENCES_PARAM_NAME
              + " on portletPreferences");
      portletPreferences.store();
    }
    // Una vez que terminas la lógica de saveName forward a la vista
    actionResponse.setPortletMode(PortletMode.VIEW);
  }
}
/**
 * Provides the SOAP utility for the {@link com.liferay.portal.service.PortletServiceUtil} service
 * utility. The static methods of this class calls the same methods of the service utility. However,
 * the signatures are different because it is difficult for SOAP to support certain types.
 *
 * <p>ServiceBuilder follows certain rules in translating the methods. For example, if the method in
 * the service utility returns a {@link java.util.List}, that is translated to an array of {@link
 * com.liferay.portal.model.PortletSoap}. If the method in the service utility returns a {@link
 * com.liferay.portal.model.Portlet}, that is translated to a {@link
 * com.liferay.portal.model.PortletSoap}. Methods that SOAP cannot safely wire are skipped.
 *
 * <p>The benefits of using the SOAP utility is that it is cross platform compatible. SOAP allows
 * different languages like Java, .NET, C++, PHP, and even Perl, to call the generated services. One
 * drawback of SOAP is that it is slow because it needs to serialize all calls into a text format
 * (XML).
 *
 * <p>You can see a list of services at http://localhost:8080/api/axis. Set the property
 * <b>axis.servlet.hosts.allowed</b> in portal.properties to configure security.
 *
 * <p>The SOAP utility is only generated for remote services.
 *
 * @author Brian Wing Shun Chan
 * @see PortletServiceHttp
 * @see com.liferay.portal.model.PortletSoap
 * @see com.liferay.portal.service.PortletServiceUtil
 * @generated
 */
public class PortletServiceSoap {
  public static java.lang.String getWARPortlets() throws RemoteException {
    try {
      com.liferay.portal.kernel.json.JSONArray returnValue = PortletServiceUtil.getWARPortlets();

      return returnValue.toString();
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }

  public static com.liferay.portal.model.PortletSoap updatePortlet(
      long companyId, java.lang.String portletId, java.lang.String roles, boolean active)
      throws RemoteException {
    try {
      com.liferay.portal.model.Portlet returnValue =
          PortletServiceUtil.updatePortlet(companyId, portletId, roles, active);

      return com.liferay.portal.model.PortletSoap.toSoapModel(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }

  private static Log _log = LogFactoryUtil.getLog(PortletServiceSoap.class);
}
Exemplo n.º 22
0
/**
 * @author Raymond Augé
 * @author Miguel Pastor
 */
public class PortalHttpContext implements HttpContext {

  public PortalHttpContext(ServletContext servletContext) {
    _servletContext = servletContext;
  }

  public String getMimeType(String name) {
    String mimeType = _servletContext.getMimeType(name);

    if (mimeType == null) {
      mimeType = MimeTypesUtil.getContentType(name);
    }

    return mimeType;
  }

  public URL getResource(String path) {
    try {
      return _servletContext.getResource(path);
    } catch (MalformedURLException mue) {
      _log.error(mue, mue);
    }

    return null;
  }

  public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) {

    return true;
  }

  private static Log _log = LogFactoryUtil.getLog(PortalHttpContext.class);

  private ServletContext _servletContext;
}
/** @author Julio Camarero */
public abstract class BaseJournalArticlePortletConfigurationIcon
    extends BaseJSPPortletConfigurationIcon {

  protected JournalContentDisplayContext getJournalContentDisplayContext(
      PortletRequest portletRequest, PortletResponse portletResponse) {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    try {
      JournalContentPortletInstanceConfiguration journalContentPortletInstanceConfiguration =
          portletDisplay.getPortletInstanceConfiguration(
              JournalContentPortletInstanceConfiguration.class);

      return new JournalContentDisplayContext(
          portletRequest, portletResponse, journalContentPortletInstanceConfiguration);
    } catch (PortalException pe) {
      _log.error("Unable to create display context", pe);
    }

    return null;
  }

  private static final Log _log =
      LogFactoryUtil.getLog(BaseJournalArticlePortletConfigurationIcon.class);
}
/** @author Alexander Chow */
public class ConvertDocumentLibraryExtraSettings extends ConvertProcess {

  @Override
  public String getDescription() {
    return "convert-extra-settings-from-document-library-files";
  }

  @Override
  public String getPath() {
    return "/admin_server/edit_document_library_extra_settings";
  }

  @Override
  public boolean isEnabled() {
    try {
      return DLFileEntryLocalServiceUtil.hasExtraSettings();
    } catch (Exception e) {
      _log.error(e, e);

      return false;
    }
  }

  @Override
  protected void doConvert() throws Exception {}

  private static Log _log = LogFactoryUtil.getLog(ConvertDocumentLibraryExtraSettings.class);
}
Exemplo n.º 25
0
/**
 * <a href="JBPMServlet.java.html"><b><i>View Source</i></b></a>
 *
 * @author Charles May
 */
public class JBPMServlet extends HttpServlet {

  public void service(HttpServletRequest req, HttpServletResponse res)
      throws IOException, ServletException {

    try {
      String contentType = req.getHeader(HttpHeaders.CONTENT_TYPE);

      if (_log.isDebugEnabled()) {
        _log.debug("Content type " + contentType);
      }

      if ((contentType != null) && (contentType.startsWith(ContentTypes.MULTIPART_FORM_DATA))) {

        req = new UploadServletRequest(req);
      }

      WorkflowComponentImpl workflowComponentImpl = new WorkflowComponentImpl();

      String result = workflowComponentImpl.process(req);

      res.setContentType("text/xml");

      ServletResponseUtil.write(res, result);
    } catch (Exception e) {
      _log.error(e, e);

      res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
  }

  private static Log _log = LogFactoryUtil.getLog(JBPMServlet.class);
}
  public Logger getLogger(String name) {
    Logger logger = null;

    _readLock.lock();

    try {
      logger = _loggers.get(name);
    } finally {
      _readLock.unlock();
    }

    if (logger == null) {
      _writeLock.lock();

      try {
        Log log = LogFactoryUtil.getLog(name);

        logger = new LiferayLoggerAdapter(log);

        _loggers.put(name, logger);
      } finally {
        _writeLock.unlock();
      }
    }

    return logger;
  }
/** @author Scott Lee */
public class UserPasswordPolicyChecker extends RowChecker {

  public UserPasswordPolicyChecker(RenderResponse renderResponse, PasswordPolicy passwordPolicy) {

    super(renderResponse);

    _passwordPolicy = passwordPolicy;
  }

  @Override
  public boolean isChecked(Object obj) {
    User user = (User) obj;

    try {
      return UserLocalServiceUtil.hasPasswordPolicyUser(
          _passwordPolicy.getPasswordPolicyId(), user.getUserId());
    } catch (Exception e) {
      _log.error(e, e);

      return false;
    }
  }

  private static Log _log = LogFactoryUtil.getLog(UserPasswordPolicyChecker.class);

  private PasswordPolicy _passwordPolicy;
}
/** @author Peter Fellwock */
@Component(immediate = true, service = ShoppingServiceUpgrade.class)
public class ShoppingServiceUpgrade {

  @Reference(target = ModuleServiceLifecycle.PORTAL_INITIALIZED, unbind = "-")
  protected void setModuleServiceLifecycle(ModuleServiceLifecycle moduleServiceLifecycle) {}

  @Reference(unbind = "-")
  protected void setReleaseLocalService(ReleaseLocalService releaseLocalService) {

    _releaseLocalService = releaseLocalService;
  }

  @Activate
  protected void upgrade() throws PortalException {
    List<UpgradeProcess> upgradeProcesses = new ArrayList<>();

    upgradeProcesses.add(new UpgradePortletId());

    upgradeProcesses.add(new UpgradeClassNames());
    upgradeProcesses.add(new UpgradeShopping());
    upgradeProcesses.add(new UpgradeShoppingPreferences());

    for (UpgradeProcess upgradeProcess : upgradeProcesses) {
      if (_log.isDebugEnabled()) {
        _log.debug("Upgrade process " + upgradeProcess);
      }
    }
  }

  private static final Log _log = LogFactoryUtil.getLog(ShoppingServiceUpgrade.class);

  private ReleaseLocalService _releaseLocalService;
}
/** @author Raymond Augé */
public class LayoutSetPrototypeLayoutModelListener extends BaseModelListener<Layout> {

  @Override
  public void onAfterCreate(Layout layout) {
    updateLayoutSetPrototype(layout, layout.getModifiedDate());
  }

  @Override
  public void onAfterRemove(Layout layout) {
    updateLayoutSetPrototype(layout, new Date());
  }

  @Override
  public void onAfterUpdate(Layout layout) {
    updateLayoutSetPrototype(layout, layout.getModifiedDate());
  }

  protected void updateLayoutSetPrototype(Layout layout, Date modifiedDate) {
    if (layout == null) {
      return;
    }

    Group group = null;

    try {
      group = layout.getGroup();

      if (!group.isLayoutSetPrototype()) {
        return;
      }
    } catch (PortalException pe) {
      return;
    }

    try {
      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(group.getClassPK());

      layoutSetPrototype.setModifiedDate(modifiedDate);

      LayoutSetPrototypeLocalServiceUtil.updateLayoutSetPrototype(layoutSetPrototype);

      LayoutSet layoutSet = layoutSetPrototype.getLayoutSet();

      layoutSet.setModifiedDate(layout.getModifiedDate());

      UnicodeProperties settingsProperties = layoutSet.getSettingsProperties();

      settingsProperties.remove(Sites.MERGE_FAIL_COUNT);

      LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);
    } catch (Exception e) {
      _log.error(e, e);
    }
  }

  private static final Log _log =
      LogFactoryUtil.getLog(LayoutSetPrototypeLayoutModelListener.class);
}
Exemplo n.º 30
0
/** @author Brian Wing Shun Chan */
public class NetChecker extends BaseChecker {

  public void afterPropertiesSet() {}

  public boolean implies(Permission permission) {
    String name = permission.getName();

    if (name.equals(NET_PERMISSION_GET_PROXY_SELECTOR)) {
      if (!hasGetProxySelector()) {
        logSecurityException(_log, "Attempted to get proxy selector");

        return false;
      }
    } else if (name.equals(NET_PERMISSION_SPECIFY_STREAM_HANDLER)) {

      // TODO

    }

    return true;
  }

  protected boolean hasGetProxySelector() {
    if (JavaDetector.isJDK7()) {
      Class<?> callerClass8 = Reflection.getCallerClass(8);

      String className8 = callerClass8.getName();

      if (className8.startsWith(_CLASS_NAME_SOCKS_SOCKET_IMPL)) {
        logGetProxySelector(callerClass8, 8);

        return true;
      }
    } else {
      Class<?> callerClass7 = Reflection.getCallerClass(7);

      String className7 = callerClass7.getName();

      if (className7.startsWith(_CLASS_NAME_SOCKS_SOCKET_IMPL)) {
        logGetProxySelector(callerClass7, 7);

        return true;
      }
    }

    return false;
  }

  protected void logGetProxySelector(Class<?> callerClass, int frame) {
    if (_log.isInfoEnabled()) {
      _log.info(
          "Allowing frame " + frame + " with caller " + callerClass + " to get the proxy selector");
    }
  }

  private static final String _CLASS_NAME_SOCKS_SOCKET_IMPL = "java.net.SocksSocketImpl$";

  private static Log _log = LogFactoryUtil.getLog(NetChecker.class);
}