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;
@AllPhotos
private Album allPhotos;
+ @Inject
+ @UserCache
+ private Cache<String, User> userCache;
+
+ @Inject
+ @PhotoCache
+ private Cache<String, ArrayList<PhotoEntry>> photoCache;
+
private Configuration getCOnfiguration() {
LOGGER.info("Initializing configuration");
Configuration config;
@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<String, User> 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<String, User> 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<String, ArrayList<PhotoEntry>> getPhotoCache() {
+ try {
+ InputResource cacheConfig = new ClassPathResource(
+ "META-INF/ehcache.xml");
+ return new EhCache<String, ArrayList<PhotoEntry>>(cacheConfig,
+ "photos");
+ } catch (IOException e) {
+ throw new RuntimeException("Could not create photo cache", e);
}
}
try {
File dir = new File(getCOnfiguration().getPath());
- InputResource cacheConfig = new ClassPathResource(
- "META-INF/ehcache.xml");
- Cache<String, ArrayList<PhotoEntry>> photoCache = new EhCache<String, ArrayList<PhotoEntry>>(
- cacheConfig, "photos");
Album fileSystemAlbum = new FileSystemAlbum(dir, "/", photoCache);
Album concurrentAlbum = new ConcurrentAlbum(fileSystemAlbum);
}
}
- @Produces
- @SessionScoped
- @AuthorizedPhotos
- public Album getAuthorizedAlbum() {
- LOGGER.info("Initializing authorized photos for current session");
- try {
- InputResource cacheConfig = new ClassPathResource(
- "META-INF/ehcache.xml");
- Cache<String, User> 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() {