-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated ElytronHttpClient separating Authentication mechanism type me…
…thods
- Loading branch information
1 parent
cbac3de
commit 8f59c18
Showing
10 changed files
with
439 additions
and
299 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
35 changes: 35 additions & 0 deletions
35
.../main/java/org/wildfly/security/http/client/mechanism/ElytronHttpClientAuthMechanism.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,35 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* 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 org.wildfly.security.http.client.mechanism; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpRequest; | ||
|
||
/** | ||
* Elytron client for HTTP authentication | ||
* | ||
* @author <a href="mailto:kekumar@redhat.com">Keshav Kumar</a> | ||
*/ | ||
public interface ElytronHttpClientAuthMechanism { | ||
|
||
/** | ||
* Add required header to request object based on authentication type and return it. | ||
*/ | ||
HttpRequest evaluateMechanism(URI uri) throws Exception; | ||
} |
52 changes: 52 additions & 0 deletions
52
...org/wildfly/security/http/client/mechanism/basic/ElytronHttpClientBasicAuthMechanism.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,52 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* 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 org.wildfly.security.http.client.mechanism.basic; | ||
|
||
import org.wildfly.security.http.client.mechanism.ElytronHttpClientAuthMechanism; | ||
import org.wildfly.security.http.client.utils.ElytronHttpClientCredentialProvider; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpRequest; | ||
import java.util.Base64; | ||
|
||
/** | ||
* Elytron client for HTTP authentication | ||
* | ||
* @author <a href="mailto:kekumar@redhat.com">Keshav Kumar</a> | ||
*/ | ||
public class ElytronHttpClientBasicAuthMechanism implements ElytronHttpClientAuthMechanism { | ||
private static final String AUTHORIZATION = "Authorization"; | ||
private ElytronHttpClientCredentialProvider elytronHttpClientCredentialProvider = new ElytronHttpClientCredentialProvider(); | ||
|
||
@Override | ||
public HttpRequest evaluateMechanism(URI uri) { | ||
String userName = elytronHttpClientCredentialProvider.getUserName(uri); | ||
String password = elytronHttpClientCredentialProvider.getPassword(uri); | ||
HttpRequest request = HttpRequest | ||
.newBuilder() | ||
.uri(uri) | ||
.header(AUTHORIZATION, basicAuth(userName, password)) | ||
.build(); | ||
return request; | ||
} | ||
|
||
private String basicAuth(String username, String password) { | ||
return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...g/wildfly/security/http/client/mechanism/digest/ElytronHttpClientDigestAuthMechanism.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,49 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* 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 org.wildfly.security.http.client.mechanism.digest; | ||
|
||
import org.wildfly.security.http.client.mechanism.ElytronHttpClientAuthMechanism; | ||
import org.wildfly.security.http.client.utils.DigestHttpMechanismUtil; | ||
import org.wildfly.security.http.client.utils.ElytronHttpClientCredentialProvider; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpRequest; | ||
|
||
/** | ||
* Elytron client for HTTP authentication | ||
* | ||
* @author <a href="mailto:kekumar@redhat.com">Keshav Kumar</a> | ||
*/ | ||
public class ElytronHttpClientDigestAuthMechanism implements ElytronHttpClientAuthMechanism { | ||
private DigestHttpMechanismUtil digestHttpMechanismUtil; | ||
private String authHeader; | ||
private ElytronHttpClientCredentialProvider elytronHttpClientCredentialProvider = new ElytronHttpClientCredentialProvider(); | ||
|
||
public ElytronHttpClientDigestAuthMechanism(String authHeader){ | ||
this.authHeader = authHeader; | ||
this.digestHttpMechanismUtil = new DigestHttpMechanismUtil(); | ||
} | ||
|
||
@Override | ||
public HttpRequest evaluateMechanism(URI uri) throws Exception{ | ||
String userName = elytronHttpClientCredentialProvider.getUserName(uri); | ||
String password = elytronHttpClientCredentialProvider.getPassword(uri); | ||
return digestHttpMechanismUtil.createDigestRequest(uri,userName,password,authHeader); | ||
} | ||
} |
Oops, something went wrong.