Search in sources :

Example 1 with ClientKeys

use of edu.uiuc.ncsa.security.delegation.storage.ClientKeys in project OA4MP by ncsa.

the class ClientServer method create.

public CreateResponse create(CreateRequest request) {
    if (request.getAdminClient() != null && (request.getAdminClient().getIdentifier() == null || request.getAdminClient().getIdentifierString().length() == 0)) {
        throw new GeneralException("Error: An admin client was specified, but no identifier for this client was given. Request rejected.");
    }
    // canCreate(request);
    // requires and admin client and hashmap
    ColumnMap values = new ColumnMap();
    values.putAll(request.getAttributes());
    // values.putAll(); // add all the values passed in
    ClientKeys keys = (ClientKeys) getClientStore().getACConverter().getKeys();
    OA2Client client = (OA2Client) getClientStore().create();
    values.put(keys.identifier(), client.getIdentifier());
    values.put(keys.creationTS(), client.getCreationTS());
    String secret = null;
    if (values.containsKey(keys.secret())) {
        // if the secret is supplied, just store its hash
        secret = (String) values.get(keys.secret());
    } else {
        // no secret means to create one.
        byte[] bytes = new byte[cose.getClientSecretLength()];
        random.nextBytes(bytes);
        secret = Base64.encodeBase64URLSafeString(bytes);
    }
    String hash = DigestUtils.sha1Hex(secret);
    values.put(keys.secret(), hash);
    getClientStore().getACConverter().fromMap(values, client);
    getClientStore().save(client);
    // set the permissions for this.
    if (request.getAdminClient() != null) {
        // if there is no admin client, then do not set permissions for it. It is possible for a client to simply
        // be created and manage itself.
        PermissionServer permissionServer = new PermissionServer(cose);
        permissionServer.process(RequestFactory.createRequest(request.getAdminClient(), new TypePermission(), new ActionAdd(), client, null));
    }
    // CIL-414 Make sure an approval record is created here so we can accurately track how many approvals are pending
    ClientApproval approval = (ClientApproval) getClientApprovalStore().create();
    approval.setApproved(false);
    approval.setIdentifier(client.getIdentifier());
    getClientApprovalStore().save(approval);
    return new CreateResponse(client, secret);
}
Also used : ColumnMap(edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) PermissionServer(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.permissions.PermissionServer) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) TypePermission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission) ActionAdd(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionAdd) ClientKeys(edu.uiuc.ncsa.security.delegation.storage.ClientKeys)

Example 2 with ClientKeys

use of edu.uiuc.ncsa.security.delegation.storage.ClientKeys in project OA4MP by ncsa.

the class SATFactory method getSubject.

public static BaseClient getSubject(JSONObject json) {
    JSONObject api = json.getJSONObject(KEYS_API);
    JSONObject subject = api.getJSONObject(KEYS_SUBJECT);
    if (subject.containsKey(SUBJECT_ADMIN)) {
        return getACConverter().fromJSON(subject);
    }
    if (subject.containsKey(SUBJECT_CLIENT)) {
        JSONObject j2 = subject.getJSONObject(SUBJECT_CLIENT);
        SerializationKeys k1 = getClientConverter().getKeys();
        String secretKey = ((ClientKeys) k1).secret();
        if (j2.containsKey(CLIENT_SECRET_KEY)) {
            j2.put(secretKey, j2.getString(CLIENT_SECRET_KEY));
            j2.remove(CLIENT_SECRET_KEY);
        }
        return getClientConverter().fromJSON(subject);
    }
    return null;
}
Also used : JSONObject(net.sf.json.JSONObject) SerializationKeys(edu.uiuc.ncsa.security.storage.data.SerializationKeys) ClientKeys(edu.uiuc.ncsa.security.delegation.storage.ClientKeys)

Aggregations

ClientKeys (edu.uiuc.ncsa.security.delegation.storage.ClientKeys)2 PermissionServer (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.permissions.PermissionServer)1 ActionAdd (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionAdd)1 TypePermission (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission)1 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)1 ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)1 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)1 SerializationKeys (edu.uiuc.ncsa.security.storage.data.SerializationKeys)1 ColumnMap (edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap)1 JSONObject (net.sf.json.JSONObject)1