-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jans-auth-server): ssa get endpoint (#2719)
- Loading branch information
Showing
41 changed files
with
1,669 additions
and
538 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
59 changes: 0 additions & 59 deletions
59
jans-auth-server/client/src/main/java/io/jans/as/client/SsaResponse.java
This file was deleted.
Oops, something went wrong.
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
83 changes: 83 additions & 0 deletions
83
jans-auth-server/client/src/main/java/io/jans/as/client/ssa/create/SsaCreateResponse.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,83 @@ | ||
/* | ||
* 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.create; | ||
|
||
import io.jans.as.client.BaseResponseWithErrors; | ||
import io.jans.as.model.jwt.Jwt; | ||
import io.jans.as.model.jwt.JwtClaims; | ||
import io.jans.as.model.ssa.SsaErrorResponseType; | ||
import jakarta.ws.rs.core.Response; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.log4j.Logger; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.Objects; | ||
|
||
import static io.jans.as.model.ssa.SsaRequestParam.JTI; | ||
import static io.jans.as.model.ssa.SsaRequestParam.SSA; | ||
|
||
public class SsaCreateResponse extends BaseResponseWithErrors<SsaErrorResponseType> { | ||
|
||
private static final Logger LOG = Logger.getLogger(SsaCreateResponse.class); | ||
|
||
private String ssa; | ||
|
||
private String jti; | ||
|
||
public SsaCreateResponse() { | ||
} | ||
|
||
public SsaCreateResponse(Response clientResponse) { | ||
super(clientResponse); | ||
} | ||
|
||
@Override | ||
public SsaErrorResponseType fromString(String p_str) { | ||
return SsaErrorResponseType.fromString(p_str); | ||
} | ||
|
||
public void injectDataFromJson() { | ||
injectDataFromJson(entity); | ||
} | ||
|
||
@Override | ||
public void injectDataFromJson(String json) { | ||
if (StringUtils.isNotBlank(entity)) { | ||
try { | ||
JSONObject jsonObj = new JSONObject(entity); | ||
if (jsonObj.has(SSA.getName())) { | ||
ssa = jsonObj.getString(SSA.getName()); | ||
if (StringUtils.isNotBlank(ssa)) { | ||
JwtClaims jwtClaims = Objects.requireNonNull(Jwt.parseSilently(ssa)).getClaims(); | ||
if (jwtClaims.hasClaim(JTI.getName())) { | ||
jti = jwtClaims.getClaimAsString(JTI.getName()); | ||
} | ||
} | ||
} | ||
} catch (JSONException e) { | ||
LOG.error(e.getMessage(), e); | ||
} | ||
} | ||
} | ||
|
||
public String getSsa() { | ||
return ssa; | ||
} | ||
|
||
public void setSsa(String ssa) { | ||
this.ssa = ssa; | ||
} | ||
|
||
public String getJti() { | ||
return jti; | ||
} | ||
|
||
public void setJti(String jti) { | ||
this.jti = jti; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
jans-auth-server/client/src/main/java/io/jans/as/client/ssa/get/SsaGetClient.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,75 @@ | ||
/* | ||
* 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.get; | ||
|
||
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.http.client.utils.URIBuilder; | ||
import org.apache.log4j.Logger; | ||
|
||
public class SsaGetClient extends BaseClient<SsaGetRequest, SsaGetResponse> { | ||
|
||
private static final Logger LOG = Logger.getLogger(SsaGetClient.class); | ||
|
||
public SsaGetClient(String url) { | ||
super(url); | ||
} | ||
|
||
@Override | ||
public String getHttpMethod() { | ||
return HttpMethod.GET; | ||
} | ||
|
||
public SsaGetResponse execSsaGet(String accessToken, String jti, Long orgId, Boolean softwareRoles) { | ||
SsaGetRequest ssaGetRequest = new SsaGetRequest(); | ||
ssaGetRequest.setAccessToken(accessToken); | ||
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(); | ||
applyCookies(clientRequest); | ||
|
||
clientRequest.header("Content-Type", request.getContentType()); | ||
if (StringUtils.isNotBlank(request.getAccessToken())) { | ||
clientRequest.header(Constants.AUTHORIZATION, "Bearer ".concat(request.getAccessToken())); | ||
} | ||
|
||
clientResponse = clientRequest.buildGet().invoke(); | ||
final SsaGetResponse ssaGetResponse = new SsaGetResponse(clientResponse); | ||
ssaGetResponse.injectDataFromJson(); | ||
setResponse(ssaGetResponse); | ||
|
||
} catch (Exception e) { | ||
LOG.error(e.getMessage(), e); | ||
} finally { | ||
closeConnection(); | ||
} | ||
|
||
return getResponse(); | ||
} | ||
} | ||
|
Oops, something went wrong.