-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[relates #4956] Add netty-http JAAS test case
- Loading branch information
Showing
7 changed files
with
188 additions
and
0 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
77 changes: 77 additions & 0 deletions
77
...ttp/src/main/java/org/apache/camel/quarkus/component/netty/http/auth/JaasLoginModule.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,77 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.netty.http.auth; | ||
|
||
import java.util.Map; | ||
|
||
import javax.security.auth.Subject; | ||
import javax.security.auth.callback.Callback; | ||
import javax.security.auth.callback.CallbackHandler; | ||
import javax.security.auth.callback.PasswordCallback; | ||
import javax.security.auth.login.LoginException; | ||
import javax.security.auth.spi.LoginModule; | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@RegisterForReflection | ||
public class JaasLoginModule implements LoginModule { | ||
private CallbackHandler callbackHandler; | ||
|
||
@Override | ||
public void initialize( | ||
Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { | ||
this.callbackHandler = callbackHandler; | ||
} | ||
|
||
@Override | ||
public boolean login() throws LoginException { | ||
Callback[] callbacks = new Callback[1]; | ||
callbacks[0] = new PasswordCallback("password", false); | ||
|
||
try { | ||
callbackHandler.handle(callbacks); | ||
char[] tmpPassword = ((PasswordCallback) callbacks[0]).getPassword(); | ||
String password = new String(tmpPassword); | ||
((PasswordCallback) callbacks[0]).clearPassword(); | ||
if (!"adminjaaspass".equals(password)) { | ||
throw new LoginException("Login denied"); | ||
} | ||
} catch (Exception e) { | ||
LoginException le = new LoginException(e.getMessage()); | ||
le.initCause(e); | ||
throw le; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean commit() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean abort() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean logout() { | ||
callbackHandler = null; | ||
return true; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...tty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/NettyHttpJaasIT.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,23 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.netty.http; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class NettyHttpJaasIT extends NettyHttpJaasTest { | ||
} |
40 changes: 40 additions & 0 deletions
40
...y-http/src/test/java/org/apache/camel/quarkus/component/netty/http/NettyHttpJaasTest.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,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.netty.http; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(NettyHttpJaasTestResource.class) | ||
public class NettyHttpJaasTest { | ||
@ParameterizedTest | ||
@CsvSource({ | ||
"admin,wrongjaaspass,401", | ||
"admin,adminjaaspass,200" | ||
}) | ||
public void testJaas(String user, String password, int responseCode) { | ||
RestAssured | ||
.when() | ||
.get("/netty/http/jaas/{user}/{password}", user, password) | ||
.then() | ||
.statusCode(responseCode); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...rc/test/java/org/apache/camel/quarkus/component/netty/http/NettyHttpJaasTestResource.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,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.netty.http; | ||
|
||
import java.util.Map; | ||
|
||
public class NettyHttpJaasTestResource extends NettyHttpTestResource { | ||
@Override | ||
public Map<String, String> start() { | ||
// for JVM | ||
System.setProperty("java.security.auth.login.config", "src/test/resources/config.jaas"); | ||
final Map<String, String> properties = super.start(); | ||
// for native | ||
properties.put("java.security.auth.login.config", "src/test/resources/config.jaas"); | ||
return properties; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
System.clearProperty("java.security.auth.login.config"); | ||
super.stop(); | ||
} | ||
} |
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,3 @@ | ||
Quarkus { | ||
org.apache.camel.quarkus.component.netty.http.auth.JaasLoginModule required debug=true; | ||
}; |
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