Skip to content

Commit

Permalink
Merge pull request #2601 from NationalSecurityAgency/2.12.X-merge-4
Browse files Browse the repository at this point in the history
2.12.x merge 4
  • Loading branch information
rmmayo authored Jun 24, 2024
2 parents f033bbc + 8b2ac6e commit 689438f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dashboard/src/store/modules/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const actions = {
logout({ commit }) {
commit('clearAuthData');
commit('showUa', false, { root: true });
axios.get('/logout')
axios.post('/logout')
.then(() => {
router.replace('/skills-login');
});
Expand Down
13 changes: 12 additions & 1 deletion service/src/main/java/skills/auth/PortalWebSecurityHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ import org.springframework.security.authorization.AuthorizationManager
import org.springframework.security.authorization.AuthorizationManagers
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.web.access.intercept.RequestAuthorizationContext
import org.springframework.security.web.authentication.session.NullAuthenticatedSessionStrategy
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter
import org.springframework.security.web.csrf.CookieCsrfTokenRepository
import org.springframework.security.web.csrf.CsrfToken
import org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler
import org.springframework.security.web.csrf.CsrfTokenRequestHandler
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository
import org.springframework.security.web.csrf.XorCsrfTokenRequestAttributeHandler
import org.springframework.security.web.util.matcher.AntPathRequestMatcher
import org.springframework.security.web.util.matcher.OrRequestMatcher
Expand Down Expand Up @@ -68,16 +71,24 @@ class PortalWebSecurityHelper {
@Autowired
InviteOnlyProjectAuthorizationManager inviteOnlyProjectAuthorizationManager

@Autowired
CookieCsrfTokenRepository cookieCsrfTokenRepository

@Autowired
UserCommunityAuthorizationManager userCommunityAuthorizationManager

@Autowired
SessionAuthenticationStrategy csrfAuthenticationStrategy

HttpSecurity configureHttpSecurity(HttpSecurity http) {
if (disableCsrfProtection) {
http.csrf().disable()
} else {
http.csrf((csrf) -> csrf
.requireCsrfProtectionMatcher(new MultipartRequestMatcher())
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.csrfTokenRepository(cookieCsrfTokenRepository)
// .csrfTokenRepository(new HttpSessionCsrfTokenRepository())
.sessionAuthenticationStrategy(csrfAuthenticationStrategy)
.csrfTokenRequestHandler(new SpaCsrfTokenRequestHandler()))
.addFilterAfter(new CsrfCookieFilter(), BasicAuthenticationFilter.class)
}
Expand Down
20 changes: 20 additions & 0 deletions service/src/main/java/skills/auth/SecurityConfiguration.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ import org.springframework.security.web.AuthenticationEntryPoint
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.access.AccessDeniedHandler
import org.springframework.security.web.access.AccessDeniedHandlerImpl
import org.springframework.security.web.authentication.session.NullAuthenticatedSessionStrategy
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy
import org.springframework.security.web.context.SecurityContextRepository
import org.springframework.security.web.csrf.CookieCsrfTokenRepository
import org.springframework.security.web.csrf.CsrfAuthenticationStrategy
import org.springframework.security.web.firewall.HttpFirewall
import org.springframework.security.web.firewall.StrictHttpFirewall
import org.springframework.stereotype.Component
Expand Down Expand Up @@ -182,4 +186,20 @@ class SecurityConfiguration {
return strictHttpFirewall
}

@Bean
CookieCsrfTokenRepository cookieCsrfTokenRepository() {
CookieCsrfTokenRepository cookieCsrfTokenRepository = CookieCsrfTokenRepository.withHttpOnlyFalse();
cookieCsrfTokenRepository.setCookiePath("/");
return cookieCsrfTokenRepository;
}

@Bean
SessionAuthenticationStrategy csrfAuthenticationStrategy(CookieCsrfTokenRepository cookieCsrfTokenRepository) {
if (this.authMode == AuthMode.PKI) {
return new NullAuthenticatedSessionStrategy()
} else {
return new CsrfAuthenticationStrategy(cookieCsrfTokenRepository);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class RestTemplateWrapper extends RestTemplate {
if (returnedCookies && cookies == null) {
cookies = returnedCookies
log.info("Setting cookies to {}", returnedCookies)
printf "Setting cookies to ${returnedCookies}"
}
if (returnedCookies && !xsrfToken) {
String cookieXSRF = returnedCookies.find { it.startsWith("XSRF-TOKEN=") }
Expand Down Expand Up @@ -170,6 +169,8 @@ class RestTemplateWrapper extends RestTemplate {

authenticationToken = authResponse.getHeaders().getFirst(AUTH_HEADER)
}
} else {
restTemplate.getForEntity("${skillsServiceUrl}/app/users/validExistingDashboardUserId/{userId}", String, username)
}
authenticated = true
}
Expand Down

0 comments on commit 689438f

Please sign in to comment.