-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oxauth): add first party native authn support #1925
- Loading branch information
Showing
4 changed files
with
658 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
Model/src/main/java/org/gluu/oxauth/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,44 @@ | ||
package org.gluu.oxauth.model.authzdetails; | ||
|
||
import org.json.JSONObject; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
public class AuthzDetail { | ||
|
||
private final JSONObject jsonObject; | ||
private String uiRepresentation; | ||
|
||
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"); | ||
} | ||
|
||
public String getUiRepresentation() { | ||
return uiRepresentation; | ||
} | ||
|
||
public void setUiRepresentation(String uiRepresentation) { | ||
this.uiRepresentation = uiRepresentation; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AuthzDetail{" + | ||
"jsonObject=" + jsonObject + | ||
"uiRepresentation=" + uiRepresentation + | ||
'}'; | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
Model/src/main/java/org/gluu/oxauth/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,105 @@ | ||
package org.gluu.oxauth.model.authzdetails; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.json.JSONArray; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
public class AuthzDetails { | ||
|
||
private final List<AuthzDetail> details; | ||
|
||
public AuthzDetails(List<AuthzDetail> details) { | ||
this.details = details; | ||
} | ||
|
||
public AuthzDetails() { | ||
this(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 static boolean similar(String authorizationDetails1, String authorizationDetails2) { | ||
if (StringUtils.equals(authorizationDetails1, authorizationDetails2)) { | ||
return true; | ||
} | ||
if (authorizationDetails1 == null || authorizationDetails2 == null) { | ||
return false; | ||
} | ||
JSONArray array1 = new JSONArray(authorizationDetails1); | ||
JSONArray array2 = new JSONArray(authorizationDetails2); | ||
return array1.similar(array2); | ||
} | ||
|
||
public static String simpleMerge(String authorizationDetails1, String authorizationDetails2) { | ||
final AuthzDetails details1 = AuthzDetails.of(authorizationDetails1); | ||
final AuthzDetails details2 = AuthzDetails.of(authorizationDetails2); | ||
details1.getDetails().addAll(details2.getDetails()); | ||
return details1.asJsonArray().toString(); | ||
} | ||
|
||
public JSONArray asJsonArray() { | ||
JSONArray array = new JSONArray(); | ||
array.putAll(details.stream().map(AuthzDetail::getJsonObject).collect(Collectors.toList())); | ||
return array; | ||
} | ||
|
||
public String asJsonString() { | ||
return asJsonArray().toString(); | ||
} | ||
|
||
public boolean similar(String authorizationDetails) { | ||
if (StringUtils.isBlank(authorizationDetails)) { | ||
return false; | ||
} | ||
return asJsonArray().similar(new JSONArray(authorizationDetails)); | ||
} | ||
|
||
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; | ||
} | ||
|
||
public static boolean isEmpty(AuthzDetails authzDetails) { | ||
return authzDetails == null || authzDetails.getDetails() == null || authzDetails.getDetails().isEmpty(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AuthzDetails{" + | ||
"details=" + details + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.