Skip to content

Commit

Permalink
Merge pull request #359 from yahoo/client-creds
Browse files Browse the repository at this point in the history
support for direct setting credentials for zms and zts clients
  • Loading branch information
mujibur authored Dec 19, 2017
2 parents 1a4de86 + 329fa2a commit c19903a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
21 changes: 10 additions & 11 deletions clients/java/zms/src/main/java/com/yahoo/athenz/zms/ZMSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ public void setZMSRDLGeneratedClient(ZMSRDLGeneratedClient client) {
this.client = client;
}

/**
* Set the client credentials using the specified header and token.
* @param credHeader authentication header name
* @param credToken authentication credentials
*/
public void addCredentials(String credHeader, String credToken) {
client.addCredentials(credHeader, credToken);
}

/**
* Sets or overrides the current principal identity set in the client.
* @param identity Principal identity for authenticating requests
Expand Down Expand Up @@ -211,17 +220,7 @@ public ZMSClient addCredentials(Principal identity) {
final Authority authority = principal.getAuthority();
if (authority != null) {

// special handling for cookie headers since we want to keep
// cookie name in the authority header name

String headerName = authority.getHeader();
String credentials = principal.getCredentials();
if (headerName.startsWith("Cookie.")) {
credentials = headerName.substring(7) + "=" + credentials;
headerName = "Cookie";
}

client.addCredentials(headerName, credentials);
client.addCredentials(authority.getHeader(), principal.getCredentials());

// final check if the authority does not support authorization
// by the zms server then it's most likely a user authority and
Expand Down
13 changes: 10 additions & 3 deletions clients/java/zts/src/main/java/com/yahoo/athenz/zts/ZTSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -539,16 +539,23 @@ public static String getHeader() {
}

/**
* Clear the principal identity set for the client. Unless a new principal is set
* using the addCredentials method, the client can only be used to requests data
* from the ZTS Server that doesn't require any authentication.
* Set client credentials based on the given principal.
* @param identity Principal identity for authenticating requests
* @return self ZTSClient object
*/
public ZTSClient addCredentials(Principal identity) {
return addPrincipalCredentials(identity, true);
}

/**
* Set the client credentials using the specified header and token.
* @param credHeader authentication header name
* @param credToken authentication credentials
*/
public void addCredentials(String credHeader, String credToken) {
ztsClient.addCredentials(credHeader, credToken);
}

/**
* Clear the principal identity set for the client. Unless a new principal is set
* using the addCredentials method, the client can only be used to requests data
Expand Down

0 comments on commit c19903a

Please sign in to comment.