use of edu.uiuc.ncsa.security.oauth_2_0.OA2Client in project OA4MP by ncsa.
the class ClientServerTest method testCreatePublicClient.
public void testCreatePublicClient(CMTestStoreProvider tp2) throws Exception {
// only needs an admin client and map.
CC cc = setupClients(tp2);
cc.client.setPublicClient(true);
tp2.getClientStore().save(cc.client);
OA2ClientConverter converter = getClientConverter(tp2);
ColumnMap values = new ColumnMap();
converter.toMap(cc.client, values);
tp2.getClientStore().remove(cc.client.getIdentifier());
assert !tp2.getClientStore().containsKey(cc.client.getIdentifier());
// remove the identifier and create it
OA2ClientKeys clientKeys = getClientKeys(tp2);
values.remove(clientKeys.identifier());
values.remove(clientKeys.creationTS());
JSONObject json = new JSONObject();
json.putAll(values);
CreateRequest req = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionCreate(), null, json);
ClientServer server = new ClientServer(tp2.getCOSE());
CreateResponse resp = (CreateResponse) server.process(req);
OA2Client newClient = resp.getClient();
assert tp2.getClientStore().containsKey(newClient.getIdentifier());
// quick and dirty check
OA2Client oldClient = (OA2Client) cc.client;
oldClient.setIdentifier(newClient.getIdentifier());
oldClient.setSecret(newClient.getSecret());
assert oldClient.equals(newClient);
}
use of edu.uiuc.ncsa.security.oauth_2_0.OA2Client in project OA4MP by ncsa.
the class ClientServerTest method testCreate.
public void testCreate(CMTestStoreProvider tp2) throws Exception {
// only needs an admin client and map.
CC cc = setupClients(tp2);
OA2ClientConverter converter = getClientConverter(tp2);
ColumnMap values = new ColumnMap();
converter.toMap(cc.client, values);
tp2.getClientStore().remove(cc.client.getIdentifier());
assert !tp2.getClientStore().containsKey(cc.client.getIdentifier());
// remove the identifier and create it
OA2ClientKeys clientKeys = getClientKeys(tp2);
values.remove(clientKeys.identifier());
values.remove(clientKeys.creationTS());
JSONObject json = new JSONObject();
json.putAll(values);
CreateRequest req = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionCreate(), null, json);
ClientServer server = new ClientServer(tp2.getCOSE());
CreateResponse resp = (CreateResponse) server.process(req);
OA2Client newClient = resp.getClient();
assert tp2.getClientStore().containsKey(newClient.getIdentifier());
// quick and dirty check
OA2Client oldClient = (OA2Client) cc.client;
oldClient.setIdentifier(newClient.getIdentifier());
oldClient.setSecret(newClient.getSecret());
assert oldClient.equals(newClient);
}
use of edu.uiuc.ncsa.security.oauth_2_0.OA2Client in project OA4MP by ncsa.
the class DDServerTests method getOa2Client.
protected OA2Client getOa2Client(ClientStore store) {
OA2Client c = (OA2Client) store.create();
String random = getRandom(8);
c.setSecret(getRandom(64));
c.setProxyLimited(true);
c.setHomeUri("https://baz.foo.edu/" + random + "/home");
c.setErrorUri("https://baz.foo.edu/home/" + random + "/error");
c.setProxyLimited(false);
c.setEmail("bob@" + random + ".foo.bar");
c.setName("Test client " + random);
c.setRtLifetime(456767875477L);
LinkedList<String> callbacks = new LinkedList<>();
callbacks.add("https:/baz.foo.edu/client2/" + random + "/ready1");
callbacks.add("https:/baz.foo.edu/client2/" + random + "/ready2");
c.setCallbackURIs(callbacks);
LDAPConfiguration ldapConfiguration = new LDAPConfiguration();
ldapConfiguration.setServer("foo.bar.edu");
LinkedList<LDAPConfiguration> ldaps = new LinkedList<>();
ldaps.add(ldapConfiguration);
c.setLdaps(ldaps);
LinkedList<String> scopes = new LinkedList<>();
scopes.add(OA2Scopes.SCOPE_OPENID);
scopes.add(OA2Scopes.SCOPE_EMAIL);
scopes.add(OA2Scopes.SCOPE_PROFILE);
scopes.add(OA2Scopes.SCOPE_CILOGON_INFO);
c.setScopes(scopes);
store.save(c);
return c;
}
use of edu.uiuc.ncsa.security.oauth_2_0.OA2Client in project OA4MP by ncsa.
the class FunctorTests method testCIL2.
@Test
public void testCIL2() throws Exception {
HashMap<String, Object> claims2 = new HashMap<>();
claims2.put("sub", "http://cilogon.org/serverT/users/173048");
claims2.put("idp_name", "National Center for Supercomputing Applications");
claims2.put("idp", "https://idp.ncsa.illinois.edu/idp/shibboleth");
claims2.put("mail", "gaynor@illinois.edu");
claims2.put("affiliation", "staff@ncsa.illinois.edu;employee@ncsa.illinois.edu;member@ncsa.illinois.edu");
claims2.put("eppn", "jgaynor@ncsa.illinois.edu");
claims2.put("cert_subject_dn", "/DC=org/DC=cilogon/C=US/O=National Center for Supercomputing Applications/CN=Jeffrey Gaynor T173053 email=gaynor@illinois.edu");
claims2.put("name", "Jeffrey Gaynor");
claims2.put("isMemberOf", "[\"cn=jira-users,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=org_all_groups,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=all_ncsa_employe,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=grp_jira_users,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=all_users,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=grp_bldg_ncsa,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=grp_bldg_both,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=org_cisr,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=org_ici,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=org_csd,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=prj_cerb_users,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=iam_sec_testing,ou=Groups,dc=ncsa,dc=illinois,dc=edu\",\"cn=all_building,ou=Groups,dc=ncsa,dc=illinois,dc=edu\"]");
claims2.put("given_name", "Jeffrey");
claims2.put("family_name", "Gaynor");
claims2.put("email", "gaynor@illinois.edu}");
String rawConfig = "{\"config\":\"testforurgeclient\",\"id_token\":{\"$if\":{\"$match\":[\"${idp}\",\"https://idp.ncsa.illinois.edu/idp/shibboleth\"]},\"$then\":{\"$set\":[\"sub\",\"${eppn}\"]}}}";
OA2Client client = new OA2Client(BasicIdentifier.newID("test:client:42"));
client.setConfig(JSONObject.fromObject(rawConfig));
ClaimsProcessor ch = new ClaimsProcessor(client.getClaimsConfig());
DebugUtil.setIsEnabled(true);
Map<String, Object> claims3 = ch.process(claims2);
System.out.println("\n*** CIL2 claims handler test");
System.out.println(claims3);
System.out.println("\n*** done. Returned claims:");
assert claims3.get("sub").equals(claims2.get("eppn"));
}
use of edu.uiuc.ncsa.security.oauth_2_0.OA2Client in project OA4MP by ncsa.
the class PermissionServerTest method testGetClients.
public void testGetClients(CMTestStoreProvider tp2) throws Exception {
int clientCount = 4;
CC cc = setupClients(tp2);
List<OA2Client> clients = new LinkedList<>();
for (int i = 0; i < clientCount; i++) {
OA2Client client2 = getOa2Client(tp2.getClientStore());
Permission p = tp2.getPermissionStore().create();
p.setDelete(true);
p.setRead(true);
p.setApprove(true);
p.setCreate(true);
p.setWrite(true);
p.setAdminID(cc.adminClient.getIdentifier());
p.setClientID(client2.getIdentifier());
tp2.getPermissionStore().save(p);
clients.add(client2);
}
clients.add(cc.client);
// need this list of identifiers later for checking that the returned result is correct.
List<Identifier> clientIDs = new LinkedList<>();
for (OA2Client ac : clients) {
clientIDs.add(ac.getIdentifier());
}
PermissionServer permissionServer = new PermissionServer(tp2.getCOSE());
ListClientsRequest req = (ListClientsRequest) RequestFactory.createRequest(cc.adminClient, new TypePermission(), new ActionList(), null, null);
ListClientResponse resp = (ListClientResponse) permissionServer.process(req);
// so add a bunch of admins for a single client and check that they all come back.
List<OA2Client> returnedACs = resp.getClients();
assert returnedACs.size() == clients.size();
for (OA2Client x : returnedACs) {
assert clientIDs.contains(x.getIdentifier());
}
}
Aggregations