- Several bug fixes for potenial bugs found by FindBugs
- Created StaticThemeProvider class


git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5075 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
jensp 2017-10-23 17:08:52 +00:00
parent a9a15eb803
commit 80479cde9f
22 changed files with 360 additions and 113 deletions

View File

@ -7,6 +7,7 @@ import org.libreccm.security.RoleManager;
import org.libreccm.security.RoleMembership; import org.libreccm.security.RoleMembership;
import org.libreccm.security.RoleRepository; import org.libreccm.security.RoleRepository;
import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -19,7 +20,9 @@ import javax.transaction.Transactional;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class RolesController { public class RolesController implements Serializable {
private static final long serialVersionUID = 4127664283856716723L;
@Inject @Inject
private PartyRepository partyRepo; private PartyRepository partyRepo;
@ -70,8 +73,8 @@ public class RolesController {
protected void assignRoleToParty(final Role role, final Party party) { protected void assignRoleToParty(final Role role, final Party party) {
final Party assignee = partyRepo final Party assignee = partyRepo
.findById(party.getPartyId()) .findById(party.getPartyId())
.orElseThrow(() -> new IllegalArgumentException(String .orElseThrow(() -> new IllegalArgumentException(String
.format("No Party with ID %d in the database.", .format("No Party with ID %d in the database.",
party.getPartyId()))); party.getPartyId())));
@ -85,4 +88,3 @@ public class RolesController {
} }
} }

View File

@ -163,7 +163,7 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
final String[] tokens = normalizedPath.split("/"); final String[] tokens = normalizedPath.split("/");
Category current = domain.getRoot(); Category current = domain.getRoot();
for (final String token : tokens) { for (final String token : tokens) {
if (current.getSubCategories() == null) { if (current.getSubCategories().isEmpty()) {
return Optional.empty(); return Optional.empty();
} }
final Optional<Category> result = current.getSubCategories() final Optional<Category> result = current.getSubCategories()

View File

@ -27,11 +27,20 @@ import org.libreccm.modules.Module;
import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.RequiresPrivilege; import org.libreccm.security.RequiresPrivilege;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -40,7 +49,9 @@ import java.util.stream.Collectors;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class ConfigurationManager { public class ConfigurationManager implements Serializable {
private static final long serialVersionUID = 5453012565110339303L;
private static final Logger LOGGER = LogManager.getLogger( private static final Logger LOGGER = LogManager.getLogger(
ConfigurationManager.class); ConfigurationManager.class);
@ -378,7 +389,7 @@ public class ConfigurationManager {
settingName, settingName,
setting.getValue()); setting.getValue());
field.set(conf, setting.getValue()); field.set(conf, setting.getValue());
} catch(IllegalAccessException ex) { } catch (IllegalAccessException ex) {
LOGGER.warn( LOGGER.warn(
"Failed to set value of configuration class \"{}\". " "Failed to set value of configuration class \"{}\". "
+ "Ignoring.", + "Ignoring.",

View File

@ -18,8 +18,13 @@
*/ */
package org.libreccm.core; package org.libreccm.core;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javax.inject.Inject; import javax.inject.Inject;
import javax.persistence.EntityGraph; import javax.persistence.EntityGraph;
@ -29,7 +34,6 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.util.*;
/** /**
* A base class providing common method needed by every repository. * A base class providing common method needed by every repository.
@ -38,13 +42,12 @@ import java.util.*;
* @param <K> Type of the primary key of the entity * @param <K> Type of the primary key of the entity
* @param <E> Type of the entity. * @param <E> Type of the entity.
*/ */
public abstract class AbstractEntityRepository<K, E> { public abstract class AbstractEntityRepository<K, E> implements Serializable {
private static final Logger LOGGER = LogManager.getLogger( private static final long serialVersionUID = 8462548002420023652L;
AbstractEntityRepository.class);
protected static final String FETCH_GRAPH_HINT_KEY protected static final String FETCH_GRAPH_HINT_KEY
= "javax.persistence.fetchgraph"; = "javax.persistence.fetchgraph";
/** /**
* The {@link EntityManager} instance to use. Provided by the container via * The {@link EntityManager} instance to use. Provided by the container via
@ -83,7 +86,7 @@ public abstract class AbstractEntityRepository<K, E> {
* @param query The query from which the result is retrieved. * @param query The query from which the result is retrieved.
* *
* @return An {@link Optional} instance wrapping the first result of the * @return An {@link Optional} instance wrapping the first result of the
* query. If there is no result the {@code Optional} is empty. * query. If there is no result the {@code Optional} is empty.
*/ */
protected Optional<E> getSingleResult(final TypedQuery<E> query) { protected Optional<E> getSingleResult(final TypedQuery<E> query) {
final List<E> result = query.getResultList(); final List<E> result = query.getResultList();
@ -104,12 +107,13 @@ public abstract class AbstractEntityRepository<K, E> {
* @param entityGraphName The name of the named entity graph. * @param entityGraphName The name of the named entity graph.
* *
* @return A mutable copy of the named entity graph identified by the * @return A mutable copy of the named entity graph identified by the
* provided name or {@code null} if there is no such named entity graph. * provided name or {@code null} if there is no such named entity
* graph.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public EntityGraph<E> createEntityGraph(final String entityGraphName) { public EntityGraph<E> createEntityGraph(final String entityGraphName) {
return (EntityGraph<E>) entityManager.createEntityGraph( return (EntityGraph<E>) entityManager.createEntityGraph(
entityGraphName); entityGraphName);
} }
/** /**
@ -117,7 +121,7 @@ public abstract class AbstractEntityRepository<K, E> {
* a repository class overwrite this method. * a repository class overwrite this method.
* *
* @return The {@code Class} of the Entity which are managed by this * @return The {@code Class} of the Entity which are managed by this
* repository. * repository.
*/ */
public abstract Class<E> getEntityClass(); public abstract Class<E> getEntityClass();
@ -127,7 +131,8 @@ public abstract class AbstractEntityRepository<K, E> {
* @param entityId The ID of the entity to retrieve. * @param entityId The ID of the entity to retrieve.
* *
* @return An {@link Optional} containing the entity identified by the * @return An {@link Optional} containing the entity identified by the
* provided ID or am empty {@link Optional} if there is no such entity. * provided ID or am empty {@link Optional} if there is no such
* entity.
*/ */
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public Optional<E> findById(final K entityId) { public Optional<E> findById(final K entityId) {
@ -141,7 +146,7 @@ public abstract class AbstractEntityRepository<K, E> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final EntityGraph<E> entityGraph = (EntityGraph<E>) entityManager. final EntityGraph<E> entityGraph = (EntityGraph<E>) entityManager.
getEntityGraph(entityGraphName); getEntityGraph(entityGraphName);
return findById(entityId, entityGraph); return findById(entityId, entityGraph);
} }
@ -161,7 +166,7 @@ public abstract class AbstractEntityRepository<K, E> {
* responsible for. * responsible for.
* *
* @return The list of entities in the database which are of the type * @return The list of entities in the database which are of the type
* provided by {@link #getEntityClass()}. * provided by {@link #getEntityClass()}.
*/ */
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<E> findAll() { public List<E> findAll() {
@ -174,7 +179,7 @@ public abstract class AbstractEntityRepository<K, E> {
public List<E> findAll(final String entityGraphName) { public List<E> findAll(final String entityGraphName) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final EntityGraph<E> entityGraph = (EntityGraph<E>) entityManager final EntityGraph<E> entityGraph = (EntityGraph<E>) entityManager
.getEntityGraph(entityGraphName); .getEntityGraph(entityGraphName);
return findAll(entityGraph); return findAll(entityGraph);
} }
@ -188,9 +193,9 @@ public abstract class AbstractEntityRepository<K, E> {
public CriteriaQuery<E> createCriteriaQuery() { public CriteriaQuery<E> createCriteriaQuery() {
final CriteriaBuilder criteriaBuilder = entityManager final CriteriaBuilder criteriaBuilder = entityManager
.getCriteriaBuilder(); .getCriteriaBuilder();
final CriteriaQuery<E> criteriaQuery = criteriaBuilder.createQuery( final CriteriaQuery<E> criteriaQuery = criteriaBuilder.createQuery(
getEntityClass()); getEntityClass());
final Root<E> root = criteriaQuery.from(getEntityClass()); final Root<E> root = criteriaQuery.from(getEntityClass());
return criteriaQuery.select(root); return criteriaQuery.select(root);
} }
@ -208,8 +213,8 @@ public abstract class AbstractEntityRepository<K, E> {
final String graphName) { final String graphName) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final EntityGraph<E> entityGraph = (EntityGraph< E>) entityManager final EntityGraph<E> entityGraph = (EntityGraph< E>) entityManager
.getEntityGraph( .getEntityGraph(
graphName); graphName);
return executeCriteriaQuery(criteriaQuery, entityGraph); return executeCriteriaQuery(criteriaQuery, entityGraph);
} }
@ -228,7 +233,7 @@ public abstract class AbstractEntityRepository<K, E> {
* @param entity The entity to check. * @param entity The entity to check.
* *
* @return {@code true} if the entity is new (isn't in the database yet), * @return {@code true} if the entity is new (isn't in the database yet),
* {@code false} otherwise. * {@code false} otherwise.
*/ */
public abstract boolean isNew(final E entity); public abstract boolean isNew(final E entity);

View File

@ -23,7 +23,9 @@ import org.libreccm.configuration.ConfigurationManager;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import java.io.*; import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -78,14 +80,17 @@ public class NIOFileSystemAdapter implements FileSystemAdapter {
throw new InsufficientPermissionsException(path); throw new InsufficientPermissionsException(path);
} }
final FileReader fileReader; final InputStreamReader reader;
try { try {
fileReader = new FileReader(nioPath.toFile()); final FileInputStream inputStream = new FileInputStream(
nioPath.toFile());
reader = new InputStreamReader(inputStream,
Charset.forName("UTF-8"));
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
throw new FileDoesNotExistException(path, ex); throw new FileDoesNotExistException(path, ex);
} }
return fileReader; return reader;
} }
@Override @Override
@ -107,14 +112,17 @@ public class NIOFileSystemAdapter implements FileSystemAdapter {
throw new InsufficientPermissionsException(path); throw new InsufficientPermissionsException(path);
} }
final FileWriter fileWriter; final OutputStreamWriter writer;
try { try {
fileWriter = new FileWriter(nioPath.toFile()); final FileOutputStream outputStream = new FileOutputStream(nioPath
.toFile());
writer = new OutputStreamWriter(outputStream,
Charset.forName("UTF-8"));
} catch (IOException ex) { } catch (IOException ex) {
throw new FileAccessException(path, ex); throw new FileAccessException(path, ex);
} }
return fileWriter; return writer;
} }
@Override @Override

View File

@ -25,6 +25,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.libreccm.configuration.ConfigurationManager; import org.libreccm.configuration.ConfigurationManager;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -68,7 +70,9 @@ import java.util.ResourceBundle;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class GlobalizationHelper { public class GlobalizationHelper implements Serializable {
private static final long serialVersionUID = 3988918294651460360L;
private static final Logger LOGGER = LogManager private static final Logger LOGGER = LogManager
.getLogger(GlobalizationHelper.class); .getLogger(GlobalizationHelper.class);
@ -76,7 +80,7 @@ public class GlobalizationHelper {
private static final String LANG_PARAM = "lang"; private static final String LANG_PARAM = "lang";
@Inject @Inject
private HttpServletRequest request; private transient HttpServletRequest request;
@Inject @Inject
private ConfigurationManager confManager; private ConfigurationManager confManager;

View File

@ -1,7 +1,6 @@
package org.libreccm.l10n.ui; package org.libreccm.l10n.ui;
import com.vaadin.data.provider.QuerySortOrder; import com.vaadin.data.provider.QuerySortOrder;
import com.vaadin.server.SerializableSupplier;
import com.vaadin.ui.CustomComponent; import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Grid; import com.vaadin.ui.Grid;
import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.l10n.GlobalizationHelper;
@ -10,7 +9,6 @@ import org.libreccm.l10n.LocalizedString;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -178,9 +176,8 @@ public class LocalizedStringEditor extends CustomComponent {
.compareTo(Objects.toString(locale2)); .compareTo(Objects.toString(locale2));
}); });
locales.subList(offset, limit);
return locales return locales
.subList(offset, limit)
.stream() .stream()
.map(locale -> new LocalizedStringValue( .map(locale -> new LocalizedStringValue(
locale, localizedString.getValue(locale))); locale, localizedString.getValue(locale)));

View File

@ -94,7 +94,7 @@ public class ComponentRendererManager {
/** /**
* Annotation literal for the {@link ComponentModelType} annotation. * Annotation literal for the {@link ComponentModelType} annotation.
*/ */
private class ComponentModelTypeLiteral private static class ComponentModelTypeLiteral
extends AnnotationLiteral<ComponentModelType> extends AnnotationLiteral<ComponentModelType>
implements ComponentModelType { implements ComponentModelType {

View File

@ -42,7 +42,7 @@ class PageTreeModel implements TreeModel {
public boolean hasChildren(final TreeNode node, final PageState state) { public boolean hasChildren(final TreeNode node, final PageState state) {
if (node instanceof RootNode) { if (node instanceof RootNode) {
return true; return true;
} else if (node instanceof ApplicationTypeTreeNode) { } else if (node instanceof ApplicationTreeNode) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PageModelRepository pageModelRepo = cdiUtil.findBean( final PageModelRepository pageModelRepo = cdiUtil.findBean(
PageModelRepository.class); PageModelRepository.class);

View File

@ -35,6 +35,8 @@ import java.util.Optional;
@RequestScoped @RequestScoped
public class PartyRepository extends AbstractEntityRepository<Long, Party> { public class PartyRepository extends AbstractEntityRepository<Long, Party> {
private static final long serialVersionUID = -8056652791690243141L;
@Override @Override
public Class<Party> getEntityClass() { public Class<Party> getEntityClass() {
return Party.class; return Party.class;

View File

@ -416,12 +416,6 @@ public class PermissionManager {
final Role grantee, final Role grantee,
final CcmObject object) { final CcmObject object) {
LOGGER.debug("Revoking permission granting privilege \"{}\" "
+ "on object \"{}\" to role \"{}\"...",
privilege,
grantee.getName(),
object.getUuid());
if (privilege == null || privilege.isEmpty()) { if (privilege == null || privilege.isEmpty()) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Can't revoke a permission without a privilege."); "Can't revoke a permission without a privilege.");
@ -437,6 +431,12 @@ public class PermissionManager {
"Can't revoke a permission from object NULL."); "Can't revoke a permission from object NULL.");
} }
LOGGER.debug("Revoking permission granting privilege \"{}\" "
+ "on object \"{}\" to role \"{}\"...",
privilege,
grantee.getName(),
object.getUuid());
if (existsPermission(privilege, grantee, object) if (existsPermission(privilege, grantee, object)
|| existsInheritedPermission(privilege, grantee, object)) { || existsInheritedPermission(privilege, grantee, object)) {

View File

@ -20,12 +20,15 @@ package org.libreccm.security;
import org.libreccm.core.CoreConstants; import org.libreccm.core.CoreConstants;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -39,7 +42,9 @@ import java.util.stream.Collectors;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class RoleManager { public class RoleManager implements Serializable {
private static final long serialVersionUID = -3012991584385998270L;
@Inject @Inject
private RoleRepository roleRepository; private RoleRepository roleRepository;
@ -166,7 +171,7 @@ public class RoleManager {
.map(membership -> membership.getRole()) .map(membership -> membership.getRole())
.collect(Collectors.toList()); .collect(Collectors.toList());
final Set<Role> roles = new HashSet<>(); final Set<Role> roles = new HashSet<>(directlyAssigned);
final List<Group> groups = user final List<Group> groups = user
.getGroupMemberships() .getGroupMemberships()

View File

@ -37,6 +37,8 @@ import java.util.Optional;
@RequestScoped @RequestScoped
public class RoleRepository extends AbstractEntityRepository<Long, Role> { public class RoleRepository extends AbstractEntityRepository<Long, Role> {
private static final long serialVersionUID = 2285369521940062504L;
@Override @Override
public Class<Role> getEntityClass() { public Class<Role> getEntityClass() {
return Role.class; return Role.class;

View File

@ -19,6 +19,7 @@
package org.libreccm.security; package org.libreccm.security;
import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.KernelConfig;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.Session; import org.apache.shiro.session.Session;
@ -26,10 +27,13 @@ import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.SimplePrincipalCollection; import org.apache.shiro.subject.SimplePrincipalCollection;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import java.io.Serializable;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces; import javax.enterprise.inject.Produces;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -50,7 +54,9 @@ import java.util.Optional;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@ApplicationScoped @ApplicationScoped
public class Shiro { public class Shiro implements Serializable {
private static final long serialVersionUID = -3270585472267405099L;
/** /**
* Principal used for the public user if * Principal used for the public user if
@ -67,7 +73,8 @@ public class Shiro {
* *
* @see #getPublicUser() * @see #getPublicUser()
*/ */
public static final String PUBLIC_USER_PRINCIPAL_EMAIL = "public-user@localhost"; public static final String PUBLIC_USER_PRINCIPAL_EMAIL
= "public-user@localhost";
/** /**
* Principal used for the system user if * Principal used for the system user if
@ -84,7 +91,8 @@ public class Shiro {
* *
* @see #getSystemUser() * @see #getSystemUser()
*/ */
public static final String SYSTEM_USER_PRINCIPAL_EMAIL = "system-user@localhost"; public static final String SYSTEM_USER_PRINCIPAL_EMAIL
= "system-user@localhost";
@Inject @Inject
private UserRepository userRepository; private UserRepository userRepository;
@ -171,8 +179,9 @@ public class Shiro {
* subject. * subject.
* *
* @return An {@link Optional} containing the {@link User} entity for the * @return An {@link Optional} containing the {@link User} entity for the
* current subject. If the current subject is a virtual user which has no * current subject. If the current subject is a virtual user which
* representation in the database the returned {@link Optional} is empty. * has no representation in the database the returned
* {@link Optional} is empty.
* *
* @see #getSubject() * @see #getSubject()
* @see #getSystemUser() * @see #getSystemUser()
@ -223,6 +232,7 @@ public class Shiro {
throw ex.getTargetException(); throw ex.getTargetException();
} }
} }
} }
private static class SubjectInvocationHandler extends Handler { private static class SubjectInvocationHandler extends Handler {
@ -233,6 +243,7 @@ public class Shiro {
final Object[] args) throws Throwable { final Object[] args) throws Throwable {
return method.invoke(SecurityUtils.getSubject(), args); return method.invoke(SecurityUtils.getSubject(), args);
} }
} }
private static class SecurityManagerInvocationHandler extends Handler { private static class SecurityManagerInvocationHandler extends Handler {
@ -254,6 +265,7 @@ public class Shiro {
final Object[] args) throws Throwable { final Object[] args) throws Throwable {
return method.invoke(SecurityUtils.getSubject().getSession(), args); return method.invoke(SecurityUtils.getSubject().getSession(), args);
} }
} }
} }

View File

@ -116,6 +116,10 @@ public class Site extends CcmObject {
return false; return false;
} }
final Site other = (Site) obj; final Site other = (Site) obj;
if (!other.canEqual(this)) {
return false;
}
if (defaultSite != other.isDefaultSite()) { if (defaultSite != other.isDefaultSite()) {
return false; return false;
} }

View File

@ -0,0 +1,195 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.theming;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.core.UnexpectedErrorException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* A theme provider implementation which serves themes from the class path
* ({@code /themes)}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class StaticThemeProvider implements ThemeProvider {
private static final Logger LOGGER = LogManager
.getLogger(StaticThemeProvider.class);
private static final String THEMES_DIR = "/themes";
private static final String THEME_XML = "theme.xml";
private static final String THEME_JSON = "theme.json";
@Override
public List<ThemeInfo> getThemes() {
LOGGER.debug("Retrieving info about all static themes...");
final List<ThemeInfo> themeInfos = new ArrayList<>();
try (final FileSystem jarFileSystem = FileSystems.newFileSystem(
getJarUri(), Collections.emptyMap())) {
final Path themesPath = jarFileSystem.getPath(THEMES_DIR);
if (!Files.isDirectory(themesPath)) {
LOGGER.warn(THEMES_DIR + " is not a directory. Returning "
+ "empty list.");
return Collections.emptyList();
}
return Files
.list(themesPath)
.filter(this::isTheme)
.map(this::generateThemeInfo)
.collect(Collectors.toList());
} catch (IOException ex) {
throw new UnexpectedErrorException(ex);
}
}
@Override
public List<ThemeInfo> getLiveThemes() {
return getThemes();
}
@Override
public Optional<ThemeInfo> getThemeInfo(String theme, ThemeVersion version) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean providesTheme(String theme, ThemeVersion version) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public List<ThemeFileInfo> listThemeFiles(String theme, ThemeVersion version,
String path) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Optional<InputStream> getThemeFileAsStream(String theme,
ThemeVersion version,
String path) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public OutputStream getOutputStreamForThemeFile(String theme, String path) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean supportsChanges() {
return false;
}
@Override
public boolean supportsDraftThemes() {
return false;
}
@Override
public void publishTheme(final String theme) {
LOGGER.info("StaticThemeProvider#publishTheme(String) called, but "
+ "StaticThemeProvider does not support draft/live "
+ "themes.");
}
private URI getJarUri() {
LOGGER.debug("Getting URI of JAR...");
final String themesUrl = getClass().getResource(THEMES_DIR).toString();
LOGGER.debug("Full URL of " + THEMES_DIR + " directory: {}", themesUrl);
final int index = themesUrl.indexOf('!');
final String pathToJar = themesUrl.substring(0, index);
final URI uri = URI.create(pathToJar);
LOGGER.debug("URI to JAR is \"%s\".", uri.toString());
return uri;
}
private boolean isTheme(final Path path) {
Objects.requireNonNull(path);
if (!Files.isDirectory(path)) {
return false;
}
final Path manifestPathJson = path.resolve(THEME_JSON);
final Path manifestPathXml = path.resolve(THEME_XML);
return Files.exists(manifestPathJson) || Files.exists(manifestPathXml);
}
private ThemeInfo generateThemeInfo(final Path path) {
Objects.requireNonNull(path);
if (!Files.exists(path)) {
throw new IllegalArgumentException(String
.format("The provided path \"%s\" does "
+ "not exist.",
path.toString()));
}
final Path manifestPathJson = path.resolve(THEME_JSON);
final Path manifestPathXml = path.resolve(THEME_XML);
if (Files.exists(manifestPathJson)) {
return generateThemeInfoFromJson(manifestPathJson);
} else if (Files.exists(manifestPathXml)) {
return generateThemeInfoFromXml(manifestPathXml);
} else {
throw new IllegalArgumentException(String
.format("The provided path \"%s\" does "
+ "contain a theme manifest file.",
path.toString()));
}
}
private ThemeInfo generateThemeInfoFromJson(final Path path) {
throw new UnsupportedOperationException();
}
private ThemeInfo generateThemeInfoFromXml(final Path path) {
throw new UnsupportedOperationException();
}
}

View File

@ -126,7 +126,7 @@ public class Themes {
return processor.process(page, theme, provider); return processor.process(page, theme, provider);
} }
private class ThemeTypeLiteral extends AnnotationLiteral<ThemeType> private static class ThemeTypeLiteral extends AnnotationLiteral<ThemeType>
implements ThemeType { implements ThemeType {
private static final long serialVersionUID = 3377237291286175824L; private static final long serialVersionUID = 3377237291286175824L;

View File

@ -336,7 +336,9 @@ public class LocalizedStringWidget extends CustomComponent {
UI.getCurrent().addWindow(window); UI.getCurrent().addWindow(window);
} }
private class SimpleTextEditor extends TextArea implements TextEditor { private static class SimpleTextEditor
extends TextArea
implements TextEditor {
private static final long serialVersionUID = -1189747199799719077L; private static final long serialVersionUID = -1189747199799719077L;

View File

@ -22,6 +22,7 @@ import com.arsdigita.kernel.KernelConfig;
import org.libreccm.configuration.ConfigurationManager; import org.libreccm.configuration.ConfigurationManager;
import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -38,7 +39,9 @@ import javax.inject.Inject;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class LocalizedStringWidgetController { public class LocalizedStringWidgetController implements Serializable {
private static final long serialVersionUID = -8390792440087872905L;
@Inject @Inject
private ConfigurationManager confManager; private ConfigurationManager confManager;
@ -53,17 +56,16 @@ public class LocalizedStringWidgetController {
public List<Locale> getSupportedLocales() { public List<Locale> getSupportedLocales() {
final KernelConfig kernelConfig = confManager final KernelConfig kernelConfig = confManager
.findConfiguration(KernelConfig.class); .findConfiguration(KernelConfig.class);
return kernelConfig return kernelConfig
.getSupportedLanguages() .getSupportedLanguages()
.stream() .stream()
.sorted((lang1, lang2) -> lang1.compareTo(lang2)) .sorted((lang1, lang2) -> lang1.compareTo(lang2))
.map(Locale::new) .map(Locale::new)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.libreccm.ui; package org.libreccm.ui;
import java.io.Serializable;
/** /**
* A functional interface which can be used by other components which embed * A functional interface which can be used by other components which embed
* a text editor. * a text editor.
@ -25,7 +27,7 @@ package org.libreccm.ui;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@FunctionalInterface @FunctionalInterface
public interface TextEditorBuilder { public interface TextEditorBuilder extends Serializable {
/** /**
* Create the text editor component. * Create the text editor component.

View File

@ -43,7 +43,7 @@ public class UserContextController implements Serializable {
private Shiro shiro; private Shiro shiro;
@Inject @Inject
private Subject subject; private transient Subject subject;
public boolean isLoggedIn() { public boolean isLoggedIn() {
return subject.isAuthenticated(); return subject.isAuthenticated();

View File

@ -376,10 +376,7 @@ public class Task implements Identifiable, Serializable {
+ "uuid = \"%s\", " + "uuid = \"%s\", "
+ "label = %s, " + "label = %s, "
+ "active = %b, " + "active = %b, "
+ "taskState = \"%s\", " + "taskState = \"%s\"%s"
// + "workflow = %s, "
// + "dependentTasks = %s, "
// + "dependsOn = %s%s"
+ " }", + " }",
super.toString(), super.toString(),
taskId, taskId,
@ -387,9 +384,6 @@ public class Task implements Identifiable, Serializable {
Objects.toString(label), Objects.toString(label),
active, active,
taskState, taskState,
// Objects.toString(workflow),
// Objects.toString(dependentTasks),
// Objects.toString(dependsOn),
data); data);
} }