forked from spinnaker/gate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-14834: invalidate session and throw SAMLAuthenticationException (s…
…pinnaker#209) (spinnaker#216) * OP-14834: Check and update the token. * OP-14834: Updated logs and packages. * OP-14834: Only validates ExpiringUsernameAuthenticationToken. * OP-14834: Only validates ExpiringUsernameAuthenticationToken. * OP-14834: Added SamlAuthTokenUpdateFilter to the filter chain. * OP-14834: Added SamlAuthTokenUpdateFilter to the filter chain after basic auth filter. * OP-14834: redirect to logout * OP-14834: throw AccessDeniedException * OP-14834:redirect to /saml/login. * OP-14834:redirect to /saml/sso. * OP-14834: send html response * OP-14834: clear context * OP-14834: invalidate session * OP-14834: and then logout * OP-14834: clear context, invalidate session and redirect to log out url. * OP-14834: invalidate session and throw SAMLAuthenticationException * OP-14834: removed commented code. * OP-14834: Updated the log message. * OP-14834: Updated the certificate
- Loading branch information
1 parent
098c31d
commit c9aeffe
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
...aml/src/main/java/com/opsmx/spinnaker/gate/security/saml/SAMLAuthenticationException.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,13 @@ | ||
package com.opsmx.spinnaker.gate.security.saml; | ||
|
||
import org.springframework.security.core.AuthenticationException; | ||
|
||
public class SAMLAuthenticationException extends AuthenticationException { | ||
public SAMLAuthenticationException(String msg) { | ||
super(msg); | ||
} | ||
|
||
public SAMLAuthenticationException(String msg, Throwable t) { | ||
super(msg, t); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...-saml/src/main/java/com/opsmx/spinnaker/gate/security/saml/SamlAuthTokenUpdateFilter.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,59 @@ | ||
/* | ||
* Copyright 2022 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.security.saml; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.providers.ExpiringUsernameAuthenticationToken; | ||
import org.springframework.web.filter.GenericFilterBean; | ||
|
||
public class SamlAuthTokenUpdateFilter extends GenericFilterBean { | ||
|
||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) | ||
throws IOException, ServletException { | ||
logger.debug("SamlAuthTokenUpdateFilter doFilter started"); | ||
HttpServletRequest request = (HttpServletRequest) req; | ||
HttpServletResponse response = (HttpServletResponse) res; | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
|
||
logger.debug("Previously Authenticated is : " + authentication); | ||
if (authentication instanceof ExpiringUsernameAuthenticationToken | ||
&& !authentication.isAuthenticated()) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug( | ||
"Previously Authenticated token Expired; redirecting to authentication entry point."); | ||
} | ||
|
||
HttpSession session = request.getSession(); | ||
if (session != null) { | ||
session.invalidate(); | ||
} | ||
throw new SAMLAuthenticationException("Previously Authenticated token Expired"); | ||
} | ||
logger.debug("SamlAuthTokenUpdateFilter doFilter ended"); | ||
|
||
chain.doFilter(request, response); | ||
} | ||
} |