├── .gitignore ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── bobko │ │ └── storage │ │ ├── common │ │ ├── Main.java │ │ ├── StorageConst.java │ │ ├── TestClass.java │ │ └── UserRolesTypes.java │ │ ├── component │ │ └── LogoutSuccessHandler.java │ │ ├── dao │ │ ├── ActivationTokenDao.java │ │ ├── PageHolderDao.java │ │ ├── PictureDao.java │ │ ├── UserDao.java │ │ ├── base │ │ │ ├── HibernateDao.java │ │ │ └── IGenericDao.java │ │ └── interfaces │ │ │ ├── IActivationTokenDao.java │ │ │ ├── IPagesHolderDao.java │ │ │ ├── IPictureDao.java │ │ │ └── IUserDao.java │ │ ├── domain │ │ ├── ActivationToken.java │ │ ├── Document.java │ │ ├── IncomingURL.java │ │ ├── StoragePage.java │ │ ├── Topic.java │ │ └── UserEntity.java │ │ ├── events │ │ ├── OnPasswordResetEvent.java │ │ └── OnRegistrationInitiatedEvent.java │ │ ├── exceptions │ │ ├── TokenExpiredException.java │ │ ├── TokenVerifyedException.java │ │ ├── UserActivationException.java │ │ └── UserNotFoundException.java │ │ ├── init │ │ └── WebStorageInitializer.java │ │ ├── listeners │ │ ├── RegistrationInitiateListener.java │ │ └── ResetPasswordListener.java │ │ ├── service │ │ ├── MailService.java │ │ ├── PagesService.java │ │ ├── PictureGrabber.java │ │ ├── PictureService.java │ │ ├── StorageUserDetailsService.java │ │ ├── UserService.java │ │ └── interfaces │ │ │ ├── IMailService.java │ │ │ ├── IPagesService.java │ │ │ ├── IPictureGrabber.java │ │ │ ├── IPictureService.java │ │ │ └── IUserService.java │ │ ├── util │ │ └── AlbumUtils.java │ │ └── web │ │ ├── DataController.java │ │ ├── ErrorController.java │ │ ├── MainController.java │ │ ├── MainRestController.java │ │ ├── RegistrationController.java │ │ └── UploadController.java ├── resources │ ├── create-storage-schema.sql │ ├── log4j2.xml │ ├── messages_en.properties │ └── messages_ru.properties └── webapp │ ├── WEB-INF │ ├── config │ │ ├── email.xml │ │ ├── persistence.xml │ │ ├── root-context.xml │ │ ├── security.xml │ │ ├── servlet-context.xml │ │ └── tiles.xml │ ├── jsp │ │ ├── anonymous │ │ │ ├── error.jsp │ │ │ ├── footer.jsp │ │ │ ├── header.jsp │ │ │ ├── login.jsp │ │ │ ├── main.jsp │ │ │ ├── new-password.jsp │ │ │ ├── pagenation.jsp │ │ │ ├── pictures.jsp │ │ │ ├── registration-page.jsp │ │ │ ├── reset-password.jsp │ │ │ └── thankyou.jsp │ │ ├── common │ │ │ └── layout.jsp │ │ └── user │ │ │ └── upload-file.jsp │ └── web.xml │ └── resources │ ├── css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.css.map │ ├── bootstrap-theme.min.css │ ├── bootstrap.css │ ├── bootstrap.css.map │ ├── bootstrap.min.css │ ├── default.css │ ├── social-sharing.css │ └── sticky-footer-navbar.css │ ├── favicon.ico │ ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 │ ├── images │ ├── canvas.png │ ├── close.png │ ├── closeX.png │ ├── close_img.png │ ├── controlbar-black-border.gif │ ├── controlbar-text-buttons.png │ ├── controlbar-white-small.gif │ ├── controlbar-white.gif │ ├── controlbar2.gif │ ├── controlbar3.gif │ ├── controlbar4-hover.gif │ ├── controlbar4.gif │ ├── fullexpand.gif │ ├── geckodimmer.png │ ├── icon-remove.gif │ ├── icon.gif │ ├── loader.gif │ ├── loader.white.gif │ ├── logo.jpg │ ├── outlines │ │ ├── beveled.png │ │ ├── drop-shadow.png │ │ ├── glossy-dark.png │ │ ├── outer-glow.png │ │ ├── rounded-black.png │ │ └── rounded-white.png │ ├── resize.gif │ ├── scrollarrows.png │ ├── zoomin.cur │ └── zoomout.cur │ ├── js │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── default.js │ ├── highslide-with-gallery.js │ ├── highslide-with-gallery.min.js │ └── highslide-with-gallery.packed.js │ └── style │ ├── highslide.css │ └── style.css └── test ├── java └── com │ └── bobko │ └── storage │ ├── dao │ ├── PageHolderDaoTest.java │ ├── PictureDAOTest.java │ └── UserDAOTest.java │ ├── service │ ├── PagesServiceTest.java │ └── test │ │ ├── PictureServiceTest.java │ │ ├── UserDetailsServiceTest.java │ │ └── UserServiceTest.java │ └── web │ ├── RegistrationControllerTest.java │ └── UploadControllerTest.java └── resources ├── application-context.xml ├── log4j.xml └── test-context.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.settings 3 | .classpath 4 | .project 5 | *.orig 6 | src/main/resources/log4j.xml 7 | src/main/resources/jdbc.properties 8 | src/main/resources/email.properties 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | web-storage 2 | ===== 3 | 4 | Spring MVC + Security + Apache tiles. 5 | 6 | Twitter bootstrap + JQuery 7 | 8 | Generic dao + Hibernate + c3p0 9 | 10 | JUnit Mockito testing. 11 | 12 | http://tomcat-bobkofiles.rhcloud.com 13 | 14 | do not forget to add jdbc.properties file into classpath 15 | 16 | example: 17 | ``` 18 | jdbc.driverClassName=com.mysql.jdbc.Driver 19 | jdbc.url=jdbc:mysql://127.0.0.1:3306/album 20 | jdbc.username=root 21 | jdbc.password=root 22 | c3p0.acquireIncrement = 3 23 | c3p0.minPoolSize = 5 24 | c3p0.maxPoolSize = 20 25 | c3p0.maxIdleTime = 3600 26 | hibernate.show_sql = true 27 | hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 28 | hibernate.format_sql = true 29 | hibernate.use_sql_comments = true 30 | hibernate.auto_close_session = true 31 | 32 | data.root.path=/home/oleksii/pictures/ 33 | pagination.page.size=3 34 | ``` 35 | email.properties file 36 | 37 | ``` 38 | email.host=smtp.gmail.com 39 | email.port=587 40 | email.username=your_nameo@gmail.com 41 | email.password=secret 42 | ``` 43 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.bobko 5 | web-storage 6 | web-storage 7 | war 8 | 1.0.2-BUILD-SNAPSHOT 9 | 10 | 1.8 11 | 1.6.9 12 | 1.5.10 13 | 4.3.2.RELEASE 14 | 4.1.3.RELEASE 15 | 16 | 17 | 18 | javax.mail 19 | mail 20 | 1.4 21 | 22 | 23 | 24 | org.springframework 25 | spring-context 26 | ${org.springframework-version} 27 | 28 | 29 | commons-logging 30 | commons-logging 31 | 32 | 33 | 34 | 35 | org.springframework 36 | spring-webmvc 37 | ${org.springframework-version} 38 | 39 | 40 | 41 | org.springframework 42 | spring-orm 43 | ${org.springframework-version} 44 | 45 | 46 | 47 | org.springframework.security 48 | spring-security-web 49 | ${org.spring-security-version} 50 | 51 | 52 | spring-aop 53 | org.springframework 54 | 55 | 56 | 57 | 58 | org.springframework.security 59 | spring-security-config 60 | ${org.spring-security-version} 61 | 62 | 63 | spring-aop 64 | org.springframework 65 | 66 | 67 | 68 | 69 | org.springframework.security 70 | spring-security-core 71 | ${org.spring-security-version} 72 | 73 | 74 | spring-aop 75 | org.springframework 76 | 77 | 78 | 79 | 80 | 81 | org.springframework.security 82 | spring-security-taglibs 83 | ${org.spring-security-version} 84 | 85 | 86 | spring-aop 87 | org.springframework 88 | 89 | 90 | 91 | 92 | org.springframework 93 | spring-context-support 94 | 4.1.5.RELEASE 95 | 96 | 97 | org.springframework 98 | spring-jdbc 99 | ${org.springframework-version} 100 | 101 | 102 | 103 | 104 | org.hibernate 105 | hibernate-core 106 | 4.0.1.Final 107 | 108 | 109 | org.hibernate 110 | hibernate-validator 111 | 4.2.0.Final 112 | 113 | 114 | org.hibernate.common 115 | hibernate-commons-annotations 116 | 4.0.1.Final 117 | tests 118 | 119 | 120 | org.hibernate.javax.persistence 121 | hibernate-jpa-2.0-api 122 | 1.0.1.Final 123 | 124 | 125 | org.hibernate 126 | hibernate-entitymanager 127 | 4.0.1.Final 128 | 129 | 130 | mysql 131 | mysql-connector-java 132 | 5.1.26 133 | 134 | 135 | 136 | 137 | c3p0 138 | c3p0 139 | 0.9.1.2 140 | 141 | 142 | 143 | org.aspectj 144 | aspectjrt 145 | 1.7.3 146 | 147 | 148 | 149 | org.apache.logging.log4j 150 | log4j-api 151 | 2.6.2 152 | 153 | 154 | org.apache.logging.log4j 155 | log4j-core 156 | 2.6.2 157 | 158 | 159 | 160 | org.slf4j 161 | slf4j-simple 162 | 1.6.2 163 | 164 | 165 | 166 | 167 | javax.servlet 168 | javax.servlet-api 169 | 3.0.1 170 | provided 171 | 172 | 173 | javax.servlet.jsp 174 | jsp-api 175 | 2.1 176 | provided 177 | 178 | 179 | javax.servlet 180 | jstl 181 | 1.2 182 | 183 | 184 | commons-fileupload 185 | commons-fileupload 186 | 1.2 187 | 188 | 189 | 190 | commons-io 191 | commons-io 192 | 2.4 193 | 194 | 195 | 196 | junit 197 | junit 198 | 4.12 199 | test 200 | 201 | 202 | org.mockito 203 | mockito-all 204 | 1.9.5 205 | test 206 | 207 | 208 | 209 | org.springframework 210 | spring-test 211 | 3.2.3.RELEASE 212 | provided 213 | 214 | 215 | 216 | taglibs 217 | standard 218 | 1.1.2 219 | 220 | 221 | javax.validation 222 | validation-api 223 | 1.0.0.GA 224 | 225 | 226 | org.hibernate 227 | hibernate-validator 228 | 4.3.0.Final 229 | 230 | 231 | org.apache.tiles 232 | tiles-core 233 | 3.0.7 234 | 235 | 236 | org.apache.tiles 237 | tiles-jsp 238 | 3.0.7 239 | 240 | 241 | 242 | 243 | 244 | org.apache.maven.plugins 245 | maven-compiler-plugin 246 | 247 | ${java-version} 248 | ${java-version} 249 | 250 | 251 | 252 | org.apache.maven.plugins 253 | maven-war-plugin 254 | 255 | web-storage 256 | 257 | 258 | 259 | org.apache.maven.plugins 260 | maven-dependency-plugin 261 | 262 | 263 | install 264 | install 265 | 266 | sources 267 | 268 | 269 | 270 | 271 | 272 | 273 | http://tomcat-bobkofiles.rhcloud.com/ 274 | 275 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/common/Main.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.common; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) throws InterruptedException { 8 | String regex = "^(?!\\.)([a-zA-Z0-9-_\\.!?*+]*)@([a-zA-Z0-9-_\\.!?*+]*)$"; 9 | String regex133 = "rx1"; 10 | boolean b = Pattern.matches(regex, "ole..ksii.bobko@somemail.org.kz"); 11 | System.err.println(b); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/common/StorageConst.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.common; 2 | 3 | public class StorageConst { 4 | 5 | public static final int MAX_DESCRIPTION_SIZE = 100; 6 | 7 | /** 8 | * value PICTURE_COUNT define number of pictures per one page 9 | * */ 10 | public static final int PICTURE_COUNT = 15; 11 | /** 12 | * value MAX_PAGES_COUNT define max number of pages link on pagination 13 | * */ 14 | public static final int MAX_PAGES_COUNT = 2; 15 | 16 | private StorageConst() { 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/common/TestClass.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.common; 2 | 3 | /** 4 | * @author Oleksii_Bobko 5 | * @date Jan 23, 2015 6 | * @time 5:38:50 PM 7 | */ 8 | public class TestClass { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/common/UserRolesTypes.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * */ 4 | package com.bobko.storage.common; 5 | 6 | public enum UserRolesTypes { 7 | 8 | ROLE_ADMIN("ROLE_ADMIN"), 9 | ROLE_USER("ROLE_USER") { 10 | @Override 11 | public String getValue() { 12 | return "ROLE_USER"; 13 | } 14 | }, 15 | ROLE_ANONYMOUS("ROLE_ANONYMOUS"); 16 | 17 | private String value; 18 | 19 | private UserRolesTypes(String value) { 20 | this.value = value; 21 | } 22 | 23 | public String getValue() { 24 | return value; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/component/LogoutSuccessHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * */ 4 | package com.bobko.storage.component; 5 | 6 | /** 7 | * This class provides logout event handling and redirect page to login page 8 | * @author oleksii bobko 9 | * @data 12.08.2013 10 | * @see SimpleUrlLogoutSuccessHandler 11 | */ 12 | 13 | import java.io.IOException; 14 | 15 | import javax.servlet.ServletException; 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | 19 | import org.apache.logging.log4j.LogManager; 20 | import org.apache.logging.log4j.Logger; 21 | import org.springframework.security.core.Authentication; 22 | import org.springframework.security.web.authentication.logout. 23 | SimpleUrlLogoutSuccessHandler; 24 | import org.springframework.stereotype.Component; 25 | 26 | /** 27 | * 28 | * */ 29 | @Component 30 | public class LogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler { 31 | 32 | private static final Logger LOGGER = LogManager.getLogger(LogoutSuccessHandler.class); 33 | 34 | public LogoutSuccessHandler() { 35 | LOGGER.info("instantiated"); 36 | } 37 | 38 | @Override 39 | public void onLogoutSuccess(HttpServletRequest request, 40 | final HttpServletResponse response, Authentication authentication) 41 | throws IOException, ServletException { 42 | 43 | if (authentication != null) { 44 | authentication.getName(); 45 | } 46 | 47 | setDefaultTargetUrl("/"); 48 | super.onLogoutSuccess(request, response, authentication); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/ActivationTokenDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | * @see UserDAO 7 | */ 8 | 9 | import org.springframework.stereotype.Repository; 10 | 11 | import com.bobko.storage.dao.base.HibernateDao; 12 | import com.bobko.storage.dao.interfaces.IActivationTokenDao; 13 | import com.bobko.storage.domain.ActivationToken; 14 | 15 | @Repository 16 | public class ActivationTokenDao extends HibernateDao 17 | implements IActivationTokenDao {} 18 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/PageHolderDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao; 2 | 3 | /** 4 | * Contains list with AlbumPage. Provide navigation and pagination. 5 | * 6 | * @author oleksii bobko 7 | * @data 12.08.2013 8 | * @see AlbumPagesHolderDAO 9 | * @see AlbumPage 10 | */ 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import org.hibernate.Session; 16 | import org.hibernate.SessionFactory; 17 | import org.hibernate.criterion.Projections; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.stereotype.Repository; 20 | 21 | import com.bobko.storage.common.StorageConst; 22 | import com.bobko.storage.dao.interfaces.IPagesHolderDao; 23 | import com.bobko.storage.domain.StoragePage; 24 | import com.bobko.storage.domain.Document; 25 | 26 | @Repository 27 | public class PageHolderDao implements IPagesHolderDao { 28 | 29 | private int shift = 0; 30 | private int pagesCount = 0; 31 | private int rowCount = 1; 32 | 33 | @Autowired 34 | private SessionFactory sessionFactory; 35 | 36 | @Override 37 | public List list() { 38 | return createPagesList(); 39 | } 40 | 41 | /** 42 | * @return List of AlbumPage 43 | * */ 44 | private List createPagesList() { 45 | Session session = sessionFactory.getCurrentSession(); 46 | Number num = ((Number) session.createCriteria(Document.class).setProjection(Projections.rowCount()).uniqueResult()); 47 | if(num != null) { 48 | rowCount = num.intValue(); 49 | } 50 | 51 | pagesCount = ((int) Math.ceil(rowCount / (double) StorageConst.PICTURE_COUNT)) - 1; 52 | 53 | int finalCount = pagesCount; 54 | 55 | List pages = new ArrayList(); 56 | 57 | if (pagesCount > StorageConst.MAX_PAGES_COUNT) { 58 | finalCount = StorageConst.MAX_PAGES_COUNT; 59 | } 60 | 61 | for (int i = 0; i <= finalCount; i++) { 62 | if ((shift + i) > pagesCount) { 63 | break; 64 | } 65 | if (i == 0) { 66 | pages.add(new StoragePage(shift + i, true)); 67 | } else { 68 | pages.add(new StoragePage(shift + i, false)); 69 | } 70 | } 71 | return pages; 72 | } 73 | 74 | @Override 75 | public int getShift() { 76 | return shift; 77 | } 78 | 79 | @Override 80 | public void setShift(int index) { 81 | shift = index; 82 | } 83 | 84 | @Override 85 | public void nextPage() { 86 | if (shift < pagesCount) { 87 | shift++; 88 | } else { 89 | shift = pagesCount; 90 | } 91 | } 92 | 93 | @Override 94 | public void prevPage() { 95 | shift--; 96 | if (shift < 0) { 97 | shift = 0; 98 | } 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/PictureDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | * @see PictureDAO 7 | */ 8 | 9 | import org.springframework.stereotype.Repository; 10 | 11 | import com.bobko.storage.dao.base.HibernateDao; 12 | import com.bobko.storage.dao.interfaces.IPictureDao; 13 | import com.bobko.storage.domain.Document; 14 | 15 | @Repository 16 | public class PictureDao extends HibernateDao implements 17 | IPictureDao { 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | * @see UserDAO 7 | */ 8 | 9 | import org.springframework.stereotype.Repository; 10 | 11 | import com.bobko.storage.dao.base.HibernateDao; 12 | import com.bobko.storage.dao.interfaces.IUserDao; 13 | import com.bobko.storage.domain.UserEntity; 14 | 15 | @Repository 16 | public class UserDao extends HibernateDao implements IUserDao {} 17 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/base/HibernateDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao.base; 2 | 3 | import java.io.Serializable; 4 | import java.lang.reflect.ParameterizedType; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import org.hibernate.Criteria; 11 | import org.hibernate.Session; 12 | import org.hibernate.SessionFactory; 13 | import org.hibernate.criterion.Order; 14 | import org.hibernate.criterion.Restrictions; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.transaction.annotation.Propagation; 17 | import org.springframework.transaction.annotation.Transactional; 18 | 19 | /** 20 | * Basic DAO operations dependent with Hibernate's specific classes 21 | * 22 | * @see SessionFactory 23 | */ 24 | @Transactional(propagation = Propagation.REQUIRED, readOnly = false) 25 | public class HibernateDao implements 26 | IGenericDao { 27 | 28 | private static final Logger LOGGER = LogManager.getLogger(HibernateDao.class); 29 | 30 | @Autowired 31 | private SessionFactory sessionFactory; 32 | 33 | protected Class daoType; 34 | 35 | @SuppressWarnings("unchecked") 36 | public HibernateDao() { 37 | daoType = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; 38 | } 39 | 40 | @Autowired 41 | public void setSessionFactory(SessionFactory sessionFactory) { 42 | this.sessionFactory = sessionFactory; 43 | } 44 | 45 | protected Session currentSession() { 46 | return sessionFactory.getCurrentSession(); 47 | } 48 | 49 | @Override 50 | public void add(E entity) { 51 | currentSession().save(entity); 52 | } 53 | 54 | @Override 55 | public void update(E entity) { 56 | currentSession().saveOrUpdate(entity); 57 | } 58 | 59 | @Override 60 | public void remove(E entity) { 61 | currentSession().delete(entity); 62 | } 63 | 64 | @SuppressWarnings("unchecked") 65 | @Override 66 | public E find(K key) { 67 | return (E) currentSession().get(daoType, key); 68 | } 69 | 70 | @SuppressWarnings("unchecked") 71 | @Override 72 | public List list() { 73 | return currentSession().createCriteria(daoType).list(); 74 | } 75 | 76 | @SuppressWarnings("unchecked") 77 | @Override 78 | public List rankList(int shift, int count) { 79 | Criteria criteria = currentSession().createCriteria(daoType); 80 | criteria.setFirstResult(shift * count); 81 | criteria.setMaxResults(count); 82 | criteria.addOrder(Order.desc("id")); 83 | return criteria.list(); 84 | } 85 | 86 | @SuppressWarnings("unchecked") 87 | @Override 88 | public List getByField(String field, String value) { 89 | 90 | List result = new ArrayList(); 91 | 92 | try { 93 | Criteria criteria = currentSession().createCriteria(daoType); 94 | criteria.add(Restrictions.eq(field, value)); 95 | result = criteria.list(); 96 | } catch (Exception e) { 97 | LOGGER.error(e); 98 | } 99 | 100 | return result; 101 | 102 | } 103 | 104 | } -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/base/IGenericDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao.base; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public interface IGenericDao { 7 | 8 | public void add(T entity); 9 | 10 | public void update(T entity); 11 | 12 | public void remove(T entity); 13 | 14 | public T find(PK key); 15 | 16 | public List list(); 17 | 18 | public List rankList(int shift, int count); 19 | 20 | public List getByField(String field, String value); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/interfaces/IActivationTokenDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao.interfaces; 2 | 3 | import com.bobko.storage.dao.base.IGenericDao; 4 | import com.bobko.storage.domain.ActivationToken; 5 | 6 | public interface IActivationTokenDao extends IGenericDao {} 7 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/interfaces/IPagesHolderDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao.interfaces; 2 | 3 | /** 4 | * Interface that provides navigation and pagination 5 | * 6 | * @author oleksii bobko 7 | * @data 12.08.2013 8 | * @see AlbumPagesHolderDAO 9 | * @see AlbumPage 10 | */ 11 | 12 | import java.util.List; 13 | 14 | import com.bobko.storage.domain.StoragePage; 15 | 16 | public interface IPagesHolderDao { 17 | 18 | /** 19 | * @return List of pages that provides handling active page and count of pages 20 | * */ 21 | public List list(); 22 | 23 | /** 24 | * @return absolute number of current page 25 | * */ 26 | public int getShift(); 27 | 28 | /** 29 | * This method sets currently active page 30 | * */ 31 | public void setShift(int index); 32 | 33 | /** 34 | * This method provide one move to next page 35 | * */ 36 | public void nextPage(); 37 | 38 | /** 39 | * This method provide one move to previous page 40 | * */ 41 | public void prevPage(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/interfaces/IPictureDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao.interfaces; 2 | 3 | import java.util.List; 4 | 5 | public interface IPictureDao { 6 | 7 | public void add(E entity); 8 | 9 | public void update(E entity); 10 | 11 | public void remove(E entity); 12 | 13 | public E find(K key); 14 | 15 | public List list(); 16 | 17 | public List rankList(int shift, int count); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/dao/interfaces/IUserDao.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao.interfaces; 2 | 3 | import com.bobko.storage.dao.base.IGenericDao; 4 | import com.bobko.storage.domain.UserEntity; 5 | 6 | public interface IUserDao extends IGenericDao { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/domain/ActivationToken.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.domain; 2 | 3 | import java.sql.Timestamp; 4 | import java.util.Calendar; 5 | 6 | import javax.persistence.CascadeType; 7 | import javax.persistence.Column; 8 | import javax.persistence.Entity; 9 | import javax.persistence.GeneratedValue; 10 | import javax.persistence.Id; 11 | import javax.persistence.OneToOne; 12 | import javax.persistence.PrimaryKeyJoinColumn; 13 | import javax.persistence.Table; 14 | 15 | import org.hibernate.annotations.GenericGenerator; 16 | import org.hibernate.annotations.Parameter; 17 | import org.hibernate.annotations.Type; 18 | 19 | import com.bobko.storage.util.AlbumUtils; 20 | 21 | @Entity 22 | @Table(name = "activation_token") 23 | public class ActivationToken { 24 | private static final int EXPIRATION = 60 * 24; 25 | 26 | @Id 27 | @Column(name="token_id", unique=true, nullable=false) 28 | @GeneratedValue(generator="gen") 29 | @GenericGenerator(name="gen", strategy="foreign", parameters=@Parameter(name="property", value="user")) 30 | private int id; 31 | 32 | @Column(name="token") 33 | private String token; 34 | 35 | @OneToOne(cascade = CascadeType.ALL) 36 | @PrimaryKeyJoinColumn 37 | private UserEntity user; 38 | 39 | @Column(name="expire") 40 | @Type(type="timestamp") 41 | private Timestamp expire; 42 | 43 | @Column(name="verified") 44 | private boolean verified; 45 | 46 | public ActivationToken() { 47 | super(); 48 | } 49 | 50 | public ActivationToken(UserEntity user) { 51 | super(); 52 | this.token = AlbumUtils.getUUID(); 53 | this.user = user; 54 | this.expire = calculateExpiryDate(EXPIRATION); 55 | this.verified = false; 56 | } 57 | 58 | private Timestamp calculateExpiryDate(int expiryTimeInMinutes) { 59 | Calendar cal = Calendar.getInstance(); 60 | cal.setTime(new Timestamp(cal.getTime().getTime())); 61 | cal.add(Calendar.MINUTE, expiryTimeInMinutes); 62 | return new Timestamp(cal.getTime().getTime()); 63 | } 64 | 65 | public int getId() { 66 | return id; 67 | } 68 | public void setId(int id) { 69 | this.id = id; 70 | } 71 | public String getToken() { 72 | return token; 73 | } 74 | public void setToken(String token) { 75 | this.token = token; 76 | } 77 | public UserEntity getUser() { 78 | return user; 79 | } 80 | public void setUser(UserEntity user) { 81 | this.user = user; 82 | } 83 | public boolean isVerified() { 84 | return verified; 85 | } 86 | public void setVerified(boolean verified) { 87 | this.verified = verified; 88 | } 89 | 90 | public Timestamp getExpire() { 91 | return expire; 92 | } 93 | 94 | public void setExpire(Timestamp expire) { 95 | this.expire = expire; 96 | } 97 | 98 | public boolean isExpired() { 99 | long current = System.currentTimeMillis(); 100 | long expiration = expire.getTime(); 101 | return current > expiration; 102 | } 103 | 104 | public void reset() { 105 | this.expire = calculateExpiryDate(EXPIRATION); 106 | this.verified = false; 107 | this.token = AlbumUtils.getUUID(); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/domain/Document.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.domain; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | */ 7 | 8 | import java.sql.Timestamp; 9 | 10 | import javax.persistence.Column; 11 | import javax.persistence.Entity; 12 | import javax.persistence.GeneratedValue; 13 | import javax.persistence.Id; 14 | import javax.persistence.JoinColumn; 15 | import javax.persistence.ManyToOne; 16 | import javax.persistence.Table; 17 | import javax.validation.constraints.NotNull; 18 | 19 | import org.hibernate.annotations.Type; 20 | import org.hibernate.validator.constraints.NotEmpty; 21 | 22 | @Entity 23 | @Table(name="documents") 24 | public class Document { 25 | 26 | @Column(name="id") 27 | @Id 28 | @GeneratedValue 29 | private Integer id; 30 | 31 | @Column(name="pic_owner") 32 | private String owner; 33 | 34 | @NotNull 35 | @NotEmpty 36 | @Column(name="filename") 37 | private String filename; 38 | 39 | @Column(name="description") 40 | private String description; 41 | 42 | @Column(name="path") 43 | private String path; 44 | 45 | @Column(name="created") 46 | @Type(type="timestamp") 47 | private Timestamp created; 48 | 49 | @Column(name="thumbnail") 50 | private String thumbnail; 51 | 52 | @ManyToOne 53 | @JoinColumn(name = "userid") 54 | private UserEntity user; 55 | 56 | private boolean canDelete; 57 | 58 | public boolean isCanDelete() { 59 | return canDelete; 60 | } 61 | 62 | public void setCanDelete(boolean canDelete) { 63 | this.canDelete = canDelete; 64 | } 65 | 66 | public UserEntity getUser() { 67 | return this.user; 68 | } 69 | 70 | public void setUser(UserEntity user) { 71 | this.user = user; 72 | } 73 | 74 | public Timestamp getCreated() { 75 | return created; 76 | } 77 | 78 | public void setCreated(Timestamp created) { 79 | this.created = created; 80 | } 81 | 82 | public String getThumbnail() { 83 | return thumbnail; 84 | } 85 | 86 | public void setThumbnail(String thumbnail) { 87 | this.thumbnail = thumbnail; 88 | } 89 | 90 | public Integer getId() { 91 | return id; 92 | } 93 | 94 | public void setId(Integer id) { 95 | this.id = id; 96 | } 97 | 98 | public String getOwner() { 99 | return owner; 100 | } 101 | 102 | public void setOwner(String owner) { 103 | this.owner = owner; 104 | } 105 | 106 | public String getDescription() { 107 | return description; 108 | } 109 | 110 | public void setDescription(String description) { 111 | this.description = description; 112 | } 113 | 114 | public String getFilename() { 115 | return filename; 116 | } 117 | 118 | public void setFilename(String filename) { 119 | this.filename = filename; 120 | } 121 | 122 | public String getPath() { 123 | return path; 124 | } 125 | 126 | public void setPath(String path) { 127 | this.path = path; 128 | } 129 | 130 | public String getThumbPath() { 131 | return path; 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/domain/IncomingURL.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.domain; 2 | 3 | /** 4 | * Provides URL to web-site that will be grabbed 5 | * 6 | * @author oleksii bobko 7 | * @data 12.08.2013 8 | */ 9 | 10 | public class IncomingURL { 11 | 12 | private String url; 13 | 14 | public String getURL() { 15 | return url; 16 | } 17 | 18 | public void setURL(String url) { 19 | this.url= url; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/domain/StoragePage.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.domain; 2 | 3 | /** 4 | * Class that provides all properties to each page of PhotoAlbum 5 | * 6 | * @author oleksii bobko 7 | * @data 12.08.2013 8 | */ 9 | 10 | public class StoragePage { 11 | 12 | /** 13 | * index is the position number of page 14 | * */ 15 | private int index; 16 | 17 | /** 18 | * isActive = true when page is active. and vice versa 19 | * */ 20 | private boolean isActive; 21 | 22 | public StoragePage(int index, boolean isActive) { 23 | this.index = index; 24 | this.isActive = isActive; 25 | } 26 | 27 | public int getIndex() { 28 | return index; 29 | } 30 | public void setIndex(int index) { 31 | this.index = index; 32 | } 33 | public boolean isActive() { 34 | return isActive; 35 | } 36 | public void setActive(boolean isActive) { 37 | this.isActive = isActive; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/domain/Topic.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.domain; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | import javax.persistence.JoinColumn; 7 | import javax.persistence.ManyToOne; 8 | 9 | /** 10 | * Associated with any topic on the site 11 | * 12 | * @author oleksii bobko 13 | * @data 08.02.2016 14 | */ 15 | 16 | //@Entity 17 | //@Table(name = "topics") 18 | public class Topic { 19 | 20 | @Id 21 | @GeneratedValue 22 | @Column(name="id") 23 | private int id; 24 | 25 | @Column(name="title") 26 | private String title; 27 | 28 | @Column(name="front_image") 29 | private Document frontImage; 30 | 31 | @Column(name="tags") 32 | private String tags; 33 | 34 | @Column(name="rate") 35 | private int rate; 36 | 37 | @ManyToOne 38 | @JoinColumn(name = "userid") 39 | private UserEntity user; 40 | 41 | public String getTitle() { 42 | return title; 43 | } 44 | 45 | public void setTitle(String title) { 46 | this.title = title; 47 | } 48 | 49 | public Document getFrontImage() { 50 | return frontImage; 51 | } 52 | 53 | public void setFrontImage(Document frontImage) { 54 | this.frontImage = frontImage; 55 | } 56 | 57 | public String getTags() { 58 | return tags; 59 | } 60 | 61 | public void setTags(String tags) { 62 | this.tags = tags; 63 | } 64 | 65 | public int getRate() { 66 | return rate; 67 | } 68 | 69 | public void setRate(int rate) { 70 | this.rate = rate; 71 | } 72 | 73 | public UserEntity getUser() { 74 | return user; 75 | } 76 | 77 | public void setUser(UserEntity user) { 78 | this.user = user; 79 | } 80 | 81 | public int getId() { 82 | return id; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/domain/UserEntity.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.domain; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | */ 7 | 8 | 9 | import java.util.ArrayList; 10 | import java.util.HashSet; 11 | import java.util.List; 12 | import java.util.Set; 13 | 14 | import javax.persistence.CascadeType; 15 | import javax.persistence.Column; 16 | import javax.persistence.Entity; 17 | import javax.persistence.GeneratedValue; 18 | import javax.persistence.Id; 19 | import javax.persistence.JoinColumn; 20 | import javax.persistence.OneToMany; 21 | import javax.persistence.OneToOne; 22 | import javax.persistence.Table; 23 | import javax.validation.constraints.Size; 24 | 25 | import org.hibernate.validator.constraints.Email; 26 | import org.springframework.security.core.GrantedAuthority; 27 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 28 | 29 | 30 | @Entity 31 | @Table(name = "users") 32 | public class UserEntity { 33 | 34 | @Id 35 | @GeneratedValue 36 | @Column(name="id") 37 | private int id; 38 | 39 | @Size(min = 5, max = 32, message = "The login must be at least 5 characters long.") 40 | @Column(name = "login") 41 | private String login; 42 | 43 | @Size(max = 32, message = "First name is too long.") 44 | @Column(name = "first_name") 45 | private String firstName; 46 | 47 | @Size(max = 32, message = "Last name is too long.") 48 | @Column(name = "last_name") 49 | private String lastName; 50 | 51 | @Email(regexp="^((?!\\.).*)@(.*)$", message = "Incorrect email format") 52 | @Column(name = "email") 53 | private String email; 54 | 55 | @Column(name = "pass") 56 | private String pw; 57 | 58 | private String pwConfirmation; 59 | 60 | @Column(name = "role") 61 | private String role; 62 | 63 | @Column(name = "active") 64 | private boolean active; 65 | 66 | @OneToMany(targetEntity = Document.class, mappedBy = "user") 67 | private List pictures; 68 | 69 | @OneToOne(mappedBy="user", cascade=CascadeType.ALL) 70 | @JoinColumn(nullable = false, name = "id") 71 | private ActivationToken token; 72 | 73 | public int getId() { 74 | return id; 75 | } 76 | 77 | public void setId(Integer id) { 78 | this.id = id; 79 | } 80 | 81 | public String getLogin() { 82 | return login; 83 | } 84 | 85 | public void setLogin(String login) { 86 | this.login = login; 87 | } 88 | 89 | public String getEmail() { 90 | return email; 91 | } 92 | 93 | public void setEmail(String email) { 94 | this.email = email; 95 | } 96 | 97 | public String getPw() { 98 | return pw; 99 | } 100 | 101 | public void setPw(String pw) { 102 | this.pw = pw; 103 | } 104 | 105 | public String getRole() { 106 | return role; 107 | } 108 | 109 | public boolean isActive() { 110 | return active; 111 | } 112 | 113 | public void setActive(boolean active) { 114 | this.active = active; 115 | } 116 | 117 | public void setRole(String role) { 118 | this.role = role; 119 | } 120 | 121 | public List getPictures() { 122 | return pictures; 123 | } 124 | 125 | public String getFirstName() { 126 | return firstName; 127 | } 128 | 129 | public String getLastName() { 130 | return lastName; 131 | } 132 | 133 | public String getPwConfirmation() { 134 | return pwConfirmation; 135 | } 136 | 137 | public ActivationToken getToken() { 138 | return token; 139 | } 140 | 141 | public void setToken(ActivationToken token) { 142 | this.token = token; 143 | } 144 | 145 | public void setId(int id) { 146 | this.id = id; 147 | } 148 | 149 | public void setFirstName(String firstName) { 150 | this.firstName = firstName; 151 | } 152 | 153 | public void setLastName(String lastName) { 154 | this.lastName = lastName; 155 | } 156 | 157 | public void setPwConfirmation(String pwConfirmation) { 158 | this.pwConfirmation = pwConfirmation; 159 | } 160 | 161 | public void setPictures(List pictures) { 162 | this.pictures = pictures; 163 | } 164 | 165 | public List getAuthorities() { 166 | 167 | Set setAuths = new HashSet(); 168 | 169 | // Build user's authorities 170 | for (String userRole : getRole().split(",")) { 171 | setAuths.add(new SimpleGrantedAuthority(userRole)); 172 | } 173 | 174 | List result = new ArrayList(setAuths); 175 | return result; 176 | } 177 | 178 | public List getAuthorities(String userRole) { 179 | List result = new ArrayList(); 180 | result.add(new SimpleGrantedAuthority(userRole)); 181 | return result; 182 | 183 | } 184 | 185 | } 186 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/events/OnPasswordResetEvent.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.events; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | import com.bobko.storage.domain.UserEntity; 6 | 7 | public class OnPasswordResetEvent extends ApplicationEvent { 8 | 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = -2205810103730939310L; 13 | 14 | private UserEntity user; 15 | private String url; 16 | 17 | public OnPasswordResetEvent(UserEntity user, 18 | String url) { 19 | super(user); 20 | this.user = user; 21 | this.url = url; 22 | } 23 | 24 | public UserEntity getUser() { 25 | return user; 26 | } 27 | 28 | public void setUser(UserEntity user) { 29 | this.user = user; 30 | } 31 | 32 | public String getUrl() { 33 | return url; 34 | } 35 | 36 | public void setUrl(String url) { 37 | this.url = url; 38 | } 39 | 40 | public String getConfirmUrl() { 41 | String token = user.getToken().getToken(); 42 | return url + "/" + token; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/events/OnRegistrationInitiatedEvent.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.events; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | import com.bobko.storage.domain.UserEntity; 6 | 7 | public class OnRegistrationInitiatedEvent extends ApplicationEvent { 8 | 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = -2205810103730939310L; 13 | 14 | private UserEntity user; 15 | private String url; 16 | 17 | public OnRegistrationInitiatedEvent(UserEntity user, 18 | String url) { 19 | super(user); 20 | this.user = user; 21 | this.url = url; 22 | } 23 | 24 | public UserEntity getUser() { 25 | return user; 26 | } 27 | 28 | public void setUser(UserEntity user) { 29 | this.user = user; 30 | } 31 | 32 | public String getUrl() { 33 | return url; 34 | } 35 | 36 | public void setUrl(String url) { 37 | this.url = url; 38 | } 39 | 40 | public String getConfirmUrl() { 41 | String token = user.getToken().getToken(); 42 | return url + "/" + token; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/exceptions/TokenExpiredException.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.exceptions; 2 | 3 | public class TokenExpiredException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 2295146426029936973L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/exceptions/TokenVerifyedException.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.exceptions; 2 | 3 | public class TokenVerifyedException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = -8218325640393455788L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/exceptions/UserActivationException.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.exceptions; 2 | 3 | public class UserActivationException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 2388333390919156788L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/exceptions/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.exceptions; 2 | 3 | public class UserNotFoundException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 5257027879590799488L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/init/WebStorageInitializer.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.init; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 9 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 10 | import org.springframework.web.servlet.view.JstlView; 11 | 12 | @EnableWebMvc 13 | @Configuration 14 | @ComponentScan({ "com.bobko.storage.config" }) 15 | public class WebStorageInitializer extends WebMvcConfigurerAdapter { 16 | 17 | @Override 18 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 19 | registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); 20 | } 21 | 22 | @Bean 23 | public InternalResourceViewResolver viewResolver() { 24 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 25 | viewResolver.setViewClass(JstlView.class); 26 | viewResolver.setPrefix("/WEB-INF/views/jsp/"); 27 | viewResolver.setSuffix(".jsp"); 28 | return viewResolver; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/listeners/RegistrationInitiateListener.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.listeners; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.context.ApplicationListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | import com.bobko.storage.events.OnRegistrationInitiatedEvent; 11 | import com.bobko.storage.service.interfaces.IMailService; 12 | import com.bobko.storage.service.interfaces.IUserService; 13 | 14 | @Component 15 | public class RegistrationInitiateListener implements ApplicationListener { 16 | 17 | private static final Logger LOG = LogManager.getLogger(RegistrationInitiateListener.class); 18 | 19 | @Autowired 20 | private IUserService userService; 21 | 22 | @Autowired 23 | private IMailService mailservice; 24 | 25 | @Value("${email.username}") 26 | private String from; 27 | 28 | @Override 29 | public void onApplicationEvent(OnRegistrationInitiatedEvent event) { 30 | 31 | try { 32 | userService.addUser(event.getUser()); 33 | String confirmUrl = event.getConfirmUrl(); 34 | mailservice.sendMail(from, event.getUser().getEmail(), "noreply", 35 | "Please follow the link to confirm registration " + confirmUrl); 36 | } catch (Exception e) { 37 | LOG.error("Error during user registration", e); 38 | } 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/listeners/ResetPasswordListener.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.listeners; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.context.ApplicationListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | import com.bobko.storage.events.OnPasswordResetEvent; 11 | import com.bobko.storage.service.interfaces.IMailService; 12 | import com.bobko.storage.service.interfaces.IUserService; 13 | 14 | @Component 15 | public class ResetPasswordListener implements ApplicationListener { 16 | 17 | private static final Logger LOG = LogManager.getLogger(RegistrationInitiateListener.class); 18 | 19 | @Autowired 20 | private IUserService userService; 21 | 22 | @Autowired 23 | private IMailService mailservice; 24 | 25 | @Value("${email.username}") 26 | private String from; 27 | 28 | @Override 29 | public void onApplicationEvent(OnPasswordResetEvent event) { 30 | 31 | try { 32 | userService.resetUser(event.getUser()); 33 | } catch (Exception e) { 34 | LOG.error("Error during user registration", e); 35 | } 36 | 37 | String confirmUrl = event.getConfirmUrl(); 38 | 39 | mailservice.sendMail(from, event.getUser().getEmail(), "noreply", 40 | "Please follow the link to set new password " + confirmUrl); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/MailService.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.mail.MailSender; 5 | import org.springframework.mail.SimpleMailMessage; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.bobko.storage.service.interfaces.IMailService; 9 | 10 | @Service 11 | public class MailService implements IMailService { 12 | 13 | @Autowired 14 | private MailSender mailSender; 15 | 16 | @Override 17 | public void sendMail(String from, String to, String subject, String body) { 18 | SimpleMailMessage message = new SimpleMailMessage(); 19 | message.setFrom(from); 20 | message.setTo(to); 21 | message.setSubject(subject); 22 | message.setText(body); 23 | mailSender.send(message); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/PagesService.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | * @see PagesService 7 | */ 8 | 9 | import java.util.List; 10 | 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | import org.springframework.transaction.annotation.Transactional; 14 | 15 | import com.bobko.storage.dao.interfaces.IPagesHolderDao; 16 | import com.bobko.storage.domain.StoragePage; 17 | import com.bobko.storage.service.interfaces.IPagesService; 18 | 19 | @Service 20 | public class PagesService implements IPagesService { 21 | 22 | @Autowired 23 | private IPagesHolderDao pagesDao; 24 | 25 | @Transactional 26 | public List list() { 27 | return pagesDao.list(); 28 | } 29 | 30 | @Transactional 31 | public int getShift() { 32 | return pagesDao.getShift(); 33 | } 34 | 35 | @Transactional 36 | public void setShift(int index) { 37 | pagesDao.setShift(index); 38 | } 39 | 40 | @Transactional 41 | public void nextPage() { 42 | pagesDao.nextPage(); 43 | } 44 | 45 | @Transactional 46 | public void prevPage() { 47 | pagesDao.prevPage(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/PictureGrabber.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.net.URL; 8 | import java.net.URLConnection; 9 | import java.util.LinkedList; 10 | import java.util.List; 11 | import java.util.regex.Matcher; 12 | import java.util.regex.Pattern; 13 | 14 | import org.apache.logging.log4j.Logger; 15 | import org.apache.logging.log4j.LogManager; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.beans.factory.annotation.Value; 18 | import org.springframework.security.core.Authentication; 19 | import org.springframework.security.core.context.SecurityContextHolder; 20 | import org.springframework.stereotype.Service; 21 | 22 | import com.bobko.storage.service.interfaces.IPictureGrabber; 23 | import com.bobko.storage.service.interfaces.IPictureService; 24 | import com.bobko.storage.util.AlbumUtils; 25 | 26 | @Service 27 | public class PictureGrabber implements IPictureGrabber { 28 | 29 | private static final int SAVE_FILE = 1; 30 | private static final int SAVE_LINK = 2; 31 | private static final int EXTRACT_IMAGES = 3; 32 | 33 | @Autowired 34 | private IPictureService picService; 35 | 36 | /** 37 | * rootPath contains path which will be use to save uploaded pictures 38 | * */ 39 | @Value("${data.root.path}") 40 | String rootPath; 41 | 42 | private static final Logger logger = LogManager.getLogger(PictureGrabber.class); 43 | 44 | 45 | private static final String PATTERN_STRING = "(https?|ftp|file)://[A-Za-z0-9%./]+(\\.jpg|\\.jpeg|\\.png|\\.gif|\\.tiff|\\.ico)"; 46 | 47 | private List urls; 48 | 49 | @Override 50 | public void grub(String url, int option) throws Exception { 51 | String userName = getLoginedUserName(); 52 | 53 | File dir = new File(rootPath + "/" + userName + "/"); 54 | if (!dir.exists()) { 55 | dir.mkdirs(); 56 | } 57 | 58 | switch (option) { 59 | case SAVE_FILE: 60 | picService.savePicture(url); 61 | break; 62 | case SAVE_LINK: 63 | 64 | break; 65 | case EXTRACT_IMAGES: 66 | urls = createURLList(url); 67 | for (String s : urls) { 68 | picService.savePicture(s); 69 | } 70 | break; 71 | default: 72 | break; 73 | } 74 | 75 | } 76 | 77 | /** 78 | * @return authenticated user name 79 | * */ 80 | private String getLoginedUserName() { 81 | String userName = "anonimouse"; 82 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 83 | if (authentication != null) { 84 | userName = authentication.getName(); 85 | } 86 | return userName; 87 | } 88 | 89 | private List createURLList(String url) { 90 | InputStreamReader in = null; 91 | List result = new LinkedList(); 92 | 93 | if (url == null || url.isEmpty()) { 94 | return result; 95 | } else { 96 | 97 | try { 98 | URL url1 = new URL(url); 99 | // if it's need to 100 | // Proxy proxy = new Proxy(Proxy.Type.HTTP, new 101 | // InetSocketAddress("172.30.0.2", 3128)); 102 | URLConnection connection = url1.openConnection(); 103 | connection.addRequestProperty("User-Agent", 104 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); 105 | InputStream inputStream = connection.getInputStream(); 106 | in = new InputStreamReader(inputStream); 107 | 108 | // read contents into string buffer 109 | StringBuffer input = new StringBuffer(); 110 | 111 | int ch; 112 | while ((ch = in.read()) != -1) { 113 | input.append((char) ch); 114 | } 115 | 116 | Pattern pattern = Pattern.compile(PATTERN_STRING, Pattern.CASE_INSENSITIVE); 117 | Matcher matcher = pattern.matcher(input); 118 | 119 | while (matcher.find()) { 120 | int start = matcher.start(); 121 | int end = matcher.end(); 122 | String match = input.substring(start, end); 123 | String[] tmp = match.split("src="); 124 | if (tmp.length >= 2) { 125 | match = tmp[1].substring(1); 126 | } 127 | 128 | if (match.startsWith("//")) { 129 | match = match.substring(1); 130 | } 131 | 132 | if (match.startsWith("/")) { 133 | match = AlbumUtils.getPureAdress(url) + match; 134 | } 135 | 136 | result.add(match); 137 | } 138 | } catch (Exception e) { 139 | logger.error(e); 140 | } finally { 141 | if (in != null) { 142 | try { 143 | in.close(); 144 | } catch (IOException e) { 145 | logger.error(e); 146 | } 147 | } 148 | } 149 | } 150 | 151 | return result; 152 | 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/PictureService.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | * @see PictureService 7 | */ 8 | 9 | import java.awt.image.BufferedImage; 10 | import java.io.BufferedInputStream; 11 | import java.io.BufferedOutputStream; 12 | import java.io.File; 13 | import java.io.FileInputStream; 14 | import java.io.FileOutputStream; 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | import java.io.OutputStream; 18 | import java.net.HttpURLConnection; 19 | import java.net.URL; 20 | import java.nio.file.FileSystems; 21 | import java.nio.file.Files; 22 | import java.nio.file.Path; 23 | import java.sql.Timestamp; 24 | import java.util.Date; 25 | import java.util.List; 26 | 27 | import javax.imageio.ImageIO; 28 | import javax.validation.Valid; 29 | 30 | import org.apache.logging.log4j.LogManager; 31 | import org.apache.logging.log4j.Logger; 32 | import org.springframework.beans.factory.annotation.Autowired; 33 | import org.springframework.beans.factory.annotation.Value; 34 | import org.springframework.security.core.Authentication; 35 | import org.springframework.security.core.context.SecurityContextHolder; 36 | import org.springframework.stereotype.Service; 37 | import org.springframework.transaction.annotation.Transactional; 38 | import org.springframework.web.multipart.MultipartFile; 39 | 40 | import com.bobko.storage.common.StorageConst; 41 | import com.bobko.storage.dao.base.IGenericDao; 42 | import com.bobko.storage.dao.interfaces.IPictureDao; 43 | import com.bobko.storage.domain.Document; 44 | import com.bobko.storage.domain.UserEntity; 45 | import com.bobko.storage.service.interfaces.IPictureService; 46 | import com.bobko.storage.util.AlbumUtils; 47 | 48 | @Service 49 | @Transactional 50 | public class PictureService implements IPictureService { 51 | 52 | @Autowired 53 | private IPictureDao pictureDao; 54 | 55 | @Autowired 56 | private IGenericDao userDao; 57 | 58 | @Value("${data.root.path}") 59 | private String rootPath; 60 | 61 | private static final String JPG = "jpg"; 62 | private static final String PNG = "png"; 63 | private static final String DATA = "data"; 64 | private static final String IMAGES = "images"; 65 | private static final String THUMBNAIL = "thumbnail"; 66 | private static final int SIZE = 1024; 67 | 68 | private static final Logger LOGGER = LogManager.getLogger(PictureService.class); 69 | 70 | public List list(int shift, int count) { 71 | return pictureDao.rankList(shift, count); 72 | } 73 | 74 | public Document getPicture(int id) { 75 | return pictureDao.find(id); 76 | } 77 | 78 | public void addPicture(Document pic) { 79 | pictureDao.add(pic); 80 | } 81 | 82 | public void removePicture(int id) { 83 | Document entity = pictureDao.find(id); 84 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 85 | if(entity.getOwner().equals(auth.getName())) { 86 | pictureDao.remove(entity); 87 | } 88 | } 89 | 90 | @Override 91 | public void savePicture(@Valid Document pic, MultipartFile multipartFile) throws Exception { 92 | 93 | pic.setFilename(multipartFile.getOriginalFilename()); 94 | 95 | String username = getLoginedUserName(); 96 | pic.setOwner(username); 97 | // normalize description length 98 | if (pic.getDescription().length() >= StorageConst.MAX_DESCRIPTION_SIZE) { 99 | pic.setDescription(pic.getDescription().substring(0, StorageConst.MAX_DESCRIPTION_SIZE)); 100 | } 101 | 102 | String pathToFile = DATA + File.separator + username + File.separator + IMAGES; 103 | 104 | File dir = createDirs(rootPath + pathToFile); 105 | String pathToThumbnail = DATA + File.separator + username + File.separator + THUMBNAIL; 106 | File thumbnailDir = createDirs(rootPath + pathToThumbnail); 107 | String fileName = pic.getFilename(); 108 | 109 | String suffix = ""; 110 | 111 | int i = fileName.lastIndexOf('.'); 112 | if (i > 0) { 113 | suffix = fileName.substring(i); 114 | } 115 | String uuid = AlbumUtils.getUUID(); 116 | 117 | String name = File.separator + uuid + suffix; 118 | 119 | File image = new File(dir + File.separator + fileName); 120 | multipartFile.transferTo(image); 121 | 122 | File thumbnail = new File(thumbnailDir + name); 123 | BufferedImage bufferedImage = ImageIO.read(image); 124 | 125 | if (bufferedImage != null) { 126 | bufferedImage = AlbumUtils.correctingSize(bufferedImage); 127 | //TODO create thumbnail creator 128 | ImageIO.write(bufferedImage, suffix.substring(1), thumbnail); 129 | pic.setThumbnail(pathToThumbnail + name); 130 | } 131 | 132 | pic.setPath(pathToFile + File.separator + fileName); 133 | 134 | UserEntity user = userDao.getByField("login", username).get(0); 135 | 136 | pic.setUser(user); 137 | 138 | pic.setCreated(new Timestamp(new Date().getTime())); 139 | 140 | addPicture(pic); 141 | 142 | } 143 | 144 | @Override 145 | public void savePicture(String url) { 146 | 147 | Document pic = new Document(); 148 | 149 | int slashIndex = url.lastIndexOf('/'); 150 | String originalFileName = url.substring(slashIndex + 1); 151 | if ((originalFileName != null) && !originalFileName.isEmpty()) { 152 | pic.setFilename(originalFileName); 153 | } else { 154 | pic.setFilename("imgUrl"); 155 | } 156 | 157 | String username = getLoginedUserName(); 158 | String pathToFile = DATA + File.separator + username + File.separator + IMAGES; 159 | File dir = createDirs(rootPath + pathToFile); 160 | String pathToThumbnail = DATA + File.separator + username + File.separator + THUMBNAIL; 161 | File thumbnailDir = createDirs(rootPath + pathToThumbnail); 162 | String uuid = AlbumUtils.getUUID(); 163 | OutputStream outStream = null; 164 | HttpURLConnection connection = null; 165 | InputStream is = null; 166 | String suffix = ""; 167 | String name = ""; 168 | 169 | try { 170 | URL urlToPicture; 171 | byte[] buf; 172 | int byteRead; 173 | urlToPicture = new URL(url); 174 | 175 | int i = url.lastIndexOf('.'); 176 | if (i > 0) { 177 | suffix = url.substring(i + 1); 178 | } 179 | 180 | name = File.separator + uuid + "." + suffix; 181 | 182 | File image = new File(dir + File.separator + pic.getFilename()); 183 | 184 | outStream = new BufferedOutputStream(new FileOutputStream(image)); 185 | 186 | // Proxy proxy = new Proxy(Proxy.Type.HTTP, new 187 | // InetSocketAddress("172.30.0.2", 3128)); 188 | 189 | connection = (HttpURLConnection) urlToPicture.openConnection(); 190 | connection.addRequestProperty("User-Agent", 191 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); 192 | 193 | if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { 194 | LOGGER.error(connection.getErrorStream()); 195 | return; 196 | } else { 197 | 198 | is = connection.getInputStream(); 199 | buf = new byte[SIZE]; 200 | while ((byteRead = is.read(buf)) != -1) { 201 | outStream.write(buf, 0, byteRead); 202 | } 203 | 204 | outStream.close(); 205 | 206 | File thumbnail = new File(thumbnailDir + name); 207 | 208 | BufferedImage bufferedImage = ImageIO.read(image); 209 | 210 | if(bufferedImage != null) { 211 | if(suffix.equalsIgnoreCase(JPG) || suffix.equalsIgnoreCase(PNG)) { 212 | bufferedImage = AlbumUtils.correctingSize(bufferedImage); 213 | ImageIO.write(bufferedImage, suffix, thumbnail); 214 | } else { 215 | BufferedInputStream in = new BufferedInputStream(new FileInputStream(image)); 216 | BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(thumbnail)); 217 | 218 | while ((byteRead = in.read(buf)) != -1) { 219 | out.write(buf, 0, byteRead); 220 | } 221 | 222 | in.close(); 223 | out.close(); 224 | 225 | } 226 | 227 | pic.setThumbnail(pathToThumbnail + name); 228 | 229 | } 230 | } 231 | 232 | } catch (Exception e) { 233 | LOGGER.error(e); 234 | } finally { 235 | try { 236 | if (is != null) { 237 | is.close(); 238 | } 239 | if (outStream != null) { 240 | outStream.close(); 241 | } 242 | } catch (IOException e) { 243 | LOGGER.error(e); 244 | } 245 | } 246 | 247 | UserEntity user = userDao.getByField("login", username).get(0); 248 | pic.setUser(user); 249 | pic.setDescription(AlbumUtils.getPureAdress(url)); 250 | 251 | pic.setPath(pathToFile + File.separator + pic.getFilename()); 252 | 253 | pic.setOwner(username); 254 | 255 | pic.setCreated(new Timestamp(new Date().getTime())); 256 | 257 | try { 258 | addPicture(pic); 259 | } catch (Exception e) { 260 | LOGGER.error("some error occured", e); 261 | } 262 | } 263 | 264 | /** 265 | * @return authenticated user name 266 | * */ 267 | private String getLoginedUserName() { 268 | String userName = "anonimouse"; 269 | Authentication authentication = SecurityContextHolder.getContext() 270 | .getAuthentication(); 271 | if (authentication != null) { 272 | userName = authentication.getName(); 273 | } 274 | 275 | return userName; 276 | } 277 | 278 | @Override 279 | public byte[] getPicByPath(String path) { 280 | 281 | byte[] fileData = new byte[0]; 282 | 283 | Path p = FileSystems.getDefault().getPath(rootPath, path); 284 | try { 285 | fileData = Files.readAllBytes(p); 286 | } catch (IOException e) { 287 | LOGGER.error(e); 288 | } 289 | 290 | return fileData; 291 | 292 | } 293 | 294 | private File createDirs(String path) { 295 | File dir = new File(path); 296 | if (!dir.exists()) { 297 | dir.mkdirs(); 298 | } 299 | return dir; 300 | } 301 | 302 | } 303 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/StorageUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | 6 | /** 7 | * Service that provide user exists by username using almost at registration or authorization 8 | * 9 | * @author oleksii bobko 10 | * @data 12.08.2013 11 | * @see UserDetailsService 12 | */ 13 | 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.dao.DataAccessException; 16 | import org.springframework.security.core.userdetails.User; 17 | import org.springframework.security.core.userdetails.UserDetails; 18 | import org.springframework.security.core.userdetails.UserDetailsService; 19 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 20 | import org.springframework.stereotype.Service; 21 | import org.springframework.transaction.annotation.Transactional; 22 | 23 | import com.bobko.storage.domain.UserEntity; 24 | import com.bobko.storage.service.interfaces.IUserService; 25 | 26 | @Service("storageUserDetailsService") 27 | public class StorageUserDetailsService implements UserDetailsService { 28 | 29 | private static final Logger LOGGER = LogManager.getLogger(StorageUserDetailsService.class); 30 | 31 | public StorageUserDetailsService() { 32 | LOGGER.info("instantiated"); 33 | } 34 | 35 | @Autowired 36 | private IUserService userService; 37 | 38 | @Transactional(readOnly = true) 39 | public UserDetails loadUserByUsername(String userStr) 40 | throws UsernameNotFoundException, DataAccessException { 41 | 42 | UserEntity userEntity = userService.getUserByName(userStr); 43 | if (userEntity == null) { 44 | userEntity = userService.getUserByEmail(userStr); 45 | if (userEntity == null) { 46 | throw new UsernameNotFoundException("user not found"); 47 | } 48 | } 49 | 50 | User user = new User(userEntity.getLogin(), userEntity.getPw(), 51 | userEntity.isActive(), true, true, true, 52 | userEntity.getAuthorities()); 53 | 54 | return user; 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | * @see UserService 7 | */ 8 | 9 | import java.util.List; 10 | 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.security.authentication.encoding.Md5PasswordEncoder; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.transaction.annotation.Transactional; 15 | 16 | import com.bobko.storage.dao.interfaces.IActivationTokenDao; 17 | import com.bobko.storage.dao.interfaces.IUserDao; 18 | import com.bobko.storage.domain.ActivationToken; 19 | import com.bobko.storage.domain.UserEntity; 20 | import com.bobko.storage.exceptions.TokenExpiredException; 21 | import com.bobko.storage.exceptions.TokenVerifyedException; 22 | import com.bobko.storage.exceptions.UserActivationException; 23 | import com.bobko.storage.exceptions.UserNotFoundException; 24 | import com.bobko.storage.service.interfaces.IUserService; 25 | 26 | @Service 27 | @Transactional 28 | public class UserService implements IUserService { 29 | 30 | @Autowired 31 | private IUserDao userDao; 32 | 33 | @Autowired 34 | private IActivationTokenDao tokenDao; 35 | 36 | public UserService() { 37 | super(); 38 | } 39 | 40 | @Override 41 | public void addUser(UserEntity user) throws Exception { 42 | 43 | // set default user role 44 | user.setRole(IUserService.ROLE_USER); 45 | 46 | Md5PasswordEncoder encoder = new Md5PasswordEncoder(); 47 | user.setPw(encoder.encodePassword(user.getPw(), null)); 48 | 49 | user.setPwConfirmation(null); 50 | 51 | ActivationToken token = new ActivationToken(user); 52 | user.setToken(token); 53 | 54 | userDao.add(user); 55 | tokenDao.add(token); 56 | } 57 | 58 | public void removeUser(String name) { 59 | UserEntity entity = userDao.find(name); 60 | userDao.remove(entity); 61 | } 62 | 63 | public UserEntity getUser(String name) { 64 | if (name == null || name.isEmpty()) { 65 | return null; 66 | } 67 | return userDao.find(name); 68 | } 69 | 70 | @Override 71 | public UserEntity getUserByName(String name) { 72 | if (name == null || name.isEmpty()) { 73 | return null; 74 | } 75 | List result = userDao.getByField("login", name); 76 | return (result != null && !result.isEmpty()) ? result.get(0) : null; 77 | } 78 | 79 | @Override 80 | public UserEntity getUserByEmail(String email) { 81 | List result = userDao.getByField("email", email); 82 | return (result != null && !result.isEmpty()) ? result.get(0) : null; 83 | } 84 | 85 | @Override 86 | public void resetUser(UserEntity user) { 87 | user.setActive(false); 88 | user.getToken().reset(); 89 | userDao.update(user); 90 | } 91 | 92 | @Override 93 | public UserEntity getUserByToken(String token, boolean activate) 94 | throws TokenExpiredException, TokenVerifyedException, 95 | UserNotFoundException { 96 | List result = tokenDao.getByField("token", token); 97 | UserEntity user = null; 98 | if (result != null && !result.isEmpty()) { 99 | ActivationToken tokenEntity = result.get(0); 100 | if (tokenEntity.isVerified()) { 101 | throw new TokenVerifyedException(); 102 | } 103 | 104 | if (tokenEntity.isExpired()) { 105 | throw new TokenExpiredException(); 106 | } 107 | tokenEntity.setVerified(true); 108 | user = tokenEntity.getUser(); 109 | user.setActive(activate); 110 | return user; 111 | } else { 112 | throw new UserNotFoundException(); 113 | } 114 | } 115 | 116 | @Override 117 | public void changeUserPassword(UserEntity user, String pw) throws UserActivationException { 118 | if(user.isActive()) { 119 | throw new UserActivationException(); 120 | } 121 | Md5PasswordEncoder encoder = new Md5PasswordEncoder(); 122 | user.setPw(encoder.encodePassword(pw, null)); 123 | user.setActive(true); 124 | userDao.update(user); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/interfaces/IMailService.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service.interfaces; 2 | 3 | public interface IMailService { 4 | public void sendMail(String from, String to, String subject, String body); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/interfaces/IPagesService.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service.interfaces; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | * @see AlbumPage 7 | */ 8 | 9 | import java.util.List; 10 | 11 | import com.bobko.storage.domain.StoragePage; 12 | 13 | public interface IPagesService { 14 | 15 | /** 16 | * @return List of AlbumPage 17 | * */ 18 | public List list(); 19 | 20 | /** 21 | * @return number of current page 22 | * */ 23 | public int getShift(); 24 | 25 | /** 26 | * set current page 27 | * */ 28 | public void setShift(int index); 29 | 30 | /** 31 | * set active +1 page 32 | * */ 33 | public void nextPage(); 34 | 35 | /** 36 | * set active -1 37 | * */ 38 | public void prevPage(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/interfaces/IPictureGrabber.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service.interfaces; 2 | 3 | 4 | 5 | public interface IPictureGrabber { 6 | 7 | public void grub(String url, int option) throws Exception; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/interfaces/IPictureService.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service.interfaces; 2 | 3 | /** 4 | * @author oleksii bobko 5 | * @data 12.08.2013 6 | */ 7 | 8 | import java.util.List; 9 | 10 | import org.springframework.web.multipart.MultipartFile; 11 | 12 | import com.bobko.storage.domain.Document; 13 | 14 | public interface IPictureService { 15 | 16 | public void addPicture(Document pic); 17 | 18 | public List list(int shift, int count); 19 | 20 | public Document getPicture(int id); 21 | 22 | public void removePicture(int id); 23 | 24 | public void savePicture(Document pic, MultipartFile file) throws Exception; 25 | 26 | public byte[] getPicByPath(String path); 27 | 28 | public void savePicture(String url); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/service/interfaces/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service.interfaces; 2 | 3 | /** 4 | * Service provide access to domain lavel to retrieve information about users from DB 5 | * @author oleksii bobko 6 | * @data 12.08.2013 7 | */ 8 | 9 | import com.bobko.storage.domain.UserEntity; 10 | import com.bobko.storage.exceptions.TokenExpiredException; 11 | import com.bobko.storage.exceptions.TokenVerifyedException; 12 | import com.bobko.storage.exceptions.UserActivationException; 13 | import com.bobko.storage.exceptions.UserNotFoundException; 14 | 15 | public interface IUserService { 16 | 17 | public static final String ROLE_USER = "ROLE_USER"; 18 | /** 19 | * add new user to db 20 | * */ 21 | public void addUser(UserEntity user) throws Exception; 22 | 23 | /** 24 | * remove user from db by unique user name 25 | * */ 26 | public void removeUser(String name); 27 | 28 | /** 29 | * retrieve user from db bt unique user name 30 | * */ 31 | public UserEntity getUser(String name); 32 | 33 | public UserEntity getUserByName(String name); 34 | 35 | public UserEntity getUserByEmail(String email); 36 | 37 | public void resetUser(UserEntity user); 38 | 39 | public UserEntity getUserByToken(String token, boolean activate) throws TokenExpiredException, TokenVerifyedException, UserNotFoundException; 40 | 41 | public void changeUserPassword(UserEntity oldUser, String pw) throws UserActivationException; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/util/AlbumUtils.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.util; 2 | 3 | /** 4 | * Generate unique string with UUID 5 | * @author oleksii bobko 6 | * @data 12.08.2013 7 | * @see UUID 8 | */ 9 | 10 | import java.awt.Graphics2D; 11 | import java.awt.RenderingHints; 12 | import java.awt.image.BufferedImage; 13 | import java.math.BigInteger; 14 | import java.net.URI; 15 | import java.net.URISyntaxException; 16 | import java.security.MessageDigest; 17 | import java.security.NoSuchAlgorithmException; 18 | import java.util.List; 19 | import java.util.UUID; 20 | 21 | import org.apache.logging.log4j.Logger; 22 | import org.apache.logging.log4j.LogManager; 23 | 24 | import com.bobko.storage.domain.Document; 25 | 26 | public class AlbumUtils { 27 | 28 | private static final int MAX_PICTURE_SIZE = 400; 29 | private static final int PREFIX_SIZE = 4; 30 | 31 | private static final Logger LOGGER = LogManager.getLogger(AlbumUtils.class); 32 | 33 | private AlbumUtils() { 34 | } 35 | 36 | public static String getUUID() { 37 | return UUID.randomUUID().toString().replaceAll("-", ""); 38 | } 39 | 40 | /** 41 | * Method set proportional size of picture if picture height or width more 42 | * then MAX_PICTURE_SIZE 43 | * */ 44 | public static BufferedImage correctingSize(BufferedImage img) { 45 | if (img == null) { 46 | return null; 47 | } 48 | int oldWidth = img.getWidth(); 49 | int oldHeight = img.getHeight(); 50 | 51 | if ((oldHeight <= MAX_PICTURE_SIZE) && (oldWidth <= MAX_PICTURE_SIZE)) { 52 | return img; 53 | } 54 | double ratio = Math.min((double) MAX_PICTURE_SIZE / (double) oldHeight, 55 | (double) MAX_PICTURE_SIZE / (double) oldWidth); 56 | int newWidth = (int) (oldWidth * ratio); 57 | int newHeight = (int) (oldHeight * ratio); 58 | 59 | BufferedImage dimg = new BufferedImage(newWidth, newHeight, 60 | img.getType()); 61 | Graphics2D g = dimg.createGraphics(); 62 | g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, 63 | RenderingHints.VALUE_INTERPOLATION_BILINEAR); 64 | g.drawImage(img, 0, 0, newWidth, newHeight, 0, 0, oldWidth, oldHeight, 65 | null); 66 | g.dispose(); 67 | return dimg; 68 | } 69 | 70 | public static String getPureAdress(String url) { 71 | try { 72 | URI uri = new URI(url); 73 | String result = uri.getScheme() + "://" + uri.getHost(); 74 | return result.startsWith("www.") ? result.substring(PREFIX_SIZE) : result; 75 | } catch (URISyntaxException ex) { 76 | LOGGER.warn("bad URI syntax", ex); 77 | return ""; 78 | } 79 | } 80 | 81 | public static void correctPaths(List pictures) { 82 | for (Document picture : pictures) { 83 | picture.setPath(picture.getPath().replace("\\", "/")); 84 | } 85 | 86 | } 87 | 88 | public static String getMD5(String input) throws Exception { 89 | 90 | MessageDigest messageDigest = null; 91 | String encoded = ""; 92 | 93 | // encode pw to md5 hash 94 | try { 95 | messageDigest = MessageDigest.getInstance("MD5"); 96 | messageDigest.update(input.getBytes(), 0, input.length()); 97 | encoded = new BigInteger(1, messageDigest.digest()).toString(16); 98 | } catch (NoSuchAlgorithmException e) { 99 | throw new Exception("Encription failure", e); 100 | } 101 | 102 | return encoded; 103 | 104 | } 105 | 106 | public static void setCanDelete(List pictures, String userName) { 107 | 108 | for(Document p : pictures) { 109 | if(userName != null && !userName.isEmpty() && p.getOwner().equals(userName)) { 110 | p.setCanDelete(true); 111 | } else { 112 | p.setCanDelete(false); 113 | } 114 | } 115 | 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/web/DataController.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.web; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | import org.springframework.web.servlet.HandlerMapping; 11 | 12 | import com.bobko.storage.service.interfaces.IPictureService; 13 | 14 | @Controller 15 | public class DataController { 16 | 17 | @Autowired 18 | private IPictureService picService; 19 | 20 | @ResponseBody 21 | @RequestMapping(value = "/data/**", method = RequestMethod.GET) 22 | private byte[] getFile(HttpServletRequest request) { 23 | return picService.getPicByPath((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/web/ErrorController.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | 7 | @Controller 8 | public class ErrorController { 9 | 10 | @RequestMapping("error") 11 | public String hendleError() { 12 | return "error"; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/web/MainController.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.web; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | 12 | import com.bobko.storage.domain.Document; 13 | import com.bobko.storage.domain.Topic; 14 | 15 | @Controller 16 | public class MainController { 17 | /** 18 | * default request mapping redirect requests to pictures page 19 | * */ 20 | // @RequestMapping("/") 21 | public String home(Map model, HttpServletRequest request) { 22 | 23 | Document p = new Document(); 24 | p.setPath("data/admin/images/fc03856b60bd42769485784afb56317a.jpeg"); 25 | 26 | Topic stub = new Topic(); 27 | stub.setFrontImage(p); 28 | stub.setRate(5); 29 | stub.setFrontImage(p); 30 | 31 | List topics = new ArrayList(); 32 | 33 | topics.add(stub); 34 | topics.add(stub); 35 | topics.add(stub); 36 | 37 | model.put("topics", topics); 38 | return "main"; 39 | } 40 | 41 | @RequestMapping(value = "/reset_password") 42 | public String forgot() { 43 | return "reset_password"; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/web/MainRestController.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.web; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | import javax.validation.Valid; 6 | 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.ApplicationEventPublisher; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.security.access.prepost.PreAuthorize; 14 | import org.springframework.security.core.Authentication; 15 | import org.springframework.security.core.context.SecurityContextHolder; 16 | import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; 17 | import org.springframework.validation.BindingResult; 18 | import org.springframework.web.bind.annotation.ModelAttribute; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RequestMethod; 21 | import org.springframework.web.bind.annotation.RequestParam; 22 | import org.springframework.web.bind.annotation.ResponseBody; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import com.bobko.storage.domain.UserEntity; 26 | import com.bobko.storage.events.OnPasswordResetEvent; 27 | import com.bobko.storage.events.OnRegistrationInitiatedEvent; 28 | import com.bobko.storage.exceptions.UserActivationException; 29 | import com.bobko.storage.service.interfaces.IUserService; 30 | 31 | @RestController 32 | public class MainRestController { 33 | 34 | private static final Logger LOG = LogManager.getLogger(MainRestController.class); 35 | 36 | @Autowired 37 | private IUserService userService; 38 | 39 | @Autowired 40 | private ApplicationEventPublisher eventPublisher; 41 | 42 | @RequestMapping(value = "/reset_password", method = RequestMethod.POST) 43 | public ResponseEntity resetPassword(@RequestParam String email, 44 | HttpServletRequest request) { 45 | UserEntity checkUser = userService.getUserByName(email); 46 | // try to fetch user by nickname 47 | if (checkUser == null) { 48 | checkUser = userService.getUserByEmail(email); 49 | if(checkUser == null) { 50 | return new ResponseEntity("no such user", HttpStatus.NOT_FOUND); 51 | } 52 | } 53 | 54 | eventPublisher.publishEvent(new OnPasswordResetEvent(checkUser, 55 | request.getRequestURL().toString())); 56 | return new ResponseEntity<>("Check your Email", HttpStatus.OK); 57 | 58 | } 59 | 60 | /** 61 | * perform adding new user to db 62 | * */ 63 | @RequestMapping(value = "/registration", method = RequestMethod.POST) 64 | public ResponseEntity createNewUser( 65 | @Valid @ModelAttribute("user") UserEntity user, 66 | BindingResult bindingResult, HttpServletRequest request) { 67 | 68 | if (bindingResult.hasErrors()) { 69 | return new ResponseEntity<>(HttpStatus.BAD_REQUEST); 70 | } 71 | 72 | if (!user.getPw().equals(user.getPwConfirmation())) { 73 | return new ResponseEntity("Password and confirmation are not equal", HttpStatus.CONFLICT); 74 | } 75 | 76 | UserEntity checkUser = userService.getUserByName(user.getLogin()); 77 | // check if new user already exists in base 78 | if (checkUser != null) { 79 | return new ResponseEntity("Nickname already in use", HttpStatus.CONFLICT); 80 | } 81 | 82 | UserEntity emailUser = userService.getUserByEmail(user.getEmail()); 83 | // check if new user already exists in base 84 | if (emailUser != null) { 85 | return new ResponseEntity("Email already in use", HttpStatus.CONFLICT); 86 | } 87 | 88 | eventPublisher.publishEvent(new OnRegistrationInitiatedEvent(user, 89 | request.getRequestURL().toString())); 90 | 91 | return new ResponseEntity<>("Account created", HttpStatus.OK); 92 | 93 | } 94 | 95 | @RequestMapping(value = "/save_password", method = RequestMethod.POST) 96 | @PreAuthorize("hasRole('PASSWORD_UPDATE')") 97 | @ResponseBody 98 | public ResponseEntity savePassword( 99 | @ModelAttribute("user") UserEntity user, 100 | HttpServletRequest request, HttpServletResponse response) { 101 | 102 | if (user.getPw() == null || user.getPw().isEmpty() 103 | || !user.getPw().equals(user.getPwConfirmation())) { 104 | return new ResponseEntity("password can't be empty", HttpStatus.CONFLICT); 105 | } 106 | 107 | Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 108 | 109 | UserEntity oldUser = null; 110 | 111 | if(principal instanceof UserEntity) { 112 | oldUser = (UserEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 113 | } else { 114 | return new ResponseEntity("Can't update password", HttpStatus.CONFLICT); 115 | } 116 | 117 | try { 118 | userService.changeUserPassword(oldUser, user.getPw()); 119 | } catch (UserActivationException e) { 120 | return new ResponseEntity("Can't update password", HttpStatus.CONFLICT); 121 | } 122 | 123 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 124 | if (auth != null) { 125 | new SecurityContextLogoutHandler().logout(request, response, auth); 126 | } 127 | 128 | SecurityContextHolder.getContext().setAuthentication(null); 129 | return new ResponseEntity<>("Password updated successfully", HttpStatus.OK); 130 | 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/web/RegistrationController.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.web; 2 | 3 | /** 4 | * Controller class that provides registration of new users 5 | * @author oleksii bobko 6 | * @data 12.08.2013 7 | */ 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | import org.apache.logging.log4j.LogManager; 12 | import org.apache.logging.log4j.Logger; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.security.access.prepost.PreAuthorize; 15 | import org.springframework.security.authentication.AnonymousAuthenticationToken; 16 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 17 | import org.springframework.security.core.Authentication; 18 | import org.springframework.security.core.context.SecurityContextHolder; 19 | import org.springframework.stereotype.Controller; 20 | import org.springframework.ui.Model; 21 | import org.springframework.web.bind.annotation.ModelAttribute; 22 | import org.springframework.web.bind.annotation.PathVariable; 23 | import org.springframework.web.bind.annotation.RequestMapping; 24 | import org.springframework.web.bind.annotation.RequestMethod; 25 | 26 | import com.bobko.storage.domain.UserEntity; 27 | import com.bobko.storage.exceptions.TokenExpiredException; 28 | import com.bobko.storage.exceptions.TokenVerifyedException; 29 | import com.bobko.storage.exceptions.UserNotFoundException; 30 | import com.bobko.storage.service.interfaces.IUserService; 31 | 32 | @Controller 33 | public class RegistrationController { 34 | 35 | @Autowired 36 | private IUserService userService; 37 | private static final String NOT_ACTIVE = "notActive"; 38 | private static final String OK = "ok"; 39 | private static final Logger LOG = LogManager.getLogger(RegistrationController.class); 40 | 41 | /** 42 | * redirect to registration page and put to Map UserEntity object 43 | * */ 44 | @RequestMapping(value = "/registration", method = RequestMethod.GET) 45 | public String registration(Model model) { 46 | 47 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 48 | if (!(auth instanceof AnonymousAuthenticationToken)) { 49 | /* The user is logged in :) */ 50 | return "redirect:/"; 51 | } 52 | 53 | model.addAttribute("user", new UserEntity()); 54 | return "registration"; 55 | } 56 | 57 | @RequestMapping(value = "/registration/{token}", method = RequestMethod.GET) 58 | public String confirmRegistration 59 | (HttpServletRequest request, @PathVariable String token, Model model) { 60 | UserEntity user = null; 61 | try { 62 | user = userService.getUserByToken(token, true); 63 | } catch (TokenExpiredException e) { 64 | LOG.warn("token expired " + user); 65 | model.addAttribute("message", "token.expired"); 66 | return "redirect:/reset_password"; 67 | } catch (TokenVerifyedException e) { 68 | LOG.warn("token already verified " + user); 69 | model.addAttribute("message", "token.verified"); 70 | return "redirect:/reset_password"; 71 | } catch (UserNotFoundException e) { 72 | LOG.warn("user not found " + token); 73 | return "redirect:/"; 74 | } 75 | 76 | model.addAttribute("user", user.getLogin()); 77 | model.addAttribute("token", token); 78 | LOG.warn("user activated successfully " + user); 79 | return "redirect:/thankyou"; 80 | 81 | } 82 | 83 | @RequestMapping(value = "/thankyou", method = RequestMethod.GET) 84 | public String thankYou(@ModelAttribute("user") String user, 85 | @ModelAttribute("token") String token, Model model) { 86 | UserEntity userEntity = userService.getUserByName(user); 87 | if (userEntity != null) { 88 | if (!userEntity.getToken().getToken().equals(token)) { 89 | model.addAttribute("code", NOT_ACTIVE); 90 | } else if (userEntity.isActive()) { 91 | model.addAttribute("code", OK); 92 | } else { 93 | model.addAttribute("code", NOT_ACTIVE); 94 | } 95 | } else { 96 | model.addAttribute("code", NOT_ACTIVE); 97 | } 98 | 99 | model.addAttribute("user", user); 100 | 101 | return "thankyou"; 102 | } 103 | 104 | @RequestMapping(value = "/reset_password/{token}", method = RequestMethod.GET) 105 | public String resetPassword 106 | (HttpServletRequest request, @PathVariable String token, Model model) { 107 | UserEntity user = null; 108 | try { 109 | user = userService.getUserByToken(token, false); 110 | } catch (Exception e) { 111 | LOG.warn("some error during password reset" + e.getMessage()); 112 | return "redirect:/"; 113 | } 114 | 115 | Authentication auth = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities("PASSWORD_UPDATE")); 116 | SecurityContextHolder.getContext().setAuthentication(auth); 117 | 118 | model.addAttribute("user", new UserEntity()); 119 | return "redirect:/new_password"; 120 | } 121 | 122 | @RequestMapping(value = "/new_password" , method = RequestMethod.GET) 123 | @PreAuthorize("hasRole('PASSWORD_UPDATE')") 124 | public String newPassword(Model model) { 125 | model.addAttribute("user", new UserEntity()); 126 | return "new_password"; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/com/bobko/storage/web/UploadController.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.web; 2 | 3 | /** 4 | * Controller class that provides uploading, grabing, remove pictures and also user login 5 | * 6 | * @author oleksii bobko 7 | * @data 12.08.2013 8 | */ 9 | 10 | import java.security.Principal; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | import javax.servlet.http.HttpServletRequest; 15 | 16 | import org.apache.logging.log4j.LogManager; 17 | import org.apache.logging.log4j.Logger; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.security.authentication.AnonymousAuthenticationToken; 20 | import org.springframework.security.core.Authentication; 21 | import org.springframework.security.core.context.SecurityContextHolder; 22 | import org.springframework.stereotype.Controller; 23 | import org.springframework.web.bind.annotation.ModelAttribute; 24 | import org.springframework.web.bind.annotation.PathVariable; 25 | import org.springframework.web.bind.annotation.RequestMapping; 26 | import org.springframework.web.bind.annotation.RequestMethod; 27 | import org.springframework.web.bind.annotation.RequestParam; 28 | import org.springframework.web.multipart.MultipartFile; 29 | 30 | import com.bobko.storage.common.StorageConst; 31 | import com.bobko.storage.domain.IncomingURL; 32 | import com.bobko.storage.domain.Document; 33 | import com.bobko.storage.service.interfaces.IPagesService; 34 | import com.bobko.storage.service.interfaces.IPictureGrabber; 35 | import com.bobko.storage.service.interfaces.IPictureService; 36 | import com.bobko.storage.util.AlbumUtils; 37 | 38 | @Controller 39 | public class UploadController { 40 | 41 | @Autowired 42 | private IPictureService picService; 43 | 44 | @Autowired 45 | private IPagesService pagesService; 46 | 47 | @Autowired 48 | private IPictureGrabber pictureGrubber; 49 | 50 | private static final Logger LOGGER = LogManager.getLogger(UploadController.class); 51 | 52 | private static final String REDIRECT_CONTENT_PAGE = "redirect:/"; 53 | 54 | // /** 55 | // * rootPath contains path which will be use to save uploaded pictures 56 | // * */ 57 | // @Value("${data.root.path}") 58 | // private String rootPath; 59 | 60 | @RequestMapping("/") 61 | public String getContent(Map map, 62 | HttpServletRequest request) { 63 | 64 | List pictures = picService.list(pagesService.getShift(), StorageConst.PICTURE_COUNT); 65 | Principal principal = request.getUserPrincipal(); 66 | String userName = null; 67 | 68 | if(principal != null) { 69 | userName = principal.getName(); 70 | } 71 | 72 | AlbumUtils.correctPaths(pictures); 73 | AlbumUtils.setCanDelete(pictures, userName); 74 | 75 | map.put("url", new IncomingURL()); 76 | map.put("pages", pagesService.list()); 77 | map.put("pictures", pictures); 78 | // map.put("authorized", request.isUserInRole(UserRolesTypes.ROLE_USER)); 79 | return "content"; 80 | } 81 | 82 | /** 83 | * redirect to add picture page method 84 | * */ 85 | @RequestMapping("/add") 86 | public String addNew(Map map, 87 | HttpServletRequest request) { 88 | map.put("picture", new Document()); 89 | map.put("url", new IncomingURL()); 90 | // map.put("authorized", request.isUserInRole(UserRolesTypes.ROLE_USER)); 91 | return "upload"; 92 | } 93 | 94 | /** 95 | * method save Picture pic metadata into db and binary into file 96 | * system 97 | * */ 98 | @RequestMapping(value = "/save", method = RequestMethod.POST) 99 | public String save(@ModelAttribute("picture") Document pic, @RequestParam("file") MultipartFile file) { 100 | try { 101 | picService.savePicture(pic, file); 102 | } catch (Exception e) { 103 | LOGGER.error("Error on save occured", e); 104 | return "redirect:/add?error=true"; 105 | } 106 | 107 | return REDIRECT_CONTENT_PAGE; 108 | } 109 | 110 | /** 111 | * delete picture by unique picture ID 112 | * */ 113 | @RequestMapping(value = "/delete/{picId}") 114 | public String deletePicture(@PathVariable("picId") Integer picId) { 115 | picService.removePicture(picId); 116 | return REDIRECT_CONTENT_PAGE; 117 | } 118 | 119 | /** 120 | * redirect to login page 121 | * */ 122 | @RequestMapping(value = "/login") 123 | public String login() { 124 | LOGGER.info("try to login"); 125 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 126 | if (!(auth instanceof AnonymousAuthenticationToken)) { 127 | return "redirect:/"; 128 | } 129 | return "login"; 130 | } 131 | 132 | /** 133 | * Method perform picture grabbind from web-page by incomingURL 134 | * */ 135 | @RequestMapping(value = "/grab") 136 | public String grub(@ModelAttribute("url") String url, 137 | @ModelAttribute("option") int option) { 138 | 139 | try { 140 | pictureGrubber.grub(url, option); 141 | } catch (Exception e) { 142 | LOGGER.error("error during grub occured", e); 143 | return "redirect:/error"; 144 | } 145 | 146 | return REDIRECT_CONTENT_PAGE; 147 | } 148 | 149 | /** 150 | * skip to next page and redirect to pictures page 151 | * */ 152 | @RequestMapping(value = "/nextPage") 153 | public String nextPage() { 154 | pagesService.nextPage(); 155 | return REDIRECT_CONTENT_PAGE; 156 | } 157 | 158 | /** 159 | * skip to previous page and redirect to pictures page 160 | * */ 161 | @RequestMapping(value = "/prevPage") 162 | public String prevPage() { 163 | pagesService.prevPage(); 164 | return REDIRECT_CONTENT_PAGE; 165 | } 166 | 167 | /** 168 | * skip to "index" page and redirect to pictures page 169 | * */ 170 | @RequestMapping(value = "/goto/{index}") 171 | public String gotoPage(@PathVariable("index") Integer index) { 172 | pagesService.setShift(index); 173 | return REDIRECT_CONTENT_PAGE; 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /src/main/resources/create-storage-schema.sql: -------------------------------------------------------------------------------- 1 | DROP DATABASE IF EXISTS webstorage; 2 | CREATE DATABASE webstorage; 3 | 4 | USE webstorage; 5 | 6 | create table users ( 7 | id INT NOT NULL AUTO_INCREMENT, 8 | login VARCHAR(100) NOT NULL, 9 | first_name VARCHAR(100) NOT NULL, 10 | last_name VARCHAR(100) NOT NULL, 11 | email VARCHAR(100) NOT NULL, 12 | pass VARCHAR(100) NOT NULL, 13 | role VARCHAR(100) NOT NULL, 14 | active BOOLEAN NOT NULL DEFAULT 0, 15 | PRIMARY KEY (id) 16 | ) ENGINE=InnoDB; 17 | 18 | create table activation_token ( 19 | token_id INT NOT NULL AUTO_INCREMENT, 20 | token VARCHAR(100) NOT NULL, 21 | expire TIMESTAMP NOT NULL, 22 | verified BOOLEAN NOT NULL DEFAULT 0, 23 | PRIMARY KEY (token_id), 24 | CONSTRAINT FKUSR FOREIGN KEY (token_id) REFERENCES users(id) 25 | ) ENGINE=InnoDB; 26 | 27 | create table documents ( 28 | id INT AUTO_INCREMENT, 29 | pic_owner VARCHAR(100) NOT NULL, 30 | filename VARCHAR(100) NOT NULL, 31 | description VARCHAR(100), 32 | path VARCHAR(100), 33 | thumbnail VARCHAR(100), 34 | created TIMESTAMP NOT NULL, 35 | userid INT NOT NULL, 36 | PRIMARY KEY (id), 37 | FOREIGN KEY (userid) 38 | REFERENCES users(id) 39 | ON DELETE CASCADE 40 | ) ENGINE=InnoDB; 41 | -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %d %p %C{1.} [%t] %m%n 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/main/resources/messages_en.properties: -------------------------------------------------------------------------------- 1 | label.add=Upload 2 | label.grab=Let's Grub!!! 3 | label.addError=Upload error 4 | label.author=Author 5 | label.description=Description 6 | label.name=Name 7 | label.picture=Picture 8 | label.title=Commercial Bank 9 | label.album=Album 10 | label.content=Content 11 | label.delete=Delete 12 | label.registration=Registration 13 | label.logout=Logout 14 | label.login=Login 15 | label.password=Password 16 | label.confirm=Confirm 17 | label.email=Email 18 | label.check=Check 19 | label.capture=Capture 20 | label.loginerror=Login error 21 | label.registererror=Registration error 22 | label.next=Next › 23 | label.prev=‹ Prev 24 | label.begin=‹ ‹ To the top 25 | -------------------------------------------------------------------------------- /src/main/resources/messages_ru.properties: -------------------------------------------------------------------------------- 1 | label.add=\u0417\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0438\u0442\u0438 2 | label.grab=\u0413\u0440\u0430\u0431\u0438\u0442\u044c!!! 3 | label.addError=\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 4 | label.author=\u0410\u0432\u0442\u043e\u0440 5 | label.description=\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 6 | label.name=\u0418\u043c\u044f 7 | label.picture=\u0424\u043e\u0442\u043e 8 | label.title=\u0410\u043b\u044c\u0431\u043e\u043c 9 | label.album=\u0410\u043b\u044c\u0431\u043e\u043c 10 | label.content=\u041a\u043e\u043d\u0442\u0435\u043d\u0442 11 | label.delete=\u0423\u0434\u0430\u043b\u0438\u0442\u044c 12 | label.registration=\u0420\u0435\u0454\u0441\u0442\u0440\u0430\u0446\u0456\u044f 13 | label.logout=\u0412\u0438\u0439\u0442\u0438 14 | label.login=\u0412\u0445\u0456\u0434 15 | label.password=\u041f\u0430\u0440\u043e\u043b\u044c 16 | label.confirm=\u041f\u0456\u0434\u0442\u0432\u0435\u0440\u0434\u0436\u0435\u043d\u043d\u044f 17 | label.email=Email 18 | label.test=\u041f\u0440\u043e\u0432\u0456\u0440\u0438\u0442\u0438 19 | label.capture=Capture 20 | label.loginerror=\u041e\u0448\u0438\u0431\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 21 | label.registererror=\u041e\u0448\u0438\u0431\u043a\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 22 | label.next=\u0421\u043b\u0435\u0434. › 23 | label.prev=‹ \u041f\u0440\u0435\u0434. 24 | label.begin=‹ ‹ \u0412 \u043d\u0430\u0447\u0430\u043b\u043e 25 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/config/email.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | smtp 13 | true 14 | true 15 | true 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/config/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | classpath:email.properties 38 | classpath:jdbc.properties 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | com.bobko.storage.domain 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | ${hibernate.dialect} 76 | 77 | ${hibernate.use_sql_comments} 78 | ${hibernate.auto_close_session} 79 | create 80 | 81 | 82 | 83 | 84 | 85 | 87 | 88 | 89 | 90 | 92 | 93 | 94 | */* 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/config/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/config/security.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/config/servlet-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | 23 | org.springframework.web.servlet.view.tiles3.TilesView 24 | 25 | 26 | 27 | 28 | 29 | 30 | /WEB-INF/config/tiles.xml 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/config/tiles.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/error.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring" %> 4 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 5 | 6 | 7 | 8 | 9 | 404 Page 10 | 11 | 12 |

