Skip to content

Commit

Permalink
feat: ssa revoke endpoint (#2865)
Browse files Browse the repository at this point in the history
  • Loading branch information
Milton-Ch authored Nov 7, 2022
1 parent 943d99f commit 9c68f91
Show file tree
Hide file tree
Showing 23 changed files with 749 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,19 @@ public String getHttpMethod() {
public SsaGetResponse execSsaGet(String accessToken, String jti, Long orgId, Boolean softwareRoles) {
SsaGetRequest ssaGetRequest = new SsaGetRequest();
ssaGetRequest.setAccessToken(accessToken);
ssaGetRequest.setJti(jti);
ssaGetRequest.setOrgId(orgId);
ssaGetRequest.setSoftwareRoles(softwareRoles);
setRequest(ssaGetRequest);

URIBuilder uriBuilder = new URIBuilder();
if (StringUtils.isNotBlank(jti)) {
uriBuilder.addParameter("jti", jti);
}
if (orgId != null && orgId > 0) {
uriBuilder.addParameter("org_id", orgId.toString());
}
if (softwareRoles != null) {
uriBuilder.addParameter("software_roles", softwareRoles.toString());
}
setUrl(getUrl() + uriBuilder);
return exec();
}

public SsaGetResponse exec() {
try {
initClient();

Builder clientRequest = webTarget.request();
String uriWithParams = getUrl() + "?" + getRequest().getQueryString();
Builder clientRequest = resteasyClient.target(uriWithParams).request();
applyCookies(clientRequest);

clientRequest.header("Content-Type", request.getContentType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@

import io.jans.as.client.BaseRequest;
import io.jans.as.model.common.AuthorizationMethod;
import io.jans.as.model.ssa.SsaRequestParam;
import io.jans.as.model.util.QueryBuilder;
import jakarta.ws.rs.core.MediaType;

public class SsaGetRequest extends BaseRequest {

private String accessToken;

private String jti;

private Long orgId;

private Boolean softwareRoles;

public SsaGetRequest() {
setContentType(MediaType.APPLICATION_JSON);
setMediaType(MediaType.APPLICATION_JSON);
Expand All @@ -28,8 +36,36 @@ public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}

public String getJti() {
return jti;
}

public void setJti(String jti) {
this.jti = jti;
}

public Long getOrgId() {
return orgId;
}

public void setOrgId(Long orgId) {
this.orgId = orgId;
}

public Boolean getSoftwareRoles() {
return softwareRoles;
}

public void setSoftwareRoles(Boolean softwareRoles) {
this.softwareRoles = softwareRoles;
}

@Override
public String getQueryString() {
return null;
QueryBuilder builder = QueryBuilder.instance();
builder.append(SsaRequestParam.JTI.getName(), jti);
builder.append(SsaRequestParam.ORG_ID.getName(), orgId != null ? orgId.toString() : "");
builder.append(SsaRequestParam.SOFTWARE_ROLES.getName(), softwareRoles != null ? softwareRoles.toString() : "");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.as.client.ssa.revoke;

import io.jans.as.client.BaseClient;
import io.jans.as.model.config.Constants;
import jakarta.ws.rs.HttpMethod;
import jakarta.ws.rs.client.Invocation.Builder;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

public class SsaRevokeClient extends BaseClient<SsaRevokeRequest, SsaRevokeResponse> {

private static final Logger LOG = Logger.getLogger(SsaRevokeClient.class);

public SsaRevokeClient(String url) {
super(url);
}

@Override
public String getHttpMethod() {
return HttpMethod.DELETE;
}

public SsaRevokeResponse execSsaRevoke(String accessToken, String jti, Long orgId) {
SsaRevokeRequest req = new SsaRevokeRequest();
req.setAccessToken(accessToken);
req.setJti(jti);
req.setOrgId(orgId);
setRequest(req);
return exec();
}

public SsaRevokeResponse exec() {
try {
initClient();

String uriWithParams = getUrl() + "?" + getRequest().getQueryString();
Builder clientRequest = resteasyClient.target(uriWithParams).request();
applyCookies(clientRequest);

clientRequest.header("Content-Type", request.getContentType());
if (StringUtils.isNotBlank(request.getAccessToken())) {
clientRequest.header(Constants.AUTHORIZATION, "Bearer ".concat(request.getAccessToken()));
}

clientResponse = clientRequest.buildDelete().invoke();
final SsaRevokeResponse res = new SsaRevokeResponse(clientResponse);
setResponse(res);

} catch (Exception e) {
LOG.error(e.getMessage(), e);
} finally {
closeConnection();
}

return getResponse();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.as.client.ssa.revoke;

import io.jans.as.client.BaseRequest;
import io.jans.as.model.common.AuthorizationMethod;
import io.jans.as.model.ssa.SsaRequestParam;
import io.jans.as.model.util.QueryBuilder;
import jakarta.ws.rs.core.MediaType;

public class SsaRevokeRequest extends BaseRequest {

private String accessToken;

private String jti;

private Long orgId;

public SsaRevokeRequest() {
setContentType(MediaType.APPLICATION_JSON);
setMediaType(MediaType.APPLICATION_JSON);
setAuthorizationMethod(AuthorizationMethod.AUTHORIZATION_REQUEST_HEADER_FIELD);
}

public String getAccessToken() {
return accessToken;
}

public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}

public String getJti() {
return jti;
}

public void setJti(String jti) {
this.jti = jti;
}

public Long getOrgId() {
return orgId;
}

public void setOrgId(Long orgId) {
this.orgId = orgId;
}

@Override
public String getQueryString() {
QueryBuilder builder = QueryBuilder.instance();
builder.append(SsaRequestParam.JTI.getName(), jti);
builder.append(SsaRequestParam.ORG_ID.getName(), orgId != null ? orgId.toString() : "");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.as.client.ssa.revoke;

import io.jans.as.client.BaseResponseWithErrors;
import io.jans.as.model.ssa.SsaErrorResponseType;
import jakarta.ws.rs.core.Response;

public class SsaRevokeResponse extends BaseResponseWithErrors<SsaErrorResponseType> {

public SsaRevokeResponse(Response clientResponse) {
super(clientResponse);
}

@Override
public SsaErrorResponseType fromString(String p_str) {
return SsaErrorResponseType.fromString(p_str);
}

@Override
public void injectDataFromJson(String json) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public SsaValidateClient(String url) {

@Override
public String getHttpMethod() {
return HttpMethod.GET;
return HttpMethod.HEAD;
}

public SsaValidateResponse execSsaValidate(@NotNull String jti) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import java.util.*;

public class SsaCreateRestTest extends BaseTest {
public class SsaCreateTest extends BaseTest {

@Parameters({"redirectUris", "sectorIdentifierUri"})
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Collections;
import java.util.List;

public class SsaGetRestTest extends BaseTest {
public class SsaGetTest extends BaseTest {

@Parameters({"redirectUris", "sectorIdentifierUri"})
@Test
Expand Down
Loading

0 comments on commit 9c68f91

Please sign in to comment.