Skip to content

Commit

Permalink
Merge pull request #436 from chrisshayan/Release48
Browse files Browse the repository at this point in the history
Release48
  • Loading branch information
phuonghuynh committed Oct 21, 2015
2 parents 980bea0 + b494b37 commit eb400ce
Show file tree
Hide file tree
Showing 103 changed files with 10,926 additions and 2,772 deletions.
6 changes: 5 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"angular-sanitize": "latest",
"moment": "latest",
"angular-strap": "latest",
"datetimepicker": "latest"
"datetimepicker": "latest",
"angular-summernote": "latest"
},
"overrides": {
"jquery": {
Expand Down Expand Up @@ -161,6 +162,9 @@
"build/css/bootstrap-datetimepicker.min.css",
"build/js/bootstrap-datetimepicker.min.js"
]
},
"angular-summernote": {
"main": "dist/angular-summernote.js"
}
},
"resolutions": {
Expand Down
925 changes: 464 additions & 461 deletions src/main/java/com/techlooper/config/CoreConfiguration.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
import com.techlooper.config.CoreConfiguration;
import com.techlooper.config.VnwDbConfiguration;
import com.techlooper.config.web.sec.SecurityConfiguration;
import com.techlooper.config.web.sec.SessionListener;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;

public class DispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
Expand All @@ -31,6 +34,12 @@ public class DispatcherServletInitializer extends AbstractAnnotationConfigDispat
// @Value("${spring.profiles.active}")
// private String profile;

public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.getSessionCookieConfig().setMaxAge(15770000);
servletContext.addListener(new SessionListener());
}

protected Class<?>[] getRootConfigClasses() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import org.springframework.security.config.annotation.web.builders.WebSecurity;
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.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.security.web.authentication.rememberme.InMemoryTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
Expand All @@ -27,58 +30,58 @@
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Bean
public AuthenticationProvider vnwAuthenticationProvider() {
return new VnwAuthenticationProvider();
}
@Bean
public AuthenticationProvider vnwAuthenticationProvider() {
return new VnwAuthenticationProvider();
}

@Bean
public AuthenticationProvider socialAuthenticationProvider() {
return new SocialAuthenticationProvider();
}
@Bean
public AuthenticationProvider socialAuthenticationProvider() {
return new SocialAuthenticationProvider();
}

@Bean
public AuthenticationProvider switchingAuthenticationProvider() {
SwitchingAuthenticationProvider switchingAuthenticationProvider = new SwitchingAuthenticationProvider();
Map<SocialProvider, AuthenticationProvider> authenticationProviders = new HashMap<>();
authenticationProviders.put(SocialProvider.VIETNAMWORKS, vnwAuthenticationProvider());
authenticationProviders.put(SocialProvider.FACEBOOK, socialAuthenticationProvider());
authenticationProviders.put(SocialProvider.GOOGLE, socialAuthenticationProvider());
switchingAuthenticationProvider.setProviders(authenticationProviders);
return switchingAuthenticationProvider;
}
@Bean
public AuthenticationProvider switchingAuthenticationProvider() {
SwitchingAuthenticationProvider switchingAuthenticationProvider = new SwitchingAuthenticationProvider();
Map<SocialProvider, AuthenticationProvider> authenticationProviders = new HashMap<>();
authenticationProviders.put(SocialProvider.VIETNAMWORKS, vnwAuthenticationProvider());
authenticationProviders.put(SocialProvider.FACEBOOK, socialAuthenticationProvider());
authenticationProviders.put(SocialProvider.GOOGLE, socialAuthenticationProvider());
switchingAuthenticationProvider.setProviders(authenticationProviders);
return switchingAuthenticationProvider;
}

@Bean
public AuthenticationManager authenticationManager() {
return new ProviderManager(Arrays.asList(switchingAuthenticationProvider()));
}
@Bean
public AuthenticationManager authenticationManager() {
return new ProviderManager(Arrays.asList(switchingAuthenticationProvider()));
}

protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.and().formLogin().loginPage("/login").usernameParameter("us").passwordParameter("pwd").successHandler(getSuccessHandler()).failureHandler(getAuthenticationFailureHandler())
.and().logout().logoutUrl("/logout").logoutSuccessHandler(getLogoutSuccessHandler()).invalidateHttpSession(true).deleteCookies("SESSION").permitAll()
.and().exceptionHandling().authenticationEntryPoint(exceptionHandler());
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.headers().frameOptions().disable();
http.authorizeRequests()
.and().formLogin().loginPage("/login").usernameParameter("us").passwordParameter("pwd").successHandler(getSuccessHandler()).failureHandler(getAuthenticationFailureHandler())
.and().logout().logoutUrl("/logout").logoutSuccessHandler(getLogoutSuccessHandler()).invalidateHttpSession(true).deleteCookies("JSESSIONID").permitAll()
.and().exceptionHandling().authenticationEntryPoint(exceptionHandler());
}

}
private AuthenticationEntryPoint exceptionHandler() {
return (request, response, authException) -> response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}

private AuthenticationEntryPoint exceptionHandler() {
return (request, response, authException) -> response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
private LogoutSuccessHandler getLogoutSuccessHandler() {
return (request, response, authentication) -> response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}

private LogoutSuccessHandler getLogoutSuccessHandler() {
return (request, response, authentication) -> response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
private AuthenticationFailureHandler getAuthenticationFailureHandler() {
return (request, response, exception) -> response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}

private AuthenticationFailureHandler getAuthenticationFailureHandler() {
return (request, response, exception) -> response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
private AuthenticationSuccessHandler getSuccessHandler() {
return (request, response, authentication) -> response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}

private AuthenticationSuccessHandler getSuccessHandler() {
return (request, response, authentication) -> response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}

public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/images/**", "/css/**", "/generate-resources/**", "/modules/**", "/bower_components/**", "/custom-js/**");
}
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/images/**", "/css/**", "/generate-resources/**", "/modules/**", "/bower_components/**", "/custom-js/**");
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/techlooper/config/web/sec/SessionListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.techlooper.config.web.sec;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
* Created by phuonghqh on 10/12/15.
*/
public class SessionListener implements HttpSessionListener {

public void sessionCreated(HttpSessionEvent event) {
event.getSession().setMaxInactiveInterval(15770000);
}

public void sessionDestroyed(HttpSessionEvent se) {
}
}
Loading

0 comments on commit eb400ce

Please sign in to comment.