Skip to content

Commit

Permalink
feat(jans-auth-server): included org_id in the response of DCR #5787 (#…
Browse files Browse the repository at this point in the history
…6095)

* feat(jans-auth-server): included org_id in the response of DCR #5787

Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>

* minor

Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>

* updated swagger with org_id

Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>

---------

Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>
Signed-off-by: Mustafa Baser <mbaser@mail.com>
  • Loading branch information
yuriyz authored and devrimyatar committed Dec 30, 2023
1 parent a3ab169 commit c4df785
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 1 deletion.
6 changes: 6 additions & 0 deletions jans-auth-server/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,9 @@ paths:
description: ROPC script dn
items:
type: string
org_id:
type: string
description: Organization Id

responses:
200:
Expand Down Expand Up @@ -1583,6 +1586,9 @@ paths:
client_secret_expires_at:
type: integer
description: Time at which the client_secret will expire or 0 if it will not expire.
org_id:
type: string
description: Organization Id. Present only when organization id is set.
400:
description: Invalid parameters provided to endpoint.
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public enum RegisterRequestParam {
*/
TOS_URI("tos_uri"),

/**
* Organization id
*/
ORG_ID("org_id"),

/**
* URL for the Client's JSON Web Key Set (JWK) document containing key(s) that are used for signing requests to
* the OP. The JWK Set may also contain the Client's encryption keys(s) that are used by the OP to encrypt the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public JSONObject getJSONObject(Client client) throws JSONException, StringEncry
Util.addToJSONObjectIfNotNull(responseJsonObject, CLIENT_URI.toString(), client.getClientUri());
Util.addToJSONObjectIfNotNull(responseJsonObject, POLICY_URI.toString(), client.getPolicyUri());
Util.addToJSONObjectIfNotNull(responseJsonObject, TOS_URI.toString(), client.getTosUri());
Util.addToJSONObjectIfNotNull(responseJsonObject, ORG_ID.toString(), client.getOrganization());

Util.addToJSONObjectIfNotNull(responseJsonObject, CLIENT_NAME.toString(), client.getClientNameLocalized());
Util.addToJSONObjectIfNotNull(responseJsonObject, LOGO_URI.toString(), client.getLogoUriLocalized());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.jans.as.model.jwt.Jwt;
import io.jans.as.model.register.ApplicationType;
import io.jans.as.model.register.RegisterErrorResponseType;
import io.jans.as.model.register.RegisterRequestParam;
import io.jans.as.persistence.model.Scope;
import io.jans.as.server.ciba.CIBARegisterClientMetadataService;
import io.jans.as.server.service.ScopeService;
Expand Down Expand Up @@ -388,7 +389,7 @@ public void updateClientFromRequestObject(Client client, RegisterRequest request
}

if (requestObject.getJsonObject() != null) {
final String orgId = requestObject.getJsonObject().optString("org_id");
final String orgId = requestObject.getJsonObject().optString(RegisterRequestParam.ORG_ID.getName());
if (StringUtils.isNotBlank(orgId)) {
client.setOrganization(orgId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package io.jans.as.server.register.ws.rs;

import io.jans.as.common.model.registration.Client;
import io.jans.as.common.service.AttributeService;
import io.jans.as.model.configuration.AppConfiguration;
import io.jans.as.server.ciba.CIBARegisterClientResponseService;
import io.jans.as.server.service.ClientService;
import io.jans.as.server.service.ScopeService;
import io.jans.util.security.StringEncrypter;
import org.json.JSONObject;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import java.util.Date;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;

/**
* @author Yuriy Z
*/
@Listeners(MockitoTestNGListener.class)
public class RegisterJsonServiceTest {

@InjectMocks
@Spy
private RegisterJsonService registerJsonService;

@Mock
private AppConfiguration appConfiguration;

@Mock
private ClientService clientService;

@Mock
private ScopeService scopeService;

@Mock
private AttributeService attributeService;

@Mock
private CIBARegisterClientResponseService cibaRegisterClientResponseService;

@Test
public void getJSONObject_whenOrgIdSet_shouldHaveOrgIdPresentInJson() throws StringEncrypter.EncryptionException {
Client client = new Client();
client.setOrganization("testOrgId");
client.setClientIdIssuedAt(new Date());

final JSONObject json = registerJsonService.getJSONObject(client);
assertEquals(json.get("org_id"), "testOrgId");
}

@Test
public void getJSONObject_whenOrgIdIsNotSet_shouldHaveNullOrgIdInJson() throws StringEncrypter.EncryptionException {
Client client = new Client();
client.setOrganization(null);
client.setClientIdIssuedAt(new Date());

final JSONObject json = registerJsonService.getJSONObject(client);
assertNull(json.opt("org_id"));
}
}
1 change: 1 addition & 0 deletions jans-auth-server/server/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<class name="io.jans.as.server.register.ws.rs.action.RegisterCreateActionTest" />
<class name="io.jans.as.server.register.ws.rs.RegisterServiceTest" />
<class name="io.jans.as.server.register.ws.rs.RegisterValidatorTest" />
<class name="io.jans.as.server.register.ws.rs.RegisterJsonServiceTest" />

<!-- SESSION -->
<class name="io.jans.as.server.session.ws.rs.EndSessionRestWebServiceImplTest" />
Expand Down

0 comments on commit c4df785

Please sign in to comment.