Page not found

13 | "> 14 | 15 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/footer.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 |

8 | 9 | Twitter 13 | 14 | 18 | Facebook 19 | 20 | 24 | Google+ 25 | 26 | 30 | LinkedIn 31 |

-------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/header.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8"%> 2 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 3 | <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 4 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 5 | <%@taglib uri="http://www.springframework.org/security/tags" prefix="sec"%> 6 | <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 7 | <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%> 8 | 9 | ${req.requestURL} 10 | 11 | 12 | 70 | 96 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf8" 2 | pageEncoding="utf8"%> 3 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 4 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 5 |
6 | 26 |
27 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/main.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8"%> 2 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 3 | <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 4 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 5 | <%@taglib uri="http://www.springframework.org/security/tags" prefix="sec"%> 6 | 7 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/new-password.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8"%> 2 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 3 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%> 5 | <%@ page session="false"%> 6 | 7 |
8 |
9 |
10 | 12 |
13 |
14 | 18 |
19 |
20 | 21 |
22 |
23 |
24 |
25 | 26 |
27 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/pagenation.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 3 | <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 4 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 5 | <%@taglib uri="http://www.springframework.org/security/tags" prefix="sec"%> 6 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 7 |
8 |
9 | 26 |
27 |
28 | 29 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/pictures.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf8" 2 | pageEncoding="utf8"%> 3 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 4 | <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 5 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 6 | <%@taglib uri="http://www.springframework.org/security/tags" 7 | prefix="sec"%> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |

