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
Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>
  • Loading branch information
yuriyz committed Sep 21, 2023
1 parent 33d7151 commit 957792f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
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,66 @@
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 957792f

Please sign in to comment.