diff options
-rw-r--r-- | juick-server/src/main/java/com/juick/server/security/entities/AnonymUser.java (renamed from juick-server/src/main/java/com/juick/entity/AnonymUser.java) | 3 | ||||
-rw-r--r-- | juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java | 18 | ||||
-rw-r--r-- | juick-server/src/main/java/com/juick/util/UserUtils.java | 2 | ||||
-rw-r--r-- | juick-spring-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java | 5 | ||||
-rw-r--r-- | juick-spring-www/src/main/resources/messages.properties | 4 | ||||
-rw-r--r-- | juick-spring-www/src/main/resources/messages_en.properties | 6 | ||||
-rw-r--r-- | juick-spring-www/src/main/webapp/WEB-INF/templates/index.html | 6 | ||||
-rw-r--r-- | juick-spring-www/src/main/webapp/WEB-INF/templates/layout/partial/navigation.html | 8 |
8 files changed, 35 insertions, 17 deletions
diff --git a/juick-server/src/main/java/com/juick/entity/AnonymUser.java b/juick-server/src/main/java/com/juick/server/security/entities/AnonymUser.java index ad14dd30..2cc692a2 100644 --- a/juick-server/src/main/java/com/juick/entity/AnonymUser.java +++ b/juick-server/src/main/java/com/juick/server/security/entities/AnonymUser.java @@ -1,4 +1,4 @@ -package com.juick.entity; +package com.juick.server.security.entities; import com.juick.User; @@ -8,7 +8,6 @@ import com.juick.User; public final class AnonymUser extends User { public static final AnonymUser INSTANCE = new AnonymUser(); - private AnonymUser() { super.setUid(getUid()); super.setName(getName()); diff --git a/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java b/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java index f6d27ddf..596c95d1 100644 --- a/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java +++ b/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java @@ -7,23 +7,35 @@ import org.springframework.security.core.userdetails.UserDetails; import java.util.Collection; import java.util.Collections; +import java.util.List; /** * Created by aalexeev on 11/21/16. */ public class JuickUser implements UserDetails { - public static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER"); - public static final Collection<? extends GrantedAuthority> USER_AUTHORITY = Collections.singletonList(ROLE_USER); + static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER"); + static final GrantedAuthority ROLE_ANONYM = new SimpleGrantedAuthority("ROLE_ANONYM"); + + public static final List<GrantedAuthority> USER_AUTHORITY = Collections.singletonList(ROLE_USER); + public static final List<GrantedAuthority> ANONYM_AUTHORITY = Collections.singletonList(ROLE_ANONYM); + + public static final JuickUser ANONYM_USER = new JuickUser(AnonymUser.INSTANCE, ANONYM_AUTHORITY); private final com.juick.User user; + private final Collection<? extends GrantedAuthority> authorities; public JuickUser(com.juick.User user) { + this(user, USER_AUTHORITY); + } + + public JuickUser(com.juick.User user, Collection<? extends GrantedAuthority> authorities) { this.user = user; + this.authorities = authorities; } @Override public Collection<? extends GrantedAuthority> getAuthorities() { - return USER_AUTHORITY; + return authorities; } @Override diff --git a/juick-server/src/main/java/com/juick/util/UserUtils.java b/juick-server/src/main/java/com/juick/util/UserUtils.java index ddeedbbd..8be415c9 100644 --- a/juick-server/src/main/java/com/juick/util/UserUtils.java +++ b/juick-server/src/main/java/com/juick/util/UserUtils.java @@ -1,7 +1,7 @@ package com.juick.util; import com.juick.User; -import com.juick.entity.AnonymUser; +import com.juick.server.security.entities.AnonymUser; import com.juick.server.security.entities.JuickUser; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java index d10f2532..692cf8cc 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java @@ -1,6 +1,6 @@ package com.juick.www.configuration; -import com.juick.entity.AnonymUser; +import com.juick.server.security.entities.JuickUser; import com.juick.service.UserService; import com.juick.service.security.JuickUserDetailsService; import org.springframework.context.annotation.Bean; @@ -9,7 +9,6 @@ import org.springframework.core.env.Environment; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.userdetails.UserDetailsService; import javax.annotation.Resource; @@ -38,7 +37,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers("/settings", "/pm/**").authenticated() .anyRequest().permitAll() .and() - .anonymous().principal(AnonymUser.INSTANCE) + .anonymous().principal(JuickUser.ANONYM_USER).authorities(JuickUser.ANONYM_AUTHORITY) .and() .sessionManagement().invalidSessionUrl("/") .and() diff --git a/juick-spring-www/src/main/resources/messages.properties b/juick-spring-www/src/main/resources/messages.properties index 201c1f2c..42494512 100644 --- a/juick-spring-www/src/main/resources/messages.properties +++ b/juick-spring-www/src/main/resources/messages.properties @@ -31,4 +31,6 @@ message.sendLoginToXmpp=Отправьте <b>LOGIN</b> на <a href="xmpp:juick question.areRegistered=Уже зарегистрированы? title.help=Справка -title.loginOrSignup=Juick - Войдите в систему или зарегистрируйтесь
\ No newline at end of file +title.loginOrSignup=Juick - Войдите в систему или зарегистрируйтесь +title.index.anonym=Микроблоги Juick: популярные записи +title.index.user=Популярные
\ No newline at end of file diff --git a/juick-spring-www/src/main/resources/messages_en.properties b/juick-spring-www/src/main/resources/messages_en.properties index cbd3b5f9..fd1e17e0 100644 --- a/juick-spring-www/src/main/resources/messages_en.properties +++ b/juick-spring-www/src/main/resources/messages_en.properties @@ -1,7 +1,7 @@ date.format=MM/dd/yyyy link.settings=Settings -link.returnToMain=Return to home +link.returnToMain=Back to Home Page link.contacts=Contacts link.help=Help link.adv=Advertisement @@ -31,4 +31,6 @@ message.sendLoginToXmpp=Send <b>LOGIN</b> to <a href="xmpp:juick@juick.com?messa question.areRegistered=Are you registered? title.help=Help -title.loginOrSignup=Juick - Log In or Sign Up
\ No newline at end of file +title.loginOrSignup=Juick - Log In or Sign Up +title.index.anonym=Juick microblogs: popular posts +title.index.user=Popular
\ No newline at end of file diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html index 4cd32be3..7ee2156d 100644 --- a/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html +++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html @@ -3,12 +3,16 @@ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{layout/mainLayout}"> <head> - <title>Главная страница</title> + <title th:if="${#authorization.expression('hasRole(''ROLE_USER'')')}" th:text="#{title.index.user}">Популярные</title> + <title th:if="${#authorization.expression('hasRole(''ROLE_ANONYM'')')}" th:text="#{title.index.anonym}">Микроблоги Juick: популярные записи</title> </head> <body> <section layout:fragment="content"> <p>Главная страница !</p> + <p th:text="${#authorization.expression('hasRole(''ROLE_USER'')')}"></p> + <p th:text="${#authorization.expression('hasRole(''ROLE_ANONYM'')')}"></p> + <p th:text="${#authentication}"></p> </section> <aside id="column"> <p layout:fragment="column"></p> diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/partial/navigation.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/partial/navigation.html index 95714e10..c7cd1c81 100644 --- a/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/partial/navigation.html +++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/partial/navigation.html @@ -20,8 +20,8 @@ th:value="${param.search}"/> </form> </div> - <section id="headdiv" th:switch="${visitor.isAnonym()}"> - <th:block th:case="false"> + <section id="headdiv"> + <th:block th:if="${#authorization.expression('hasRole(''ROLE_USER'')')}"> <nav id="user"> <ul> <li><a href="/?show=my" th:href="@{/?show=my}" th:text="#{link.my}">Моя лента</a></li> @@ -35,13 +35,13 @@ <nav id="actions"> <ul> <li><a href="/#post" th:href="@{/#post}" th:text="#{link.postMessage}">Написать</a></li> - <li><a href="/ugnich" th:href="@{/{userName}(userName=${visitor.name})}" th:text="'@'+${visitor.name}">@ugnich</a></li> + <li><a href="/ugnich" th:href="@{/{userName}(userName=${#authentication.name})}" th:text="'@'+${#authentication.name}">@ugnich</a></li> <li><a href="/settings" th:href="@{/settings}" th:text="#{link.settings}" rel="nofollow">Настройки</a></li> <li><a href="/logout" th:href="@{/logout}" th:text="#{link.logout}">Выйти</a></li> </ul> </nav> </th:block> - <th:block th:case="true"> + <th:block th:if="${#authorization.expression('hasRole(''ROLE_ANONYM'')')}"> <p>[(#{message.loginForSending(@{/login})})]</p> </th:block> </section> |