X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fwamblee%2Fphotos%2Fmodel%2Fplumbing%2FProducer.java;h=a3d9c2a74f75525050cfc36887f674e36e4287b1;hb=be2dfde47261118e3f67f1c100bb935bc0a1b581;hp=4e5b1da7b6a2a1540c3fb9c11bab938993f0dd09;hpb=f3e05888d09a2d39375639b056d8e9093e00668b;p=photos diff --git a/src/main/java/org/wamblee/photos/model/plumbing/Producer.java b/src/main/java/org/wamblee/photos/model/plumbing/Producer.java index 4e5b1da..a3d9c2a 100644 --- a/src/main/java/org/wamblee/photos/model/plumbing/Producer.java +++ b/src/main/java/org/wamblee/photos/model/plumbing/Producer.java @@ -38,7 +38,6 @@ import org.wamblee.io.InputResource; import org.wamblee.photos.concurrent.ConcurrentAlbum; import org.wamblee.photos.model.Album; import org.wamblee.photos.model.PhotoEntry; -import org.wamblee.photos.model.authorization.AuthorizedAlbum; import org.wamblee.photos.model.filesystem.FileSystemAlbum; import org.wamblee.photos.security.PageAuthorizationRule; import org.wamblee.photos.security.PhotoAuthorizationRule; @@ -104,6 +103,14 @@ public class Producer { @AllPhotos private Album allPhotos; + @Inject + @UserCache + private Cache userCache; + + @Inject + @PhotoCache + private Cache> photoCache; + private Configuration getCOnfiguration() { LOGGER.info("Initializing configuration"); Configuration config; @@ -122,32 +129,51 @@ public class Producer { @ApplicationScoped public UserAdministration getUserAdmin() { LOGGER.info("Initializing user administration"); + NameValidator passwordvalidator = new RegexpNameValidator(".{5,}", + "INVALID_PASSWORD", "Password must have at least 5 characters"); + MessageDigester passwordEncoder = new Md5HexMessageDigester(); + UserSet userset = new JpaUserSet(userCache, passwordvalidator, + passwordEncoder, entityManager); + GroupSet groupset = new JpaGroupSet(entityManager); + NameValidator uservalidator = new RegexpNameValidator( + "[a-zA-Z]+[a-zA-Z0-9]*", "INVALID_USERNAME", + "User name must consist of alphanumeric characters only"); + NameValidator groupvalidator = new RegexpNameValidator( + "[a-zA-Z]+[a-zA-Z0-9]*", "INVALID_GROUPNAME", + "Group name must consist of alphanumeric characters only"); + + UserAdministration admin = new UserAdministrationImpl(userset, + groupset, uservalidator, groupvalidator); + UserAdminInitializer initializer = new UserAdminInitializer(admin, + new String[] { "erik", "admin" }, new String[] { "users", + "administrators" }, new String[] { "abc123", "abc123" }); + return admin; + } + + @Produces + @ApplicationScoped + @UserCache + public Cache getUserCache() { try { - NameValidator passwordvalidator = new RegexpNameValidator(".{5,}", - "INVALID_PASSWORD", "Password must have at least 5 characters"); InputResource cacheConfig = new ClassPathResource( "META-INF/ehcache.xml"); - Cache userCache = new EhCache(cacheConfig, "users"); - MessageDigester passwordEncoder = new Md5HexMessageDigester(); - UserSet userset = new JpaUserSet(userCache, passwordvalidator, - passwordEncoder, entityManager); - GroupSet groupset = new JpaGroupSet(entityManager); - NameValidator uservalidator = new RegexpNameValidator( - "[a-zA-Z]+[a-zA-Z0-9]*", "INVALID_USERNAME", - "User name must consist of alphanumeric characters only"); - NameValidator groupvalidator = new RegexpNameValidator( - "[a-zA-Z]+[a-zA-Z0-9]*", "INVALID_GROUPNAME", - "Group name must consist of alphanumeric characters only"); - - UserAdministration admin = new UserAdministrationImpl(userset, - groupset, uservalidator, groupvalidator); - UserAdminInitializer initializer = new UserAdminInitializer(admin, - new String[] { "erik", "admin" }, new String[] { "users", - "administrators" }, new String[] { "abc123", "abc123" }); - return admin; + return new EhCache(cacheConfig, "users"); } catch (IOException e) { - throw new RuntimeException( - "Could not initialize user administration", e); + throw new RuntimeException("Could not create user cache", e); + } + } + + @Produces + @ApplicationScoped + @PhotoCache + public Cache> getPhotoCache() { + try { + InputResource cacheConfig = new ClassPathResource( + "META-INF/ehcache.xml"); + return new EhCache>(cacheConfig, + "photos"); + } catch (IOException e) { + throw new RuntimeException("Could not create photo cache", e); } } @@ -200,10 +226,6 @@ public class Producer { try { File dir = new File(getCOnfiguration().getPath()); - InputResource cacheConfig = new ClassPathResource( - "META-INF/ehcache.xml"); - Cache> photoCache = new EhCache>( - cacheConfig, "photos"); Album fileSystemAlbum = new FileSystemAlbum(dir, "/", photoCache); Album concurrentAlbum = new ConcurrentAlbum(fileSystemAlbum); @@ -213,26 +235,6 @@ public class Producer { } } - @Produces - @SessionScoped - @AuthorizedPhotos - public Album getAuthorizedAlbum() { - LOGGER.info("Initializing authorized photos for current session"); - try { - InputResource cacheConfig = new ClassPathResource( - "META-INF/ehcache.xml"); - Cache userCache = new EhCache(cacheConfig, "users"); - Cache authorizedPhotoCache = new EhCache(cacheConfig, "photos"); - - AuthorizedAlbum album = new AuthorizedAlbum(allPhotos, - authorizationService, authorizedPhotoCache, session.getId()); - return album; - } catch (IOException e) { - throw new RuntimeException("Problem initializing authorized album", - e); - } - } - @Produces @SessionScoped public User getUser() {