-
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.
feat(jans-auth-server): added authorization_details custom intercepti…
…on script and dynamic registration #6933 Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>
- Loading branch information
Showing
29 changed files
with
568 additions
and
28 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
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
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
34 changes: 34 additions & 0 deletions
34
jans-auth-server/common/src/main/java/io/jans/as/common/model/authzdetails/AuthzDetail.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,34 @@ | ||
package io.jans.as.common.model.authzdetails; | ||
|
||
import org.json.JSONObject; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
public class AuthzDetail { | ||
|
||
private final JSONObject jsonObject; | ||
|
||
public AuthzDetail(String json) { | ||
this(new JSONObject(json)); | ||
} | ||
|
||
public AuthzDetail(JSONObject jsonObject) { | ||
this.jsonObject = jsonObject; | ||
} | ||
|
||
public JSONObject getJsonObject() { | ||
return jsonObject; | ||
} | ||
|
||
public String getType() { | ||
return jsonObject.optString("type"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AuthzDetail{" + | ||
"jsonObject=" + jsonObject + | ||
'}'; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
jans-auth-server/common/src/main/java/io/jans/as/common/model/authzdetails/AuthzDetails.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,50 @@ | ||
package io.jans.as.common.model.authzdetails; | ||
|
||
import org.json.JSONArray; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
public class AuthzDetails { | ||
private AuthzDetails() { | ||
} | ||
|
||
private final List<AuthzDetail> details = new ArrayList<>(); | ||
|
||
public static AuthzDetails of(String jsonArray) { | ||
return of(new JSONArray(jsonArray)); | ||
} | ||
|
||
public static AuthzDetails ofSilently(String jsonArray) { | ||
try { | ||
return of(new JSONArray(jsonArray)); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
public static AuthzDetails of(JSONArray jsonArray) { | ||
AuthzDetails result = new AuthzDetails(); | ||
for (int i = 0; i < jsonArray.length(); i++) { | ||
result.details.add(new AuthzDetail(jsonArray.getJSONObject(i))); | ||
} | ||
return result; | ||
} | ||
|
||
public List<AuthzDetail> getDetails() { | ||
return details; | ||
} | ||
|
||
public Set<String> getTypes() { | ||
Set<String> result = new HashSet<>(); | ||
for (AuthzDetail d : details) { | ||
result.add(d.getType()); | ||
} | ||
return result; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...th-server/common/src/test/java/io/jans/as/common/model/authzdetails/AuthzDetailsTest.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,33 @@ | ||
package io.jans.as.common.model.authzdetails; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNull; | ||
import static org.testng.AssertJUnit.assertNotNull; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
public class AuthzDetailsTest { | ||
|
||
@Test | ||
public void ofSilently_withInvalidJson_shouldReturnNull() { | ||
assertNull(AuthzDetails.ofSilently("invalidJson")); | ||
} | ||
|
||
@Test | ||
public void ofSilently_withValidJson_shouldReturnNotNull() { | ||
assertNotNull(AuthzDetails.ofSilently("[]")); | ||
} | ||
|
||
@Test | ||
public void getTypes_withValidJson_shouldReturnNotNull() { | ||
final AuthzDetails details = AuthzDetails.ofSilently("[{\"type\":\"internal_type\"}]"); | ||
assertNotNull(details); | ||
assertEquals(details.getTypes(), new HashSet<>(Collections.singletonList("internal_type"))); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.