This repository has been archived by the owner on Sep 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #107. Set 3h of session timeout for non-admin users.
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/main/java/tv/esporx/collections/functions/GrantedAuthorityAsRole.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tv.esporx.collections.functions; | ||
|
||
import com.google.common.base.Function; | ||
import org.springframework.security.core.GrantedAuthority; | ||
|
||
public class GrantedAuthorityAsRole implements Function<GrantedAuthority, String> { | ||
|
||
@Override | ||
public String apply(GrantedAuthority authority) { | ||
return authority.getAuthority(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package tv.esporx.filters; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.filter.GenericFilterBean; | ||
import tv.esporx.collections.functions.GrantedAuthorityAsRole; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
||
import static com.google.common.collect.Collections2.transform; | ||
|
||
public class LogoutPolicyFilter extends GenericFilterBean { | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
|
||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
|
||
if (authentication != null) { | ||
Collection<String> roles = transform(authentication.getAuthorities(), new GrantedAuthorityAsRole()); | ||
if (!roles.contains("ROLE_ADMIN")) { | ||
HttpServletRequest httpRequest = (HttpServletRequest) request; | ||
httpRequest.getSession().setMaxInactiveInterval(3 * 60 * 60); | ||
} | ||
} | ||
|
||
|
||
chain.doFilter(request, response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters