|
1 | 1 | import com.google.common.io.Files
|
2 | 2 | import org.apache.catalina.Context
|
| 3 | +import org.apache.catalina.LifecycleState |
3 | 4 | import org.apache.catalina.realm.MemoryRealm
|
| 5 | +import org.apache.catalina.realm.MessageDigestCredentialHandler |
4 | 6 | import org.apache.catalina.startup.Tomcat
|
5 | 7 | import org.apache.tomcat.JarScanFilter
|
6 | 8 | import org.apache.tomcat.JarScanType
|
@@ -65,31 +67,34 @@ class TomcatServlet3Test extends AbstractServlet3Test<Context> {
|
65 | 67 | servletContext.addServletMappingDecoded(url, name)
|
66 | 68 | }
|
67 | 69 |
|
68 |
| - static setupAuthentication(Tomcat server, Context servletContext) { |
| 70 | + private setupAuthentication(Tomcat server, Context servletContext) { |
69 | 71 | // Login Config
|
70 |
| - LoginConfig authConfig = new LoginConfig(); |
71 |
| - authConfig.setAuthMethod("BASIC"); |
| 72 | + LoginConfig authConfig = new LoginConfig() |
| 73 | + authConfig.setAuthMethod("BASIC") |
72 | 74 |
|
73 | 75 | // adding constraint with role "test"
|
74 |
| - SecurityConstraint constraint = new SecurityConstraint(); |
75 |
| - constraint.addAuthRole("role"); |
| 76 | + SecurityConstraint constraint = new SecurityConstraint() |
| 77 | + constraint.addAuthRole("role") |
76 | 78 |
|
77 | 79 | // add constraint to a collection with pattern /second
|
78 |
| - SecurityCollection collection = new SecurityCollection(); |
79 |
| - collection.addPattern("/auth/*"); |
80 |
| - constraint.addCollection(collection); |
| 80 | + SecurityCollection collection = new SecurityCollection() |
| 81 | + collection.addPattern("/auth/*") |
| 82 | + constraint.addCollection(collection) |
81 | 83 |
|
82 |
| - servletContext.setLoginConfig(authConfig); |
| 84 | + servletContext.setLoginConfig(authConfig) |
83 | 85 | // does the context need a auth role too?
|
84 |
| - servletContext.addSecurityRole("role"); |
85 |
| - servletContext.addConstraint(constraint); |
| 86 | + servletContext.addSecurityRole("role") |
| 87 | + servletContext.addConstraint(constraint) |
86 | 88 |
|
87 | 89 | // add tomcat users to realm
|
88 |
| - URL uri = getClass().getResource("/tomcat-users.xml"); |
89 |
| - assert uri |
90 |
| - MemoryRealm realm = new MemoryRealm(); |
91 |
| - realm.setPathname(uri.toString()); |
92 |
| - server.getEngine().setRealm(realm); |
| 90 | + MemoryRealm realm = new MemoryRealm() { |
| 91 | + protected void startInternal() { |
| 92 | + credentialHandler = new MessageDigestCredentialHandler() |
| 93 | + setState(LifecycleState.STARTING) |
| 94 | + } |
| 95 | + } |
| 96 | + realm.addUser(user, pass, "role") |
| 97 | + server.getEngine().setRealm(realm) |
93 | 98 |
|
94 | 99 | servletContext.setLoginConfig(authConfig)
|
95 | 100 | }
|
|
0 commit comments