-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from choonchernlim/development
0.4.0
- Loading branch information
Showing
11 changed files
with
352 additions
and
21 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
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
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
66 changes: 66 additions & 0 deletions
66
...main/java/com/github/choonchernlim/security/adfs/saml2/MockFilterSecurityInterceptor.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,66 @@ | ||
package com.github.choonchernlim.security.adfs.saml2; | ||
|
||
import static com.github.choonchernlim.betterPreconditions.preconditions.PreconditionFactory.expect; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.IOException; | ||
|
||
/** | ||
* This filter class can be placed before Spring Security's FilterSecurityInterceptor to bypass any security | ||
* by setting the given user to the security context and HTTP session. This allows developer to do rapid app | ||
* development without the need to log into the app again and again. | ||
*/ | ||
final class MockFilterSecurityInterceptor implements Filter { | ||
|
||
private final User user; | ||
|
||
MockFilterSecurityInterceptor(final User user) { | ||
expect(user, "user").not().toBeNull().check(); | ||
this.user = user; | ||
} | ||
|
||
@Override | ||
public void doFilter(final ServletRequest servletRequest, | ||
final ServletResponse servletResponse, | ||
final FilterChain filterChain) throws IOException, ServletException { | ||
|
||
// To be consistent with SAML configuration, the `userDetails` is set as `principal` too | ||
final UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( | ||
user, | ||
null, | ||
user.getAuthorities()); | ||
|
||
// setting user details | ||
authentication.setDetails(user); | ||
|
||
// setting `authentication` to security context | ||
final SecurityContext securityContext = SecurityContextHolder.getContext(); | ||
securityContext.setAuthentication(authentication); | ||
|
||
// setting `authentication` to HTTP session | ||
((HttpServletRequest) servletRequest) | ||
.getSession(true) | ||
.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, securityContext); | ||
|
||
filterChain.doFilter(servletRequest, servletResponse); | ||
} | ||
|
||
@Override | ||
public void init(final FilterConfig filterConfig) throws ServletException { | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
} | ||
} |
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
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
11 changes: 11 additions & 0 deletions
11
...n/java/com/github/choonchernlim/security/adfs/saml2/SpringSecurityAdfsSaml2Exception.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,11 @@ | ||
package com.github.choonchernlim.security.adfs.saml2; | ||
|
||
/** | ||
* Module specific exception. | ||
*/ | ||
public final class SpringSecurityAdfsSaml2Exception extends RuntimeException { | ||
|
||
SpringSecurityAdfsSaml2Exception(final String message) { | ||
super(message); | ||
} | ||
} |
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
Oops, something went wrong.