mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 03:01:05 +01:00
Fix build warnings (#1562)
Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
@@ -26,6 +26,7 @@ package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ObjectFactory;
|
||||
import sonia.scm.security.ApiKey;
|
||||
|
||||
@@ -39,6 +40,7 @@ public abstract class ApiKeyToApiKeyDtoMapper {
|
||||
@Inject
|
||||
private ResourceLinks resourceLinks;
|
||||
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
abstract ApiKeyDto map(ApiKey key, String user);
|
||||
|
||||
@ObjectFactory
|
||||
|
||||
@@ -27,10 +27,12 @@ package sonia.scm.api.v2.resources;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import de.otto.edison.hal.Links;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class BlameDto extends HalRepresentation {
|
||||
|
||||
private List<BlameLineDto> lines;
|
||||
|
||||
@@ -55,6 +55,7 @@ public abstract class BrowserResultToFileObjectDtoMapper extends BaseFileObjectD
|
||||
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
@Mapping(target = "children", qualifiedBy = Children.class)
|
||||
@Mapping(target = "revision", ignore = true)
|
||||
@Children
|
||||
protected abstract FileObjectDto fileObjectToDto(FileObject fileObject, @Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult, @Context Integer offset);
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import de.otto.edison.hal.Embedded;
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ObjectFactory;
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Changeset;
|
||||
@@ -80,6 +81,7 @@ public abstract class DefaultChangesetToChangesetDtoMapper extends HalAppenderMa
|
||||
|
||||
abstract ContributorDto map(Contributor contributor);
|
||||
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
abstract SignatureDto map(Signature signature);
|
||||
|
||||
abstract PersonDto map(Person person);
|
||||
|
||||
@@ -29,10 +29,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import de.otto.edison.hal.Links;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class DiffResultDto extends HalRepresentation {
|
||||
|
||||
public DiffResultDto(Links links) {
|
||||
@@ -42,6 +44,7 @@ public class DiffResultDto extends HalRepresentation {
|
||||
private List<FileDto> files;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
||||
public static class FileDto extends HalRepresentation {
|
||||
|
||||
|
||||
@@ -33,5 +33,6 @@ import sonia.scm.group.Group;
|
||||
public abstract class GroupDtoToGroupMapper extends BaseDtoMapper {
|
||||
|
||||
@Mapping(target = "creationDate", ignore = true)
|
||||
@Mapping(target = "properties", ignore = true)
|
||||
public abstract Group map(GroupDto groupDto);
|
||||
}
|
||||
|
||||
@@ -90,12 +90,12 @@ public class IncomingRootResource {
|
||||
* - ° b2
|
||||
* -
|
||||
* <p>
|
||||
* - /incoming/a/master/changesets -> a1 , e1
|
||||
* - /incoming/b/master/changesets -> b1 , b2
|
||||
* - /incoming/b/f/changesets -> b1 , b2, m2
|
||||
* - /incoming/f/b/changesets -> f1 , e1
|
||||
* - /incoming/a/b/changesets -> a1 , e1
|
||||
* - /incoming/a/b/changesets -> a1 , e1
|
||||
* - /incoming/a/master/changesets -> a1 , e1
|
||||
* - /incoming/b/master/changesets -> b1 , b2
|
||||
* - /incoming/b/f/changesets -> b1 , b2, m2
|
||||
* - /incoming/f/b/changesets -> f1 , e1
|
||||
* - /incoming/a/b/changesets -> a1 , e1
|
||||
* - /incoming/a/b/changesets -> a1 , e1
|
||||
*
|
||||
* @param namespace
|
||||
* @param name
|
||||
|
||||
@@ -232,7 +232,6 @@ public class NamespacePermissionResource {
|
||||
*
|
||||
* @param permission permission to modify
|
||||
* @param permissionName permission to modify
|
||||
* @return a web response with the status code 204
|
||||
*/
|
||||
@PUT
|
||||
@Path("{permission-name}")
|
||||
@@ -264,8 +263,8 @@ public class NamespacePermissionResource {
|
||||
)
|
||||
)
|
||||
public void update(@PathParam("namespace") String namespaceName,
|
||||
@PathParam("permission-name") String permissionName,
|
||||
@Valid RepositoryPermissionDto permission) {
|
||||
@PathParam("permission-name") String permissionName,
|
||||
@Valid RepositoryPermissionDto permission) {
|
||||
Namespace namespace = load(namespaceName);
|
||||
String extractedPermissionName = getPermissionName(permissionName);
|
||||
if (!isPermissionExist(new RepositoryPermissionDto(extractedPermissionName, isGroupPermission(permissionName)), namespace)) {
|
||||
@@ -294,7 +293,6 @@ public class NamespacePermissionResource {
|
||||
* Update a permission to the user or group managed by the repository
|
||||
*
|
||||
* @param permissionName permission to delete
|
||||
* @return a web response with the status code 204
|
||||
*/
|
||||
@DELETE
|
||||
@Path("{permission-name}")
|
||||
@@ -311,7 +309,7 @@ public class NamespacePermissionResource {
|
||||
)
|
||||
)
|
||||
public void delete(@PathParam("namespace") String namespaceName,
|
||||
@PathParam("permission-name") String permissionName) {
|
||||
@PathParam("permission-name") String permissionName) {
|
||||
log.info("try to delete the permission with name: {}.", permissionName);
|
||||
Namespace namespace = load(namespaceName);
|
||||
namespace.getPermissions()
|
||||
|
||||
@@ -26,6 +26,7 @@ package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import sonia.scm.lifecycle.Restarter;
|
||||
import sonia.scm.plugin.AvailablePlugin;
|
||||
@@ -51,6 +52,13 @@ public abstract class PluginDtoMapper {
|
||||
@Inject
|
||||
private Restarter restarter;
|
||||
|
||||
@Mapping(target = "newVersion", ignore = true)
|
||||
@Mapping(target = "pending", ignore = true)
|
||||
@Mapping(target = "core", ignore = true)
|
||||
@Mapping(target = "markedForUninstall", ignore = true)
|
||||
@Mapping(target = "dependencies", ignore = true)
|
||||
@Mapping(target = "optionalDependencies", ignore = true)
|
||||
@Mapping(target = "attributes", ignore = true)
|
||||
public abstract void map(PluginInformation plugin, @MappingTarget PluginDto dto);
|
||||
|
||||
public PluginDto mapInstalled(InstalledPlugin plugin, List<AvailablePlugin> availablePlugins) {
|
||||
|
||||
@@ -37,6 +37,8 @@ public abstract class RepositoryDtoToRepositoryMapper extends BaseDtoMapper {
|
||||
@Mapping(target = "creationDate", ignore = true)
|
||||
@Mapping(target = "id", ignore = true)
|
||||
@Mapping(target = "healthCheckFailures", ignore = true)
|
||||
@Mapping(target = "properties", ignore = true)
|
||||
@Mapping(target = "permissions", ignore = true)
|
||||
public abstract Repository map(RepositoryDto repositoryDto, @Context String id);
|
||||
|
||||
@AfterMapping
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ObjectFactory;
|
||||
import sonia.scm.importexport.ExportService;
|
||||
import sonia.scm.importexport.ExportStatus;
|
||||
@@ -56,6 +57,7 @@ public abstract class RepositoryExportInformationToDtoMapper {
|
||||
this.exportService = exportService;
|
||||
}
|
||||
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
abstract RepositoryExportInformationDto map(RepositoryExportInformation info, @Context Repository repository);
|
||||
|
||||
@ObjectFactory
|
||||
|
||||
@@ -27,6 +27,7 @@ package sonia.scm.api.v2.resources;
|
||||
import de.otto.edison.hal.Embedded;
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ObjectFactory;
|
||||
import sonia.scm.repository.RepositoryRole;
|
||||
import sonia.scm.repository.RepositoryRolePermissions;
|
||||
@@ -46,6 +47,7 @@ public abstract class RepositoryRoleToRepositoryRoleDtoMapper extends BaseMapper
|
||||
@Inject
|
||||
private ResourceLinks resourceLinks;
|
||||
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
@Override
|
||||
public abstract RepositoryRoleDto map(RepositoryRole modelObject);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import de.otto.edison.hal.Link;
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.ObjectFactory;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
@@ -70,6 +71,8 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
|
||||
abstract HealthCheckFailureDto toDto(HealthCheckFailure failure);
|
||||
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
@Mapping(target = "exporting", ignore = true)
|
||||
@Override
|
||||
public abstract RepositoryDto map(Repository modelObject);
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ public abstract class ResteasyViolationExceptionToErrorDtoMapper {
|
||||
@Mapping(target = "context", ignore = true)
|
||||
@Mapping(target = "url", ignore = true)
|
||||
@Mapping(target = "violations", ignore = true)
|
||||
@Mapping(target = "additionalMessages", ignore = true)
|
||||
public abstract ErrorDto map(ConstraintViolationException exception);
|
||||
|
||||
@AfterMapping
|
||||
|
||||
@@ -38,6 +38,7 @@ public interface ScmViolationExceptionToErrorDtoMapper {
|
||||
@Mapping(target = "errorCode", ignore = true)
|
||||
@Mapping(target = "transactionId", ignore = true)
|
||||
@Mapping(target = "context", ignore = true)
|
||||
@Mapping(target = "additionalMessages", ignore = true)
|
||||
ErrorDto map(ScmConstraintViolationException exception);
|
||||
|
||||
@AfterMapping
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import org.mapstruct.AfterMapping;
|
||||
@@ -37,6 +37,7 @@ import sonia.scm.user.User;
|
||||
public abstract class UserDtoToUserMapper extends BaseDtoMapper {
|
||||
|
||||
@Mapping(target = "creationDate", ignore = true)
|
||||
@Mapping(target = "properties", ignore = true)
|
||||
public abstract User map(UserDto userDto, @Context String usedPassword);
|
||||
|
||||
|
||||
|
||||
@@ -21,29 +21,21 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.lifecycle.classloading.ClassLoaderLifeCycle;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -59,27 +51,8 @@ public final class PluginsInternal
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(PluginsInternal.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
private PluginsInternal() {}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param classLoader
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Set<InstalledPlugin> collectPlugins(ClassLoaderLifeCycle classLoaderLifeCycle,
|
||||
Path directory)
|
||||
throws IOException
|
||||
@@ -89,15 +62,6 @@ public final class PluginsInternal
|
||||
return processor.collectPlugins(classLoaderLifeCycle.getBootstrapClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param parent
|
||||
* @param plugin
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File createPluginDirectory(File parent, InstalledPluginDescriptor plugin)
|
||||
{
|
||||
PluginInformation info = plugin.getInformation();
|
||||
@@ -105,18 +69,6 @@ public final class PluginsInternal
|
||||
return new File(parent, info.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param archive
|
||||
* @param checksum
|
||||
* @param directory
|
||||
* @param checksumFile
|
||||
* @param core
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void extract(SmpArchive archive, String checksum,
|
||||
File directory, File checksumFile, boolean core)
|
||||
throws IOException
|
||||
@@ -144,56 +96,21 @@ public final class PluginsInternal
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param wrapped
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Iterable<InstalledPluginDescriptor> unwrap(Iterable<InstalledPlugin> wrapped)
|
||||
{
|
||||
return Iterables.transform(wrapped, new Unwrap());
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param pluginDirectory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getChecksumFile(File pluginDirectory)
|
||||
{
|
||||
return new File(pluginDirectory, PluginConstants.FILE_CHECKSUM);
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class description
|
||||
*
|
||||
*
|
||||
* @version Enter version here..., 14/06/05
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
private static class Unwrap implements Function<InstalledPlugin, InstalledPluginDescriptor>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param wrapper
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public InstalledPluginDescriptor apply(InstalledPlugin wrapper)
|
||||
@Override
|
||||
public InstalledPluginDescriptor apply(InstalledPlugin wrapper)
|
||||
{
|
||||
return wrapper.getDescriptor();
|
||||
}
|
||||
|
||||
@@ -21,10 +21,9 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.github.legman.Subscribe;
|
||||
import com.google.common.base.Objects;
|
||||
@@ -62,7 +61,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* TODO add events
|
||||
@@ -71,13 +69,10 @@ import static java.util.Objects.isNull;
|
||||
* @since 1.31
|
||||
*/
|
||||
@Singleton
|
||||
public class DefaultSecuritySystem implements SecuritySystem
|
||||
{
|
||||
public class DefaultSecuritySystem implements SecuritySystem {
|
||||
|
||||
/** Field description */
|
||||
private static final String NAME = "security";
|
||||
|
||||
/** Field description */
|
||||
private static final String PERMISSION_DESCRIPTOR =
|
||||
"META-INF/scm/permissions.xml";
|
||||
|
||||
@@ -87,18 +82,8 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(DefaultSecuritySystem.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param storeFactory
|
||||
*/
|
||||
@Inject
|
||||
@SuppressWarnings("unchecked")
|
||||
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory, PluginLoader pluginLoader)
|
||||
{
|
||||
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory, PluginLoader pluginLoader) {
|
||||
store = storeFactory
|
||||
.withType(AssignedPermission.class)
|
||||
.withName(NAME)
|
||||
@@ -106,19 +91,8 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
this.availablePermissions = readAvailablePermissions(pluginLoader);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param permission
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void addPermission(AssignedPermission permission)
|
||||
{
|
||||
public void addPermission(AssignedPermission permission) {
|
||||
assertHasPermission();
|
||||
validatePermission(permission);
|
||||
|
||||
@@ -133,15 +107,8 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
//J+
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param permission
|
||||
*/
|
||||
@Override
|
||||
public void deletePermission(AssignedPermission permission)
|
||||
{
|
||||
public void deletePermission(AssignedPermission permission) {
|
||||
assertHasPermission();
|
||||
boolean deleted = deletePermissions(sap -> Objects.equal(sap.getName(), permission.getName())
|
||||
&& Objects.equal(sap.isGroupPermission(), permission.isGroupPermission())
|
||||
@@ -153,71 +120,35 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe
|
||||
public void handleEvent(final UserEvent event)
|
||||
{
|
||||
if (event.getEventType() == HandlerEventType.DELETE)
|
||||
{
|
||||
public void handleEvent(final UserEvent event) {
|
||||
if (event.getEventType() == HandlerEventType.DELETE) {
|
||||
deletePermissions(p -> !p.isGroupPermission()
|
||||
&& event.getItem().getName().equals(p.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe
|
||||
public void handleEvent(final GroupEvent event)
|
||||
{
|
||||
if (event.getEventType() == HandlerEventType.DELETE)
|
||||
{
|
||||
public void handleEvent(final GroupEvent event) {
|
||||
if (event.getEventType() == HandlerEventType.DELETE) {
|
||||
deletePermissions(p -> p.isGroupPermission()
|
||||
&& event.getItem().getName().equals(p.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<PermissionDescriptor> getAvailablePermissions()
|
||||
{
|
||||
public Collection<PermissionDescriptor> getAvailablePermissions() {
|
||||
assertHasPermission();
|
||||
|
||||
return availablePermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param predicate
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<AssignedPermission> getPermissions(Predicate<AssignedPermission> predicate)
|
||||
{
|
||||
public Collection<AssignedPermission> getPermissions(Predicate<AssignedPermission> predicate) {
|
||||
Builder<AssignedPermission> permissions = ImmutableSet.builder();
|
||||
|
||||
for (Entry<String, AssignedPermission> e : store.getAll().entrySet())
|
||||
{
|
||||
if ((predicate == null) || predicate.test(e.getValue()))
|
||||
{
|
||||
for (Entry<String, AssignedPermission> e : store.getAll().entrySet()) {
|
||||
if ((predicate == null) || predicate.test(e.getValue())) {
|
||||
permissions.add(new StoredAssignedPermission(e.getKey(), e.getValue()));
|
||||
}
|
||||
}
|
||||
@@ -225,25 +156,11 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
return permissions.build();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
private void assertHasPermission()
|
||||
{
|
||||
private void assertHasPermission() {
|
||||
PermissionPermissions.assign().check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param predicate
|
||||
*/
|
||||
private boolean deletePermissions(Predicate<AssignedPermission> predicate)
|
||||
{
|
||||
private boolean deletePermissions(Predicate<AssignedPermission> predicate) {
|
||||
List<Entry<String, AssignedPermission>> toRemove =
|
||||
store.getAll()
|
||||
.entrySet()
|
||||
@@ -253,23 +170,12 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
return !toRemove.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
* @param descriptorUrl
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<PermissionDescriptor> parsePermissionDescriptor(
|
||||
JAXBContext context, URL descriptorUrl)
|
||||
{
|
||||
JAXBContext context, URL descriptorUrl) {
|
||||
List<PermissionDescriptor> descriptors = Collections.EMPTY_LIST;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
PermissionDescriptors descriptorWrapper =
|
||||
(PermissionDescriptors) context.createUnmarshaller().unmarshal(
|
||||
descriptorUrl);
|
||||
@@ -279,26 +185,17 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
logger.debug("found {} permissions at {}", descriptors.size(),
|
||||
descriptorUrl);
|
||||
logger.trace("permissions from {}: {}", descriptorUrl, descriptors);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
} catch (JAXBException ex) {
|
||||
logger.error("could not parse permission descriptor", ex);
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
* @param pluginLoader
|
||||
*/
|
||||
private static ImmutableSet<PermissionDescriptor> readAvailablePermissions(PluginLoader pluginLoader)
|
||||
{
|
||||
private static ImmutableSet<PermissionDescriptor> readAvailablePermissions(PluginLoader pluginLoader) {
|
||||
ImmutableSet.Builder<PermissionDescriptor> builder = ImmutableSet.builder();
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
JAXBContext context =
|
||||
JAXBContext.newInstance(PermissionDescriptors.class);
|
||||
|
||||
@@ -306,21 +203,16 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
Enumeration<URL> descirptorEnum =
|
||||
pluginLoader.getUberClassLoader().getResources(PERMISSION_DESCRIPTOR);
|
||||
|
||||
while (descirptorEnum.hasMoreElements())
|
||||
{
|
||||
while (descirptorEnum.hasMoreElements()) {
|
||||
URL descriptorUrl = descirptorEnum.nextElement();
|
||||
|
||||
logger.debug("read permission descriptor from {}", descriptorUrl);
|
||||
|
||||
builder.addAll(parsePermissionDescriptor(context, descriptorUrl));
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
logger.error("could not read permission descriptors", ex);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
} catch (JAXBException ex) {
|
||||
logger.error(
|
||||
"could not create jaxb context to read permission descriptors", ex);
|
||||
}
|
||||
@@ -328,62 +220,34 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param perm
|
||||
*/
|
||||
private void validatePermission(AssignedPermission perm)
|
||||
{
|
||||
private void validatePermission(AssignedPermission perm) {
|
||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(perm.getName()),
|
||||
"name is required");
|
||||
Preconditions.checkArgument(!isNull(perm.getPermission()),
|
||||
"permission is required");
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Descriptor for permissions.
|
||||
*/
|
||||
@XmlRootElement(name = "permissions")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
private static class PermissionDescriptors
|
||||
{
|
||||
private static class PermissionDescriptors {
|
||||
|
||||
//~--- get methods --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<PermissionDescriptor> getPermissions()
|
||||
{
|
||||
if (permissions == null)
|
||||
{
|
||||
public List<PermissionDescriptor> getPermissions() {
|
||||
if (permissions == null) {
|
||||
permissions = Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
return permissions;
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "permission")
|
||||
private List<PermissionDescriptor> permissions;
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final ConfigurationEntryStore<AssignedPermission> store;
|
||||
|
||||
/** Field description */
|
||||
private final ImmutableSet<PermissionDescriptor> availablePermissions;
|
||||
}
|
||||
|
||||
@@ -21,29 +21,21 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.template;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.github.mustachejava.Mustache;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class MustacheTemplate implements Template
|
||||
{
|
||||
public class MustacheTemplate implements Template {
|
||||
|
||||
/**
|
||||
* the logger for MustacheTemplae
|
||||
@@ -51,50 +43,22 @@ public class MustacheTemplate implements Template
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(MustacheTemplate.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param templatePath
|
||||
* @param mustache
|
||||
*/
|
||||
public MustacheTemplate(String templatePath, Mustache mustache)
|
||||
{
|
||||
public MustacheTemplate(String templatePath, Mustache mustache) {
|
||||
this.templatePath = templatePath;
|
||||
this.mustache = mustache;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param writer
|
||||
* @param environment
|
||||
* @param model
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void execute(Writer writer, Object model) throws IOException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
public void execute(Writer writer, Object model) throws IOException {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("render mustache template at {}", templatePath);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
|
||||
mustache.execute(writer, model);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
} catch (Exception ex) {
|
||||
Throwables.propagateIfInstanceOf(ex, IOException.class);
|
||||
|
||||
throw new TemplateRenderException(
|
||||
@@ -102,11 +66,7 @@ public class MustacheTemplate implements Template
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Mustache mustache;
|
||||
|
||||
/** Field description */
|
||||
private String templatePath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user