Skip to content

Commit

Permalink
#189 : added ability to update client's secret expiration time
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyz committed Apr 7, 2016
1 parent b6b3787 commit afa369a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Client/src/main/java/org/xdi/oxauth/client/RegisterRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class RegisterRequest extends BaseRequest {
private List<String> postLogoutRedirectUris;
private List<String> requestUris;
private List<String> scopes;
private Date clientSecretExpiresAt;
private String federationId;
private String federationUrl;
private Map<String, String> customAttributes;
Expand Down Expand Up @@ -157,6 +158,24 @@ public void setLogoutUris(List<String> logoutUris) {
this.logoutUris = logoutUris;
}

/**
* Gets client_secret_expires_at
*
* @return client_secret_expires_at property
*/
public Date getClientSecretExpiresAt() {
return clientSecretExpiresAt;
}

/**
* Sets client secret expiration date
*
* @param clientSecretExpiresAt client secret expiration date
*/
public void setClientSecretExpiresAt(Date clientSecretExpiresAt) {
this.clientSecretExpiresAt = clientSecretExpiresAt;
}

/**
* Gets logout session required.
*
Expand Down Expand Up @@ -933,6 +952,9 @@ public Map<String, String> getParameters() {
if (scopes != null && !scopes.isEmpty()) {
parameters.put(SCOPES.toString(), toJSONArray(scopes).toString());
}
if (clientSecretExpiresAt != null) {
parameters.put(CLIENT_SECRET_EXPIRES_AT.toString(), Long.toString(clientSecretExpiresAt.getTime()));
}
// Federation params
if (!StringUtils.isBlank(federationUrl)) {
parameters.put(FEDERATION_METADATA_URL.toString(), federationUrl);
Expand Down Expand Up @@ -1064,8 +1086,16 @@ public static RegisterRequest fromJson(String p_json) throws JSONException {
}
}

Date clientSecretExpiresAt = null;
if (requestObject.has(CLIENT_SECRET_EXPIRES_AT.getName())) {
if (requestObject.optLong(CLIENT_SECRET_EXPIRES_AT.getName()) > 0) {
clientSecretExpiresAt = new Date(requestObject.optLong(CLIENT_SECRET_EXPIRES_AT.getName()));
}
}

final RegisterRequest result = new RegisterRequest();
result.setJsonObject(requestObject);
result.setClientSecretExpiresAt(clientSecretExpiresAt);
result.setFederationUrl(requestObject.optString(FEDERATION_METADATA_URL.toString()));
result.setFederationId(requestObject.optString(FEDERATION_METADATA_ID.toString()));
result.setRequestUris(requestUris);
Expand Down Expand Up @@ -1232,6 +1262,9 @@ public JSONObject getJSONParameters() throws JSONException {
if (!StringUtils.isBlank(federationId)) {
parameters.put(FEDERATION_METADATA_ID.toString(), federationId);
}
if (clientSecretExpiresAt != null) {
parameters.put(CLIENT_SECRET_EXPIRES_AT.toString(), clientSecretExpiresAt.getTime());
}
// Custom params
if (customAttributes != null && !customAttributes.isEmpty()) {
for (Map.Entry<String, String> entry : customAttributes.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ public enum RegisterRequestParam {

SCOPES("scopes"),

CLIENT_SECRET_EXPIRES_AT("client_secret_expires_at"),

// Federation Params
FEDERATION_METADATA_URL("federation_metadata_url"),
FEDERATION_METADATA_ID("federation_metadata_id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

import static org.xdi.oxauth.model.register.RegisterRequestParam.*;
import static org.xdi.oxauth.model.register.RegisterResponseParam.*;
import static org.xdi.oxauth.model.register.RegisterResponseParam.CLIENT_SECRET_EXPIRES_AT;
import static org.xdi.oxauth.model.util.StringUtils.toList;

/**
Expand Down Expand Up @@ -329,6 +330,11 @@ public static void updateClientFromRequestObject(Client p_client, RegisterReques
p_client.setRequestUris(requestUris.toArray(new String[requestUris.size()]));
}

Date clientSecretExpiresAt = requestObject.getClientSecretExpiresAt();
if (clientSecretExpiresAt != null) {
p_client.setClientSecretExpiresAt(clientSecretExpiresAt);
}

// Federation params
if (StringUtils.isNotBlank(requestObject.getFederationUrl())) {
p_client.setFederationURI(requestObject.getFederationUrl());
Expand Down

0 comments on commit afa369a

Please sign in to comment.