${picture.filename}

17 |
18 |
19 |
20 | 21 | 22 | 23 | ${picture.filename} 24 | 25 | 26 | 27 | 28 | 29 |
30 |

31 | 32 |

33 | 34 | " 35 | data-toggle="modal" data-target="#confirm-delete"> 36 | 37 | 38 | 39 |
40 |
41 |
42 |
43 | 49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | 57 |
58 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/registration-page.jsp: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 7 |
8 |
9 | 12 |
13 |
14 | 17 |
18 |
19 | 22 |
23 |
24 | 26 |
27 |
28 | 32 |
33 |
34 | 36 |
37 |
38 |
39 |
40 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/reset-password.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8"%> 2 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 3 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 |
5 |
6 |
7 | 8 |
9 |
10 | 11 |
12 |
13 |
14 |
15 | 16 | 18 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/anonymous/thankyou.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf8" 2 | pageEncoding="utf8"%> 3 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 4 | <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 5 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 6 | <%@taglib uri="http://www.springframework.org/security/tags" 7 | prefix="sec"%> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/common/layout.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> 2 | <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%> 3 | <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> 4 | <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> 5 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 6 | <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 7 | 8 | ${req.requestURL} 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | " /> 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 56 | 79 | <tiles:insertAttribute name="title" ignore="true" /> 80 | 81 | 82 | 83 | 103 | 111 | 112 | 117 | 118 |
119 | 120 | 121 | 122 |
123 |
124 |
125 | 126 |
127 |
128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/user/upload-file.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf8" 2 | pageEncoding="utf8"%> 3 | <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 4 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 5 | <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 6 |
7 | 9 |
10 | 12 | 13 |
14 |
15 | 16 |
17 |
18 | " 19 | class="btn btn-info btn-block" /> 20 |
21 |
22 |
23 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | contextConfigLocation 8 | 9 | WEB-INF/config/root-context.xml 10 | 11 | 12 | 13 | 14 | org.springframework.web.context.ContextLoaderListener 15 | 16 | 17 | 18 | appServlet 19 | org.springframework.web.servlet.DispatcherServlet 20 | 21 | contextConfigLocation 22 | /WEB-INF/config/servlet-context.xml 23 | 24 | 1 25 | 26 | 27 | 28 | appServlet 29 | / 30 | 31 | 32 | 33 | charsetFilter 34 | org.springframework.web.filter.CharacterEncodingFilter 35 | 36 | encoding 37 | UTF-8 38 | 39 | 40 | forceEncoding 41 | true 42 | 43 | 44 | 45 | charsetFilter 46 | /* 47 | 48 | 49 | 50 | springSecurityFilterChain 51 | 52 | org.springframework.web.filter.DelegatingFilterProxy 53 | 54 | 55 | 56 | springSecurityFilterChain 57 | /* 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 404 66 | /error 67 | 68 | 69 | 70 | 403 71 | /error 72 | 73 | 74 | 75 | 500 76 | /error 77 | 78 | 79 | 80 | 503 81 | /error 82 | 83 | 84 | -------------------------------------------------------------------------------- /src/main/webapp/resources/css/bootstrap-theme.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.3.2 (http://getbootstrap.com) 3 | * Copyright 2011-2015 Twitter, Inc. 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */.btn-danger,.btn-default,.btn-info,.btn-primary,.btn-success,.btn-warning{text-shadow:0 -1px 0 rgba(0,0,0,.2);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075)}.btn-danger.active,.btn-danger:active,.btn-default.active,.btn-default:active,.btn-info.active,.btn-info:active,.btn-primary.active,.btn-primary:active,.btn-success.active,.btn-success:active,.btn-warning.active,.btn-warning:active{-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,.125);box-shadow:inset 0 3px 5px rgba(0,0,0,.125)}.btn-danger .badge,.btn-default .badge,.btn-info .badge,.btn-primary .badge,.btn-success .badge,.btn-warning .badge{text-shadow:none}.btn.active,.btn:active{background-image:none}.btn-default{text-shadow:0 1px 0 #fff;background-image:-webkit-linear-gradient(top,#fff 0,#e0e0e0 100%);background-image:-o-linear-gradient(top,#fff 0,#e0e0e0 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fff),to(#e0e0e0));background-image:linear-gradient(to bottom,#fff 0,#e0e0e0 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe0e0e0', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#dbdbdb;border-color:#ccc}.btn-default:focus,.btn-default:hover{background-color:#e0e0e0;background-position:0 -15px}.btn-default.active,.btn-default:active{background-color:#e0e0e0;border-color:#dbdbdb}.btn-default.disabled,.btn-default:disabled,.btn-default[disabled]{background-color:#e0e0e0;background-image:none}.btn-primary{background-image:-webkit-linear-gradient(top,#337ab7 0,#265a88 100%);background-image:-o-linear-gradient(top,#337ab7 0,#265a88 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#265a88));background-image:linear-gradient(to bottom,#337ab7 0,#265a88 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff265a88', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#245580}.btn-primary:focus,.btn-primary:hover{background-color:#265a88;background-position:0 -15px}.btn-primary.active,.btn-primary:active{background-color:#265a88;border-color:#245580}.btn-primary.disabled,.btn-primary:disabled,.btn-primary[disabled]{background-color:#265a88;background-image:none}.btn-success{background-image:-webkit-linear-gradient(top,#5cb85c 0,#419641 100%);background-image:-o-linear-gradient(top,#5cb85c 0,#419641 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5cb85c),to(#419641));background-image:linear-gradient(to bottom,#5cb85c 0,#419641 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5cb85c', endColorstr='#ff419641', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#3e8f3e}.btn-success:focus,.btn-success:hover{background-color:#419641;background-position:0 -15px}.btn-success.active,.btn-success:active{background-color:#419641;border-color:#3e8f3e}.btn-success.disabled,.btn-success:disabled,.btn-success[disabled]{background-color:#419641;background-image:none}.btn-info{background-image:-webkit-linear-gradient(top,#5bc0de 0,#2aabd2 100%);background-image:-o-linear-gradient(top,#5bc0de 0,#2aabd2 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5bc0de),to(#2aabd2));background-image:linear-gradient(to bottom,#5bc0de 0,#2aabd2 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de', endColorstr='#ff2aabd2', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#28a4c9}.btn-info:focus,.btn-info:hover{background-color:#2aabd2;background-position:0 -15px}.btn-info.active,.btn-info:active{background-color:#2aabd2;border-color:#28a4c9}.btn-info.disabled,.btn-info:disabled,.btn-info[disabled]{background-color:#2aabd2;background-image:none}.btn-warning{background-image:-webkit-linear-gradient(top,#f0ad4e 0,#eb9316 100%);background-image:-o-linear-gradient(top,#f0ad4e 0,#eb9316 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f0ad4e),to(#eb9316));background-image:linear-gradient(to bottom,#f0ad4e 0,#eb9316 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff0ad4e', endColorstr='#ffeb9316', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#e38d13}.btn-warning:focus,.btn-warning:hover{background-color:#eb9316;background-position:0 -15px}.btn-warning.active,.btn-warning:active{background-color:#eb9316;border-color:#e38d13}.btn-warning.disabled,.btn-warning:disabled,.btn-warning[disabled]{background-color:#eb9316;background-image:none}.btn-danger{background-image:-webkit-linear-gradient(top,#d9534f 0,#c12e2a 100%);background-image:-o-linear-gradient(top,#d9534f 0,#c12e2a 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9534f),to(#c12e2a));background-image:linear-gradient(to bottom,#d9534f 0,#c12e2a 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9534f', endColorstr='#ffc12e2a', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#b92c28}.btn-danger:focus,.btn-danger:hover{background-color:#c12e2a;background-position:0 -15px}.btn-danger.active,.btn-danger:active{background-color:#c12e2a;border-color:#b92c28}.btn-danger.disabled,.btn-danger:disabled,.btn-danger[disabled]{background-color:#c12e2a;background-image:none}.img-thumbnail,.thumbnail{-webkit-box-shadow:0 1px 2px rgba(0,0,0,.075);box-shadow:0 1px 2px rgba(0,0,0,.075)}.dropdown-menu>li>a:focus,.dropdown-menu>li>a:hover{background-color:#e8e8e8;background-image:-webkit-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-o-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f5f5f5),to(#e8e8e8));background-image:linear-gradient(to bottom,#f5f5f5 0,#e8e8e8 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#ffe8e8e8', GradientType=0);background-repeat:repeat-x}.dropdown-menu>.active>a,.dropdown-menu>.active>a:focus,.dropdown-menu>.active>a:hover{background-color:#2e6da4;background-image:-webkit-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2e6da4));background-image:linear-gradient(to bottom,#337ab7 0,#2e6da4 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2e6da4', GradientType=0);background-repeat:repeat-x}.navbar-default{background-image:-webkit-linear-gradient(top,#fff 0,#f8f8f8 100%);background-image:-o-linear-gradient(top,#fff 0,#f8f8f8 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fff),to(#f8f8f8));background-image:linear-gradient(to bottom,#fff 0,#f8f8f8 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#fff8f8f8', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-radius:4px;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 5px rgba(0,0,0,.075);box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 5px rgba(0,0,0,.075)}.navbar-default .navbar-nav>.active>a,.navbar-default .navbar-nav>.open>a{background-image:-webkit-linear-gradient(top,#dbdbdb 0,#e2e2e2 100%);background-image:-o-linear-gradient(top,#dbdbdb 0,#e2e2e2 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#dbdbdb),to(#e2e2e2));background-image:linear-gradient(to bottom,#dbdbdb 0,#e2e2e2 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdbdbdb', endColorstr='#ffe2e2e2', GradientType=0);background-repeat:repeat-x;-webkit-box-shadow:inset 0 3px 9px rgba(0,0,0,.075);box-shadow:inset 0 3px 9px rgba(0,0,0,.075)}.navbar-brand,.navbar-nav>li>a{text-shadow:0 1px 0 rgba(255,255,255,.25)}.navbar-inverse{background-image:-webkit-linear-gradient(top,#3c3c3c 0,#222 100%);background-image:-o-linear-gradient(top,#3c3c3c 0,#222 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#3c3c3c),to(#222));background-image:linear-gradient(to bottom,#3c3c3c 0,#222 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff3c3c3c', endColorstr='#ff222222', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x}.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.open>a{background-image:-webkit-linear-gradient(top,#080808 0,#0f0f0f 100%);background-image:-o-linear-gradient(top,#080808 0,#0f0f0f 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#080808),to(#0f0f0f));background-image:linear-gradient(to bottom,#080808 0,#0f0f0f 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff080808', endColorstr='#ff0f0f0f', GradientType=0);background-repeat:repeat-x;-webkit-box-shadow:inset 0 3px 9px rgba(0,0,0,.25);box-shadow:inset 0 3px 9px rgba(0,0,0,.25)}.navbar-inverse .navbar-brand,.navbar-inverse .navbar-nav>li>a{text-shadow:0 -1px 0 rgba(0,0,0,.25)}.navbar-fixed-bottom,.navbar-fixed-top,.navbar-static-top{border-radius:0}@media (max-width:767px){.navbar .navbar-nav .open .dropdown-menu>.active>a,.navbar .navbar-nav .open .dropdown-menu>.active>a:focus,.navbar .navbar-nav .open .dropdown-menu>.active>a:hover{color:#fff;background-image:-webkit-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2e6da4));background-image:linear-gradient(to bottom,#337ab7 0,#2e6da4 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2e6da4', GradientType=0);background-repeat:repeat-x}}.alert{text-shadow:0 1px 0 rgba(255,255,255,.2);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.25),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 1px 0 rgba(255,255,255,.25),0 1px 2px rgba(0,0,0,.05)}.alert-success{background-image:-webkit-linear-gradient(top,#dff0d8 0,#c8e5bc 100%);background-image:-o-linear-gradient(top,#dff0d8 0,#c8e5bc 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#dff0d8),to(#c8e5bc));background-image:linear-gradient(to bottom,#dff0d8 0,#c8e5bc 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdff0d8', endColorstr='#ffc8e5bc', GradientType=0);background-repeat:repeat-x;border-color:#b2dba1}.alert-info{background-image:-webkit-linear-gradient(top,#d9edf7 0,#b9def0 100%);background-image:-o-linear-gradient(top,#d9edf7 0,#b9def0 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9edf7),to(#b9def0));background-image:linear-gradient(to bottom,#d9edf7 0,#b9def0 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9edf7', endColorstr='#ffb9def0', GradientType=0);background-repeat:repeat-x;border-color:#9acfea}.alert-warning{background-image:-webkit-linear-gradient(top,#fcf8e3 0,#f8efc0 100%);background-image:-o-linear-gradient(top,#fcf8e3 0,#f8efc0 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fcf8e3),to(#f8efc0));background-image:linear-gradient(to bottom,#fcf8e3 0,#f8efc0 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcf8e3', endColorstr='#fff8efc0', GradientType=0);background-repeat:repeat-x;border-color:#f5e79e}.alert-danger{background-image:-webkit-linear-gradient(top,#f2dede 0,#e7c3c3 100%);background-image:-o-linear-gradient(top,#f2dede 0,#e7c3c3 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f2dede),to(#e7c3c3));background-image:linear-gradient(to bottom,#f2dede 0,#e7c3c3 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede', endColorstr='#ffe7c3c3', GradientType=0);background-repeat:repeat-x;border-color:#dca7a7}.progress{background-image:-webkit-linear-gradient(top,#ebebeb 0,#f5f5f5 100%);background-image:-o-linear-gradient(top,#ebebeb 0,#f5f5f5 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#ebebeb),to(#f5f5f5));background-image:linear-gradient(to bottom,#ebebeb 0,#f5f5f5 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffebebeb', endColorstr='#fff5f5f5', GradientType=0);background-repeat:repeat-x}.progress-bar{background-image:-webkit-linear-gradient(top,#337ab7 0,#286090 100%);background-image:-o-linear-gradient(top,#337ab7 0,#286090 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#286090));background-image:linear-gradient(to bottom,#337ab7 0,#286090 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff286090', GradientType=0);background-repeat:repeat-x}.progress-bar-success{background-image:-webkit-linear-gradient(top,#5cb85c 0,#449d44 100%);background-image:-o-linear-gradient(top,#5cb85c 0,#449d44 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5cb85c),to(#449d44));background-image:linear-gradient(to bottom,#5cb85c 0,#449d44 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5cb85c', endColorstr='#ff449d44', GradientType=0);background-repeat:repeat-x}.progress-bar-info{background-image:-webkit-linear-gradient(top,#5bc0de 0,#31b0d5 100%);background-image:-o-linear-gradient(top,#5bc0de 0,#31b0d5 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5bc0de),to(#31b0d5));background-image:linear-gradient(to bottom,#5bc0de 0,#31b0d5 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de', endColorstr='#ff31b0d5', GradientType=0);background-repeat:repeat-x}.progress-bar-warning{background-image:-webkit-linear-gradient(top,#f0ad4e 0,#ec971f 100%);background-image:-o-linear-gradient(top,#f0ad4e 0,#ec971f 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f0ad4e),to(#ec971f));background-image:linear-gradient(to bottom,#f0ad4e 0,#ec971f 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff0ad4e', endColorstr='#ffec971f', GradientType=0);background-repeat:repeat-x}.progress-bar-danger{background-image:-webkit-linear-gradient(top,#d9534f 0,#c9302c 100%);background-image:-o-linear-gradient(top,#d9534f 0,#c9302c 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9534f),to(#c9302c));background-image:linear-gradient(to bottom,#d9534f 0,#c9302c 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9534f', endColorstr='#ffc9302c', GradientType=0);background-repeat:repeat-x}.progress-bar-striped{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.list-group{border-radius:4px;-webkit-box-shadow:0 1px 2px rgba(0,0,0,.075);box-shadow:0 1px 2px rgba(0,0,0,.075)}.list-group-item.active,.list-group-item.active:focus,.list-group-item.active:hover{text-shadow:0 -1px 0 #286090;background-image:-webkit-linear-gradient(top,#337ab7 0,#2b669a 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2b669a 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2b669a));background-image:linear-gradient(to bottom,#337ab7 0,#2b669a 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2b669a', GradientType=0);background-repeat:repeat-x;border-color:#2b669a}.list-group-item.active .badge,.list-group-item.active:focus .badge,.list-group-item.active:hover .badge{text-shadow:none}.panel{-webkit-box-shadow:0 1px 2px rgba(0,0,0,.05);box-shadow:0 1px 2px rgba(0,0,0,.05)}.panel-default>.panel-heading{background-image:-webkit-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-o-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f5f5f5),to(#e8e8e8));background-image:linear-gradient(to bottom,#f5f5f5 0,#e8e8e8 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#ffe8e8e8', GradientType=0);background-repeat:repeat-x}.panel-primary>.panel-heading{background-image:-webkit-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2e6da4));background-image:linear-gradient(to bottom,#337ab7 0,#2e6da4 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2e6da4', GradientType=0);background-repeat:repeat-x}.panel-success>.panel-heading{background-image:-webkit-linear-gradient(top,#dff0d8 0,#d0e9c6 100%);background-image:-o-linear-gradient(top,#dff0d8 0,#d0e9c6 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#dff0d8),to(#d0e9c6));background-image:linear-gradient(to bottom,#dff0d8 0,#d0e9c6 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdff0d8', endColorstr='#ffd0e9c6', GradientType=0);background-repeat:repeat-x}.panel-info>.panel-heading{background-image:-webkit-linear-gradient(top,#d9edf7 0,#c4e3f3 100%);background-image:-o-linear-gradient(top,#d9edf7 0,#c4e3f3 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9edf7),to(#c4e3f3));background-image:linear-gradient(to bottom,#d9edf7 0,#c4e3f3 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9edf7', endColorstr='#ffc4e3f3', GradientType=0);background-repeat:repeat-x}.panel-warning>.panel-heading{background-image:-webkit-linear-gradient(top,#fcf8e3 0,#faf2cc 100%);background-image:-o-linear-gradient(top,#fcf8e3 0,#faf2cc 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fcf8e3),to(#faf2cc));background-image:linear-gradient(to bottom,#fcf8e3 0,#faf2cc 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcf8e3', endColorstr='#fffaf2cc', GradientType=0);background-repeat:repeat-x}.panel-danger>.panel-heading{background-image:-webkit-linear-gradient(top,#f2dede 0,#ebcccc 100%);background-image:-o-linear-gradient(top,#f2dede 0,#ebcccc 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f2dede),to(#ebcccc));background-image:linear-gradient(to bottom,#f2dede 0,#ebcccc 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede', endColorstr='#ffebcccc', GradientType=0);background-repeat:repeat-x}.well{background-image:-webkit-linear-gradient(top,#e8e8e8 0,#f5f5f5 100%);background-image:-o-linear-gradient(top,#e8e8e8 0,#f5f5f5 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#e8e8e8),to(#f5f5f5));background-image:linear-gradient(to bottom,#e8e8e8 0,#f5f5f5 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffe8e8e8', endColorstr='#fff5f5f5', GradientType=0);background-repeat:repeat-x;border-color:#dcdcdc;-webkit-box-shadow:inset 0 1px 3px rgba(0,0,0,.05),0 1px 0 rgba(255,255,255,.1);box-shadow:inset 0 1px 3px rgba(0,0,0,.05),0 1px 0 rgba(255,255,255,.1)} -------------------------------------------------------------------------------- /src/main/webapp/resources/css/default.css: -------------------------------------------------------------------------------- 1 | @CHARSET "UTF-8"; 2 | 3 | .navbar-btn { 4 | margin-left: 4px; 5 | margin-right: 4px; 6 | } 7 | 8 | .container .text-muted { 9 | margin: 13px 0; 10 | } 11 | 12 | .centered-form { 13 | margin-top: 60px; 14 | } 15 | 16 | @media (min-width: 470px) { 17 | .container { 18 | max-width: 410px; 19 | } 20 | } 21 | .signup-button { 22 | -moz-box-shadow:inset 0px 1px 0px 0px #bee2f9; 23 | -webkit-box-shadow:inset 0px 1px 0px 0px #bee2f9; 24 | box-shadow:inset 0px 1px 0px 0px #bee2f9; 25 | background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #63b8ee), color-stop(1, #468ccf)); 26 | background:-moz-linear-gradient(top, #63b8ee 5%, #468ccf 100%); 27 | background:-webkit-linear-gradient(top, #63b8ee 5%, #468ccf 100%); 28 | background:-o-linear-gradient(top, #63b8ee 5%, #468ccf 100%); 29 | background:-ms-linear-gradient(top, #63b8ee 5%, #468ccf 100%); 30 | background:linear-gradient(to bottom, #63b8ee 5%, #468ccf 100%); 31 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#63b8ee', endColorstr='#468ccf',GradientType=0); 32 | background-color:#63b8ee; 33 | -moz-border-radius:6px; 34 | -webkit-border-radius:6px; 35 | border-radius:6px; 36 | border:1px solid #3866a3; 37 | display:inline-block; 38 | cursor:pointer; 39 | color:#14396a; 40 | font-family:Arial; 41 | font-size:15px; 42 | font-weight:bold; 43 | padding:6px 24px; 44 | text-decoration:none; 45 | text-shadow:0px 1px 0px #7cacde; 46 | } 47 | .signup-button:hover { 48 | background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #468ccf), color-stop(1, #63b8ee)); 49 | background:-moz-linear-gradient(top, #468ccf 5%, #63b8ee 100%); 50 | background:-webkit-linear-gradient(top, #468ccf 5%, #63b8ee 100%); 51 | background:-o-linear-gradient(top, #468ccf 5%, #63b8ee 100%); 52 | background:-ms-linear-gradient(top, #468ccf 5%, #63b8ee 100%); 53 | background:linear-gradient(to bottom, #468ccf 5%, #63b8ee 100%); 54 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#468ccf', endColorstr='#63b8ee',GradientType=0); 55 | background-color:#468ccf; 56 | } 57 | .signup-button:active { 58 | position:relative; 59 | top:1px; 60 | } 61 | 62 | .signin-button { 63 | -moz-box-shadow:inset 0px 1px 0px 0px #caefab; 64 | -webkit-box-shadow:inset 0px 1px 0px 0px #caefab; 65 | box-shadow:inset 0px 1px 0px 0px #caefab; 66 | background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #77d42a), color-stop(1, #5cb811)); 67 | background:-moz-linear-gradient(top, #77d42a 5%, #5cb811 100%); 68 | background:-webkit-linear-gradient(top, #77d42a 5%, #5cb811 100%); 69 | background:-o-linear-gradient(top, #77d42a 5%, #5cb811 100%); 70 | background:-ms-linear-gradient(top, #77d42a 5%, #5cb811 100%); 71 | background:linear-gradient(to bottom, #77d42a 5%, #5cb811 100%); 72 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#77d42a', endColorstr='#5cb811',GradientType=0); 73 | background-color:#77d42a; 74 | -moz-border-radius:6px; 75 | -webkit-border-radius:6px; 76 | border-radius:6px; 77 | border:1px solid #268a16; 78 | display:inline-block; 79 | cursor:pointer; 80 | color:#306108; 81 | font-family:Arial; 82 | font-size:15px; 83 | font-weight:bold; 84 | padding:6px 24px; 85 | text-decoration:none; 86 | text-shadow:0px 1px 0px #aade7c; 87 | } 88 | .signin-button:hover { 89 | background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #5cb811), color-stop(1, #77d42a)); 90 | background:-moz-linear-gradient(top, #5cb811 5%, #77d42a 100%); 91 | background:-webkit-linear-gradient(top, #5cb811 5%, #77d42a 100%); 92 | background:-o-linear-gradient(top, #5cb811 5%, #77d42a 100%); 93 | background:-ms-linear-gradient(top, #5cb811 5%, #77d42a 100%); 94 | background:linear-gradient(to bottom, #5cb811 5%, #77d42a 100%); 95 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#5cb811', endColorstr='#77d42a',GradientType=0); 96 | background-color:#5cb811; 97 | } 98 | .signin-button:active { 99 | position:relative; 100 | top:1px; 101 | } 102 | 103 | .panel-heading h3 { 104 | white-space: nowrap; 105 | overflow: hidden; 106 | text-overflow: ellipsis; 107 | line-height: normal; 108 | width: 75%; 109 | padding-top: 8px; 110 | } 111 | 112 | .panel { 113 | border: 0; 114 | } 115 | 116 | .table > thead > tr > th, .table > thead > tr > td { 117 | border: 0; 118 | } 119 | 120 | .borderless li { 121 | border: none; 122 | } 123 | 124 | .elipsis-box { 125 | white-space: nowrap; 126 | overflow: hidden; 127 | text-overflow: ellipsis; 128 | } 129 | -------------------------------------------------------------------------------- /src/main/webapp/resources/css/social-sharing.css: -------------------------------------------------------------------------------- 1 | .btn-twitter { 2 | background: #00acee; 3 | border-radius: 0; 4 | color: #fff 5 | } 6 | .btn-twitter:link, .btn-twitter:visited { 7 | color: #fff 8 | } 9 | .btn-twitter:active, .btn-twitter:hover { 10 | background: #0087bd; 11 | color: #fff 12 | } 13 | .btn-facebook { 14 | background: #3b5998; 15 | border-radius: 0; 16 | color: #fff 17 | } 18 | .btn-facebook:link, .btn-facebook:visited { 19 | color: #fff 20 | } 21 | .btn-facebook:active, .btn-facebook:hover { 22 | background: #30477a; 23 | color: #fff 24 | } 25 | .btn-googleplus { 26 | background: #e93f2e; 27 | border-radius: 0; 28 | color: #fff 29 | } 30 | .btn-googleplus:link, .btn-googleplus:visited { 31 | color: #fff 32 | } 33 | .btn-googleplus:active, .btn-googleplus:hover { 34 | background: #ba3225; 35 | color: #fff 36 | } 37 | .btn-stumbleupon { 38 | background: #f74425; 39 | border-radius: 0; 40 | color: #fff 41 | } 42 | .btn-stumbleupon:link, .btn-stumbleupon:visited { 43 | color: #fff 44 | } 45 | .btn-stumbleupon:active, .btn-stumbleupon:hover { 46 | background: #c7371e; 47 | color: #fff 48 | } 49 | .btn-linkedin { 50 | background: #0e76a8; 51 | border-radius: 0; 52 | color: #fff 53 | } 54 | .btn-linkedin:link, .btn-linkedin:visited { 55 | color: #fff 56 | } 57 | .btn-linkedin:active, .btn-linkedin:hover { 58 | background: #0b6087; 59 | color: #fff 60 | } -------------------------------------------------------------------------------- /src/main/webapp/resources/css/sticky-footer-navbar.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer styles 2 | -------------------------------------------------- */ 3 | html { 4 | position: relative; 5 | min-height: 100%; 6 | } 7 | body { 8 | /* Margin bottom by footer height */ 9 | margin-bottom: 60px; 10 | } 11 | .footer { 12 | position: absolute; 13 | bottom: 0; 14 | width: 100%; 15 | /* Set the fixed height of the footer here */ 16 | height: 60px; 17 | background-color: #f5f5f5; 18 | } 19 | 20 | 21 | /* Custom page CSS 22 | -------------------------------------------------- */ 23 | /* Not required for template or sticky footer method. */ 24 | 25 | body > .container { 26 | padding: 60px 15px 0; 27 | } 28 | .container .text-muted { 29 | margin: 20px 0; 30 | } 31 | 32 | .footer > .container { 33 | padding-right: 15px; 34 | padding-left: 15px; 35 | } 36 | 37 | code { 38 | font-size: 80%; 39 | } 40 | -------------------------------------------------------------------------------- /src/main/webapp/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/favicon.ico -------------------------------------------------------------------------------- /src/main/webapp/resources/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/main/webapp/resources/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/main/webapp/resources/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/main/webapp/resources/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /src/main/webapp/resources/images/canvas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/canvas.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/close.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/closeX.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/closeX.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/close_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/close_img.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/controlbar-black-border.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/controlbar-black-border.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/controlbar-text-buttons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/controlbar-text-buttons.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/controlbar-white-small.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/controlbar-white-small.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/controlbar-white.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/controlbar-white.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/controlbar2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/controlbar2.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/controlbar3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/controlbar3.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/controlbar4-hover.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/controlbar4-hover.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/controlbar4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/controlbar4.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/fullexpand.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/fullexpand.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/geckodimmer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/geckodimmer.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/icon-remove.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/icon-remove.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/icon.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/loader.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/loader.white.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/loader.white.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/logo.jpg -------------------------------------------------------------------------------- /src/main/webapp/resources/images/outlines/beveled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/outlines/beveled.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/outlines/drop-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/outlines/drop-shadow.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/outlines/glossy-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/outlines/glossy-dark.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/outlines/outer-glow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/outlines/outer-glow.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/outlines/rounded-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/outlines/rounded-black.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/outlines/rounded-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/outlines/rounded-white.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/resize.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/resize.gif -------------------------------------------------------------------------------- /src/main/webapp/resources/images/scrollarrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/scrollarrows.png -------------------------------------------------------------------------------- /src/main/webapp/resources/images/zoomin.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/zoomin.cur -------------------------------------------------------------------------------- /src/main/webapp/resources/images/zoomout.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oleksiiBobko/web-storage/d3251638c7663c9e0c0004a0e9c7fb64615dc7bb/src/main/webapp/resources/images/zoomout.cur -------------------------------------------------------------------------------- /src/main/webapp/resources/js/default.js: -------------------------------------------------------------------------------- 1 | function validate(form) { 2 | var e = form.elements; 3 | if (e['confirm-password'].value != document.getElementById('password').value) { 4 | alert('Your passwords do not match. Please type more carefully.'); 5 | return false; 6 | } 7 | 8 | return true; 9 | } 10 | 11 | /*function setRelativelySize(img) { 12 | if(img.height > 300) { 13 | img.style.height = '300px'; 14 | img.style.width = 'auto'; 15 | } else if (img.width > 300) { 16 | img.style.height = 'auto'; 17 | img.style.width = '300px'; 18 | } 19 | }*/ 20 | 21 | $(document).ready(function() { 22 | $(".submit_form").submit(function(event) { 23 | var postData = $(this).serializeArray(); 24 | var formURL = $(this).attr('action'); 25 | var method = $(this).attr('method'); 26 | $.ajax({ 27 | type: method, 28 | url: formURL, 29 | data: postData, 30 | success: function(data, textStatus, jqXHR) { 31 | console.log('success'); 32 | if(jqXHR.status === 200) { 33 | $('.result').html(''); 34 | window.setTimeout(function () { 35 | $(".alert").fadeTo(500, 0).slideUp(500, function () { 36 | $(this).remove(); 37 | }); 38 | }, 5000); 39 | } 40 | }, 41 | error: function(jqXHR, textStatus, errorThrown) { 42 | console.log(jqXHR); 43 | $('.result').html(''); 44 | window.setTimeout(function () { 45 | $(".alert").fadeTo(500, 0).slideUp(500, function () { 46 | $(this).remove(); 47 | }); 48 | }, 5000); 49 | } 50 | }); 51 | return false; 52 | }); 53 | 54 | }); -------------------------------------------------------------------------------- /src/test/java/com/bobko/storage/dao/PageHolderDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.mockito.InjectMocks; 8 | import org.mockito.MockitoAnnotations; 9 | 10 | import com.bobko.storage.dao.PageHolderDao; 11 | 12 | public class PageHolderDaoTest { 13 | 14 | @InjectMocks 15 | private PageHolderDao holder; 16 | 17 | @Before 18 | public void initTest() { 19 | MockitoAnnotations.initMocks(this); 20 | } 21 | 22 | @Test 23 | public void shiftShoulBeZerotest() { 24 | assertEquals(0, holder.getShift()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/bobko/storage/dao/PictureDAOTest.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | public class PictureDAOTest { 8 | 9 | @Test 10 | public void test() { 11 | //fail("Not yet implemented"); 12 | assertTrue("All ok", true); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/bobko/storage/dao/UserDAOTest.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.dao; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | public class UserDAOTest { 8 | 9 | @Test 10 | public void test() { 11 | //fail("Not yet implemented"); 12 | assertTrue("All ok", true); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/bobko/storage/service/PagesServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service; 2 | 3 | import static org.junit.Assert.*; 4 | import static org.mockito.Mockito.*; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.mockito.InjectMocks; 9 | import org.mockito.Mock; 10 | import org.mockito.MockitoAnnotations; 11 | 12 | import com.bobko.storage.dao.interfaces.IPagesHolderDao; 13 | 14 | public class PagesServiceTest { 15 | 16 | @Mock 17 | private IPagesHolderDao pagesDao; 18 | 19 | @InjectMocks 20 | private PagesService pagesService; 21 | 22 | @Before 23 | public void initTest() { 24 | MockitoAnnotations.initMocks(this); 25 | } 26 | 27 | @Test 28 | public void test() { 29 | when(pagesDao.getShift()).thenReturn(4); 30 | assertEquals(pagesService.getShift(), 4); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/bobko/storage/service/test/PictureServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | public class PictureServiceTest { 8 | 9 | @Test 10 | public void test() { 11 | 12 | //fail("Not yet implemented"); 13 | assertTrue("All ok", true); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/bobko/storage/service/test/UserDetailsServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | public class UserDetailsServiceTest { 8 | 9 | @Test 10 | public void test() { 11 | //fail("Not yet implemented"); 12 | assertTrue("All ok", true); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/bobko/storage/service/test/UserServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.bobko.storage.service.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | public class UserServiceTest { 8 | 9 | @Test 10 | public void test() { 11 | //fail("Not yet implemented"); 12 | assertTrue("All ok", true); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/bobko/storage/web/RegistrationControllerTest.java: -------------------------------------------------------------------------------- 1 | //package com.bobko.storage.web; 2 | // 3 | //import static org.mockito.Mockito.when; 4 | //import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 5 | //import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 6 | // 7 | //import org.junit.Before; 8 | //import org.junit.Test; 9 | //import org.junit.runner.RunWith; 10 | //import org.mockito.InjectMocks; 11 | //import org.mockito.Mock; 12 | //import org.mockito.MockitoAnnotations; 13 | //import org.springframework.beans.factory.annotation.Autowired; 14 | //import org.springframework.test.context.ContextConfiguration; 15 | //import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | //import org.springframework.test.context.web.WebAppConfiguration; 17 | //import org.springframework.test.web.servlet.MockMvc; 18 | //import org.springframework.test.web.servlet.RequestBuilder; 19 | //import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; 20 | //import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 21 | //import org.springframework.test.web.servlet.setup.MockMvcBuilders; 22 | //import org.springframework.web.context.WebApplicationContext; 23 | // 24 | //import com.bobko.storage.domain.Users; 25 | //import com.bobko.storage.service.interfaces.IPictureService; 26 | //import com.bobko.storage.service.interfaces.IUserService; 27 | // 28 | //@RunWith(SpringJUnit4ClassRunner.class) 29 | //@ContextConfiguration(locations = {"classpath:test-context.xml", "classpath:application-context.xml"}) 30 | //@WebAppConfiguration 31 | //public class RegistrationControllerTest { 32 | // 33 | // @Mock 34 | // private Users newUser; 35 | // 36 | // @Mock 37 | // private Users existsUser; 38 | // 39 | // @Mock 40 | // private IUserService userService; 41 | // 42 | // @Mock 43 | // private IPictureService picService; 44 | // 45 | // @InjectMocks 46 | // private RegistrationController registrationController; 47 | // 48 | // @Autowired 49 | // private WebApplicationContext wac; 50 | // 51 | // private MockMvc mockMvc; 52 | // 53 | // private static final String SECRET = "1111"; 54 | // 55 | // private static final String LOGIN = "alex"; 56 | // 57 | // @Before 58 | // public void setup() { 59 | // MockitoAnnotations.initMocks(this); 60 | // 61 | // when(existsUser.getLogin()).thenReturn(LOGIN); 62 | // when(existsUser.isActive()).thenReturn(Boolean.TRUE); 63 | // when(existsUser.getRole()).thenReturn(IUserService.ROLE_ADMIN); 64 | // when(existsUser.getPw()).thenReturn(SECRET); 65 | // 66 | // when(userService.getUser("alex")).thenReturn(newUser); 67 | // mockMvc = MockMvcBuilders.standaloneSetup(registrationController).build(); 68 | // } 69 | // 70 | //// @Test 71 | //// public void getHomeTest() { 72 | //// try { 73 | //// mockMvc.perform(get("/")) 74 | //// .andExpect(status().isOk()); 75 | //// } catch (Exception e) { 76 | //// e.printStackTrace(); 77 | //// } 78 | //// } 79 | // 80 | // @Test 81 | // public void testCreateNewUser() throws Exception { 82 | // 83 | // MockHttpServletRequestBuilder requBuilder = MockMvcRequestBuilders.post("/adduser"). 84 | // param("pw", "1111"). 85 | // param("login", "alex"); 86 | // mockMvc.perform(requBuilder). 87 | // andExpect(status().isFound()). 88 | // andExpect(view().name("redirect:/login")); 89 | // } 90 | // 91 | // @Test 92 | // public void testRegistrationPage() throws Exception { 93 | // 94 | // RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/registration"); 95 | // 96 | // mockMvc.perform(requestBuilder). 97 | // andExpect(status().isOk()). 98 | // andExpect(model().size(1)). 99 | // andExpect(view().name("registrationPage")); 100 | // } 101 | // 102 | //} -------------------------------------------------------------------------------- /src/test/java/com/bobko/storage/web/UploadControllerTest.java: -------------------------------------------------------------------------------- 1 | //package com.bobko.storage.web; 2 | // 3 | //import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 4 | // 5 | //import java.util.ArrayList; 6 | //import java.util.List; 7 | // 8 | //import org.junit.Before; 9 | //import org.junit.Test; 10 | //import org.junit.runner.RunWith; 11 | //import org.mockito.InjectMocks; 12 | //import org.mockito.Mock; 13 | //import org.mockito.Mockito; 14 | //import org.mockito.MockitoAnnotations; 15 | //import org.springframework.beans.factory.annotation.Autowired; 16 | //import org.springframework.mock.web.MockMultipartFile; 17 | //import org.springframework.mock.web.MockMultipartHttpServletRequest; 18 | //import org.springframework.test.context.ContextConfiguration; 19 | //import org.springframework.test.context.TestExecutionListeners; 20 | //import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 21 | //import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; 22 | //import org.springframework.test.context.web.WebAppConfiguration; 23 | //import org.springframework.test.web.servlet.MockMvc; 24 | //import org.springframework.test.web.servlet.RequestBuilder; 25 | //import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; 26 | //import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 27 | //import org.springframework.test.web.servlet.setup.MockMvcBuilders; 28 | //import org.springframework.web.context.WebApplicationContext; 29 | // 30 | //import com.bobko.storage.common.StorageConst; 31 | //import com.bobko.storage.domain.AlbumPage; 32 | //import com.bobko.storage.domain.Picture; 33 | //import com.bobko.storage.service.PictureService; 34 | //import com.bobko.storage.service.interfaces.IPagesService; 35 | //import com.bobko.storage.service.interfaces.IUserService; 36 | // 37 | //@RunWith(SpringJUnit4ClassRunner.class) 38 | //@WebAppConfiguration 39 | //@ContextConfiguration(locations = {"classpath:test-context.xml", "classpath:application-context.xml"}) 40 | //@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class}) 41 | //public class UploadControllerTest { 42 | // 43 | // private Picture picture; 44 | // private List pictures; 45 | // private List pages; 46 | // 47 | // @Autowired 48 | // private WebApplicationContext wac; 49 | // 50 | // private MockMvc mockMvc; 51 | // 52 | // @InjectMocks 53 | // private UploadController uploadController; 54 | // 55 | // @Mock 56 | // private PictureService pictureService; 57 | // 58 | // @Mock 59 | // private IPagesService pagesService; 60 | // 61 | // @Mock 62 | // private IUserService userService; 63 | // 64 | // @Before 65 | // public void setup() { 66 | // 67 | // MockitoAnnotations.initMocks(this); 68 | // 69 | // pictures = new ArrayList(); 70 | // picture = new Picture(); 71 | // 72 | // picture.setDescription("on vocation"); 73 | // picture.setFilename("1.jpg"); 74 | // picture.setId(3); 75 | // picture.setOwner("alex"); 76 | // picture.setPath("/1/2"); 77 | // 78 | // Picture picture2 = new Picture(); 79 | // 80 | // picture2.setDescription("description2"); 81 | // picture2.setFilename("2.jpg"); 82 | // picture2.setId(4); 83 | // picture2.setOwner("alex1"); 84 | // picture2.setPath("/2/3"); 85 | // 86 | // pictures.add(picture); 87 | // pictures.add(picture2); 88 | // 89 | // Mockito.when(pictureService.list(0, StorageConst.PICTURE_COUNT)).thenReturn(pictures); 90 | // 91 | // pages = new ArrayList(); 92 | // pages.add(new AlbumPage(0, true)); 93 | // pages.add(new AlbumPage(1, false)); 94 | // Mockito.when(pagesService.list()).thenReturn(pages); 95 | // 96 | // this.mockMvc = MockMvcBuilders.standaloneSetup(uploadController).build(); 97 | // 98 | // } 99 | // 100 | // @Test 101 | // public void testPictures() throws Exception { 102 | // 103 | //// RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/content"); 104 | //// 105 | //// mockMvc.perform(requestBuilder).andExpect(status().isOk()); 106 | //// 107 | //// mockMvc.perform(requestBuilder). 108 | //// andExpect(status().isOk()). 109 | //// andExpect(model().attribute("pictures", pictures)). 110 | //// andExpect(model().attribute("pages", pages)). 111 | //// andExpect(model().size(4)). 112 | //// andExpect(view().name("pictures-list")); 113 | // } 114 | // 115 | //// @Test 116 | // public void testHome() throws Exception { 117 | // RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/"); 118 | // mockMvc.perform(requestBuilder).andExpect(status().isFound()).andExpect(view().name("redirect:/")); 119 | // } 120 | // 121 | // @Test 122 | // public void testAddNew() throws Exception { 123 | // RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/add"); 124 | // mockMvc.perform(requestBuilder).andExpect(status().isOk()).andExpect(view().name("upload")); 125 | // } 126 | // 127 | // @Test 128 | // public void testSave() throws Exception { 129 | // 130 | // MockMultipartHttpServletRequest multipartRequest = new MockMultipartHttpServletRequest(); 131 | // MockMultipartFile mockMultipartFile = new MockMultipartFile("file", "orig", null, "bar".getBytes()); 132 | // multipartRequest.addFile(mockMultipartFile); 133 | // MockMultipartHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.fileUpload("/save").file(mockMultipartFile); 134 | // 135 | // requestBuilder. 136 | // param("owner", "alex"). 137 | // param("description", "on vocation"). 138 | // param("filename", "1.jpg"); 139 | // 140 | // mockMvc.perform(requestBuilder).andExpect(status().isFound()).andExpect(view().name("redirect:/")); 141 | // } 142 | // 143 | // @Test 144 | // public void testGetPicture() throws Exception { 145 | // 146 | // } 147 | // 148 | // @Test 149 | // public void testDeletePicture() throws Exception { 150 | // 151 | // } 152 | // 153 | // @Test 154 | // public void testLogin() throws Exception { 155 | // 156 | // } 157 | // 158 | // @Test 159 | // public void testGrabb() throws Exception { 160 | // 161 | // } 162 | // 163 | // @Test 164 | // public void testNextPage() throws Exception { 165 | // 166 | // } 167 | // 168 | // @Test 169 | // public void testPrevPage() throws Exception { 170 | // 171 | // } 172 | // 173 | // @Test 174 | // public void testGoToPage() throws Exception { 175 | // 176 | // } 177 | // 178 | //} -------------------------------------------------------------------------------- /src/test/resources/application-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | error/error 24 | error/error 25 | 26 | 27 | 28 | 29 | 404 30 | 500 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/test/resources/test-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | --------------------------------------------------------------------------------