use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class AttributeServerTest method testAttributeServerRemove.
public void testAttributeServerRemove(CMTestStoreProvider tp2) throws Exception {
CC cc = setupClients(tp2);
AttributeServer attributeServer = new AttributeServer(tp2.getCOSE());
OA2ClientKeys keys = getClientKeys(tp2);
JSONArray attributes = new JSONArray();
attributes.add(keys.homeURL());
attributes.add(keys.email());
attributes.add(keys.rtLifetime());
attributes.add(keys.scopes());
AttributeRemoveRequest req = RequestFactory.createRequest(cc.adminClient, new TypeAttribute(), new ActionRemove(), cc.client, attributes);
AttributeClientResponse resp = (AttributeClientResponse) attributeServer.process(req);
OA2Client client = (OA2Client) resp.getClient();
assert client.getScopes() == null || client.getScopes().isEmpty();
assert client.getRtLifetime() == 0L;
assert client.getHomeUri() == null;
assert client.getEmail() == null;
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class AttributeServerTest method testAttributeServerGet.
public void testAttributeServerGet(CMTestStoreProvider tp2) throws Exception {
CC cc = setupClients(tp2);
AttributeServer attributeServer = new AttributeServer(tp2.getCOSE());
OA2ClientKeys keys = getClientKeys(tp2);
JSONArray array = new JSONArray();
array.add(keys.scopes());
array.add(keys.callbackUri());
array.add(keys.rtLifetime());
array.add(keys.name());
AttributeGetRequest req = RequestFactory.createRequest(cc.adminClient, new TypeAttribute(), new ActionGet(), cc.client, array);
AttributeClientResponse r = (AttributeClientResponse) attributeServer.process(req);
OA2Client reducedClient = (OA2Client) r.getClient();
assert reducedClient.getIdentifier().equals(cc.client.getIdentifier());
assert reducedClient.getScopes() != null;
assert reducedClient.getCallbackURIs() != null;
assert reducedClient.getRtLifetime() == cc.client.getRtLifetime();
assert reducedClient.getName().equals(cc.client.getName());
JSONObject json = new JSONObject();
tp2.getClientStore().getACConverter().toJSON(r.getClient(), json);
System.out.println(json);
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class OA2TConverter method fromMap.
@Override
public V fromMap(ConversionMap<String, Object> map, V v) {
V st = super.fromMap(map, v);
Object refreshToken = map.get(getTCK().refreshToken());
if (refreshToken != null) {
if (refreshToken instanceof RefreshToken) {
st.setRefreshToken((RefreshToken) refreshToken);
} else {
st.setRefreshToken(getTF2().getRefreshToken(refreshToken.toString()));
}
}
st.setRefreshTokenValid(map.getBoolean(getTCK().refreshTokenValid()));
st.setRefreshTokenLifetime(map.getLong(getTCK().expiresIn()));
st.setCallback(map.getURI(getTCK().callbackUri()));
st.setNonce(map.getString(getTCK().nonce()));
if (map.get(getTCK().scopes()) != null) {
net.sf.json.JSONArray json = (JSONArray) JSONSerializer.toJSON(map.get(getTCK().scopes()));
Collection<String> zzz = (Collection<String>) JSONSerializer.toJava(json);
st.setScopes(zzz);
}
if (map.get(getTCK().authTime()) != null) {
st.setAuthTime(map.getDate(getTCK().authTime));
}
if (map.get(getTCK().flowStates()) != null) {
st.setFlowStates(new FlowStates((JSONObject) JSONSerializer.toJSON(map.get(getTCK().flowStates()))));
} else {
st.setFlowStates(new FlowStates());
}
return st;
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class OA2ClientCommands method extraUpdates.
/**
* In this case, the secret has to be gotten and processed into a hash,
* callback uris listed and the refresh token lifetime set.
* Do not call super on this method since the standard client tracks a public key file rather
* than the hash of a secret string.
*
* @param identifiable
*/
@Override
public void extraUpdates(Identifiable identifiable) {
OA2Client client = (OA2Client) identifiable;
String secret = client.getSecret();
String input;
boolean askForSecret = true;
while (askForSecret) {
input = getInput("enter a new secret or return to skip.", secret);
if (isEmpty(input)) {
sayi("Nothing entered. Client secret entry skipped.");
break;
}
if (input.equals(secret)) {
sayi(" Client secret entry skipped.");
break;
}
// input is not empty.
secret = DigestUtils.sha1Hex(input);
client.setSecret(secret);
askForSecret = false;
}
OA2Client oa2Client = (OA2Client) identifiable;
if (isRefreshTokensEnabled()) {
// so at this point the server actually allows for refresh tokens
String NONE = "none";
String rtString = oa2Client.isRTLifetimeEnabled() ? Long.toString(oa2Client.getRtLifetime() / 1000) : NONE;
String rawLifetime = getInput("enter the refresh lifetime in ms.", rtString);
if (rawLifetime == null || rawLifetime.length() == 0 || rawLifetime.toLowerCase().equals(NONE)) {
oa2Client.setRtLifetime(0);
} else {
try {
oa2Client.setRtLifetime(Long.parseLong(rawLifetime));
} catch (Throwable t) {
sayi("Sorry but \"" + rawLifetime + "\" is not a valid number. No change.");
}
}
}
boolean publicClient = oa2Client.isPublicClient();
String rawPC = getInput("is this client public?", Boolean.toString(publicClient));
if (rawPC != null && rawPC.toLowerCase().equalsIgnoreCase("y") || rawPC.toLowerCase().equalsIgnoreCase("yes")) {
rawPC = "true";
}
try {
boolean x = Boolean.parseBoolean(rawPC);
oa2Client.setPublicClient(x);
} catch (Throwable t) {
sayi("Sorry, but unable to parse the response of \"" + rawPC + "\". No change.");
}
String issuer = getInput("enter the issuer (optional)", oa2Client.getIssuer());
if (!isEmpty(issuer)) {
oa2Client.setIssuer(issuer);
}
String signTokens = getInput("Enable ID token signing (true/false)?", Boolean.toString(oa2Client.isSignTokens()));
if (!isEmpty(signTokens)) {
try {
oa2Client.setSignTokens(Boolean.parseBoolean(signTokens));
} catch (Throwable t) {
// do nothing.
sayi("Unknown response of \"" + signTokens + "\". Must be \"true\" or \"false\", ignoring.");
}
}
String currentScopes = null;
if (oa2Client.getScopes() != null) {
boolean firstPass = true;
for (String x : oa2Client.getScopes()) {
if (firstPass) {
firstPass = false;
currentScopes = x;
} else {
currentScopes = currentScopes + "," + x;
}
}
}
String scopes = getInput("enter a comma separated list of scopes. Scopes to this server will be rejected.", currentScopes);
if (!(scopes == null || scopes.isEmpty())) {
LinkedList<String> list = new LinkedList<>();
StringTokenizer stringTokenizer = new StringTokenizer(scopes, ",");
while (stringTokenizer.hasMoreTokens()) {
String raw = stringTokenizer.nextToken().trim();
if (getSupportedScopes().contains(raw)) {
list.add(raw);
} else {
say("Unknown scope \"" + raw + "\" rejected.");
}
}
oa2Client.setScopes(list);
}
// Now do much the same for the list of callback URIs
String currentUris = null;
if (oa2Client.getCallbackURIs() != null) {
boolean firstPass = true;
for (String x : oa2Client.getCallbackURIs()) {
if (firstPass) {
firstPass = false;
currentUris = x;
} else {
currentUris = currentUris + "," + x;
}
}
}
String uris = getInput("enter a comma separated list of callback uris. These must start with https or they will be ignored.", currentUris);
if (!uris.isEmpty()) {
LinkedList<String> list = new LinkedList<>();
StringTokenizer stringTokenizer = new StringTokenizer(uris, ",");
while (stringTokenizer.hasMoreTokens()) {
String raw = stringTokenizer.nextToken().trim();
try {
URI uri = URI.create(raw);
if (uri.getScheme().toLowerCase().equals("https")) {
list.add(raw);
} else {
sayi("\"" + raw + "\" rejected -- illegal protocol");
}
} catch (Throwable t) {
// do nothing. Just ignore illegal uris.
sayi("\"" + raw + "\" rejected -- illegal uri");
}
}
oa2Client.setCallbackURIs(list);
}
String currentLDAPs = null;
if (client.getLdaps() == null || client.getLdaps().isEmpty()) {
currentLDAPs = "";
} else {
currentLDAPs = LDAPConfigurationUtil.toJSON(client.getLdaps()).toString();
}
String ldaps = getInput("Enter a valid JSON object or array for the ldap configuration(s).", currentLDAPs);
if (!ldaps.isEmpty()) {
// try to parse it as a single LDAP entry
JSON json = null;
try {
JSONArray array = JSONArray.fromObject(ldaps);
json = array;
} catch (Throwable t) {
// ok, so that is not an array, try a singleton
try {
JSONObject jsonObject = JSONObject.fromObject(ldaps);
json = jsonObject;
} catch (Throwable tt) {
sayi("Sorry, could not parse JSON");
}
if (json != null) {
client.setLdaps(LDAPConfigurationUtil.fromJSON(json));
}
}
}
}
use of net.sf.json.JSONArray in project beijingThirdPeriod by weidongcao.
the class ListSort method main.
public static void main(String[] args) throws IOException {
File file = FileUtils.getFile("D:\\0WorkSpace\\JetBrains\\beijingThirdPeriod\\createIndexRecord\\index-record.txt");
List<String> list = FileUtils.readLines(file, "utf-8");
Collections.sort(list);
Map<String, String> map = list.stream().collect(Collectors.toMap(str -> str.split("\t")[0], str -> str.split("\t")[1]));
// String content = Stream.of(map)
// List<String> listFromMap = map.entrySet().stream().collect(Collectors.toList(Map.Entry :: getKey + "\t", Map.Entry :: getValue));
// map.entrySet().stream().flatMap(m -> {return m.getKey() + "\t" + m.getValue();});
JSONArray jsonArray = JSONArray.fromObject(list);
System.out.println(jsonArray.join("\r\n"));
JSONObject jsonObject = JSONObject.fromObject(map);
System.out.println(jsonObject.toString());
}
Aggregations