Search in sources :

Example 6 with ClientApproval

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

the class AbstractCLIApprover method doIt.

@Override
public void doIt() throws Exception {
    Set keys = se.getClientApprovalStore().keySet();
    LinkedList<ClientApproval> linkedList = new LinkedList<ClientApproval>();
    info("starting approval");
    int i = 0;
    for (Object k : keys) {
        ClientApproval ca = (ClientApproval) se.getClientApprovalStore().get(k);
        linkedList.add(ca);
        say((i++) + ". " + (ca.isApproved() ? "(A) " : "(D) ") + linkedList.getLast().getIdentifierString());
    }
    if (linkedList.isEmpty()) {
        say("(No entries found. You will need to manually enter the id.)");
    }
    boolean keepAsking = true;
    String inString;
    ClientApproval ca = null;
    while (keepAsking) {
        say("Enter the number of the client to approve or disapprove, OR, enter an id, starting with a " + ID_DELIMITER);
        inString = readline();
        if (inString.startsWith(ID_DELIMITER)) {
            ca = new ClientApproval(new BasicIdentifier(inString.substring(ID_DELIMITER.length())));
            keepAsking = false;
        } else {
            try {
                int index = Integer.parseInt(inString);
                if (0 <= index && index < linkedList.size()) {
                    ca = linkedList.get(index);
                    keepAsking = false;
                } else {
                    say("Sorry, that index is out of range. Try again.");
                }
            } catch (NumberFormatException xx) {
                boolean noInput = inString == null || inString.length() == 0;
                say("Woops. Didn't understand " + (noInput ? "(empty)" : "\"" + inString + "\"") + ". Try again.");
            }
        }
    }
    if (ca == null) {
        // future proof. Should never happen.
        warn("No client approval found. Aborting session");
        throw new GeneralException("Internal error: Somehow the client approval was not found. Fix that.");
    }
    Client client = (Client) se.getClientStore().get(ca.getIdentifier());
    if (client == null) {
        info("No client found for the given identifier. Aborting.");
        say("no client found for the id. You probably want to fix that.\nexiting...");
        return;
    } else {
        say("You have chosen the following client");
        say(formatClient(client));
    }
    say("Enter your approver name [" + ANONYMOUS + "]:");
    inString = readline();
    ca.setApproved(true);
    if (inString == null || 0 == inString.length()) {
        ca.setApprover(ANONYMOUS);
    } else {
        ca.setApprover(inString);
    }
    info("Approver is identifier as " + ca.getApprover());
    say("Enter Approve or Deny (A/D) [D]");
    inString = readline();
    if (inString != null && inString.toLowerCase().equals("a")) {
        ca.setApproved(true);
    }
    info("Approver " + (ca.isApproved() ? "denies" : "allows") + " approval.");
    say("Commit changes? (y/n)");
    inString = readline();
    if (!inString.toLowerCase().equals("y")) {
        info("Approval aborted manually. No changes saved.");
        say("You didn't explicitly say to save it -- operation aborted.\nexiting...");
        return;
    }
    // update timestamp to now.
    ca.setApprovalTimestamp(new Date());
    if (pollingDir != null) {
        // use polling
        File tempFile = File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX, pollingDir);
        FileOutputStream fos = new FileOutputStream(tempFile);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(ca);
        fos.flush();
        fos.close();
    } else {
        // do the approval directly
        se.getClientApprovalStore().save(ca);
    }
    info("Approval for client with id \"" + ca.getIdentifierString() + "\" finished.");
}
Also used : Set(java.util.Set) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) LinkedList(java.util.LinkedList) Date(java.util.Date) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) Client(edu.uiuc.ncsa.security.delegation.storage.Client)

Example 7 with ClientApproval

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

the class ClientServer method approve.

public ClientResponse approve(ApproveRequest request) {
    canApprove(request);
    Identifier id = request.getClient().getIdentifier();
    ClientApproval approval = null;
    OA2ClientApprovalKeys keys = new OA2ClientApprovalKeys();
    if (getClientApprovalStore().containsKey(id)) {
        approval = (ClientApproval) getClientApprovalStore().get(id);
    } else {
        approval = (ClientApproval) getClientApprovalStore().create();
        // approval ID must be the same as the client's
        approval.setIdentifier(id);
    }
    if (request.getAttributes() != null && request.getAttributes().containsKey(keys.approver())) {
        approval.setApprover(String.valueOf(request.getAttributes().get(keys.approver())));
    } else {
        approval.setApprover(request.getAdminClient().getIdentifierString());
    }
    approval.setApproved(true);
    getClientApprovalStore().save(approval);
    return new ClientResponse();
}
Also used : Identifier(edu.uiuc.ncsa.security.core.Identifier) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) OA2ClientApprovalKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientApprovalKeys)

Example 8 with ClientApproval

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

the class OA2RegistrationServlet method addNewClient.

protected Client addNewClient(HttpServletRequest request, HttpServletResponse response, boolean fireClientEvents) throws Throwable {
    OA2Client client = (OA2Client) super.addNewClient(request, response);
    String rawCBs = getRequiredParam(request, CALLBACK_URI, client);
    String rawRTLifetime = getParameter(request, REFRESH_TOKEN_LIFETIME);
    String[] rawScopes = request.getParameterValues("chkScopes");
    if (rawScopes != null) {
        Collection<String> newScopes = new LinkedList<>();
        boolean hasDefaultScope = false;
        for (String scope : rawScopes) {
            if (OA2Scopes.SCOPE_OPENID.equals(scope))
                hasDefaultScope = true;
            newScopes.add(scope);
        }
        if (!hasDefaultScope) {
            // has to be there or all requests are rejected.
            newScopes.add(OA2Scopes.SCOPE_OPENID);
        }
        client.setScopes(newScopes);
    }
    String issuer = getParameter(request, ISSUER_NAME);
    String ldap = getParameter(request, LDAP_NAME);
    if (!isEmpty(issuer)) {
        client.setIssuer(issuer);
    }
    if (!isEmpty(ldap)) {
        try {
            JSON json = JSONObject.fromObject(ldap);
            Collection<LDAPConfiguration> ldapConfiguration = LDAPConfigurationUtil.fromJSON(json);
            client.setLdaps(ldapConfiguration);
        } catch (Throwable t) {
            warn("Could not parse LDAP string during client registration for \"" + client.getIdentifierString() + "\". Skipping...");
        }
    }
    try {
        URI.create(client.getHomeUri());
    } catch (Throwable t) {
        throw new ClientRegistrationRetryException("Error. The stated home uri is invalid: " + t.getMessage(), null, client);
    }
    if (rawRTLifetime == null || rawRTLifetime.length() == 0) {
        // This effectively means there is no refresh token set.
        // FIXES CIL-309 (partial)
        client.setRtLifetime(0);
    } else {
        long clientRtLifetime = 0L;
        boolean rtLifetimeOK = true;
        if (rawRTLifetime != null && 0 < rawRTLifetime.length()) {
            try {
                // The value is in seconds on the form
                clientRtLifetime = Long.parseLong(rawRTLifetime) * 1000;
                if (clientRtLifetime < 0) {
                    rtLifetimeOK = false;
                } else {
                    rtLifetimeOK = true;
                }
            } catch (Throwable t) {
                // do nix...
                rtLifetimeOK = false;
            }
            if (!rtLifetimeOK) {
                info("Client requested illegal value for refresh token lifetime at registration of \"" + rawRTLifetime + "\"");
            }
        }
        // FIX CIL-309 (partial)
        client.setRtLifetime(Math.min(getOA2SE().getMaxClientRefreshTokenLifetime(), clientRtLifetime));
    }
    // Now generate the client secret. We generate this here:
    byte[] bytes = new byte[getOA2SE().getClientSecretLength()];
    random.nextBytes(bytes);
    String secret64 = Base64.encodeBase64URLSafeString(bytes);
    // we have to return this to the client registration ok page and store a hash of it internally
    // so we don't have a copy of it any place but the client.
    // After this is displayed the secret is actually hashed and stored.
    client.setSecret(secret64);
    BufferedReader br = new BufferedReader(new StringReader(rawCBs));
    String x = br.readLine();
    LinkedList<String> uris = new LinkedList<>();
    while (x != null) {
        if (!x.toLowerCase().startsWith("https:")) {
            warn("Attempt to add bad callback uri for client " + client.getIdentifierString());
            throw new ClientRegistrationRetryException("The callback \"" + x + "\" is not secure.", null, client);
        }
        // passes here means it is a uri. All we want this to do is throw an exception if needed.
        URI.create(x);
        uris.add(x);
        // skip it.
        x = br.readLine();
    }
    br.close();
    client.setCallbackURIs(uris);
    // part of CIL-359, signing ID tokens.
    client.setSignTokens(true);
    // CIL-414 makes the approval record here so that we can get an accurate count later.
    ClientApproval approval = (ClientApproval) getOA2SE().getClientApprovalStore().create();
    approval.setApproved(false);
    approval.setIdentifier(client.getIdentifier());
    getOA2SE().getClientApprovalStore().save(approval);
    if (fireClientEvents) {
        fireNewClientEvent(client);
    }
    return client;
}
Also used : JSON(net.sf.json.JSON) LDAPConfiguration(edu.uiuc.ncsa.security.oauth_2_0.server.config.LDAPConfiguration) LinkedList(java.util.LinkedList) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader)

Example 9 with ClientApproval

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

the class ServiceConfigTest method testClientApprovalStoreProvider.

public void testClientApprovalStoreProvider() throws Exception {
    ConfigurationNode cn = getConfig("postgresql config");
    MultiDSClientApprovalStoreProvider dap = new MultiDSClientApprovalStoreProvider(cn, true, new MyLoggingFacade("test"), null, null);
    ClientApproverConverter cp = new ClientApproverConverter(new ClientApprovalProvider());
    dap.addListener(new DSFSClientApprovalStoreProvider(cn, cp));
    dap.addListener(new DSSQLClientApprovalStoreProvider(cn, new MySQLConnectionPoolProvider("oauth", "oauth"), MYSQL_STORE, cp));
    dap.addListener(new DSSQLClientApprovalStoreProvider(cn, new PGConnectionPoolProvider("oauth", "oauth"), POSTGRESQL_STORE, cp));
    ClientApprovalStore<ClientApproval> as = (ClientApprovalStore<ClientApproval>) dap.get();
}
Also used : MultiDSClientApprovalStoreProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.storage.MultiDSClientApprovalStoreProvider) MyLoggingFacade(edu.uiuc.ncsa.security.core.util.MyLoggingFacade) MySQLConnectionPoolProvider(edu.uiuc.ncsa.security.storage.sql.mysql.MySQLConnectionPoolProvider) PGConnectionPoolProvider(edu.uiuc.ncsa.security.storage.sql.postgres.PGConnectionPoolProvider) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) ConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode) DSFSClientApprovalStoreProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStoreProvider) ClientApproverConverter(edu.uiuc.ncsa.myproxy.oa4mp.server.util.ClientApproverConverter) ClientApprovalStore(edu.uiuc.ncsa.security.delegation.server.storage.ClientApprovalStore) ClientApprovalProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.ClientApprovalProvider) DSSQLClientApprovalStoreProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.storage.sql.provider.DSSQLClientApprovalStoreProvider)

Example 10 with ClientApproval

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

the class FSCAStoreTest method testPermissions.

public void testPermissions() throws Exception {
    File storeDirectory = File.createTempFile("fs-store", "-tmp");
    File indexDirectory = File.createTempFile("fs-index", "-tmp");
    storeDirectory.setWritable(false);
    indexDirectory.setWritable(false);
    assert !storeDirectory.canWrite();
    FSClientApprovalStore x = null;
    final ClientApprovalProvider caProvider = new ClientApprovalProvider();
    try {
        // Make sure that if someone creates a bad one, it blows up in the constructor.
        x = new FSClientApprovalStore(null, null, null, null) {

            @Override
            public Object put(Object key, Object value) {
                return null;
            }
        };
        assert false : "Could make a new object without being properly configured";
    } catch (MyConfigurationException xx) {
        assert true;
    }
    x = new DSFSClientApprovalStore(storeDirectory, indexDirectory, caProvider, new ClientApproverConverter(caProvider));
    try {
        // should bomb here.
        x.create();
        assert false;
    } catch (FilePermissionsException xx) {
        assert true;
    }
    // so make a new entry and then have retrieving it fail.
    storeDirectory.setWritable(true);
    indexDirectory.setWritable(true);
    ClientApproval ca = (ClientApproval) x.create();
    // fail for store directory un readable
    storeDirectory.setReadable(false);
    try {
        x.get(ca.getIdentifier());
        assert false;
    } catch (FilePermissionsException xx) {
        assert true;
    }
}
Also used : MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) DSFSClientApprovalStore(edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStore) FSClientApprovalStore(edu.uiuc.ncsa.security.delegation.server.storage.impl.FSClientApprovalStore) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) FilePermissionsException(edu.uiuc.ncsa.security.core.exceptions.FilePermissionsException) DSFSClientApprovalStore(edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStore) ClientApproverConverter(edu.uiuc.ncsa.myproxy.oa4mp.server.util.ClientApproverConverter) ClientApprovalProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.ClientApprovalProvider) File(java.io.File)

Aggregations

ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)26 Client (edu.uiuc.ncsa.security.delegation.storage.Client)6 Date (java.util.Date)5 ClientApprovalProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.ClientApprovalProvider)3 ClientApproverConverter (edu.uiuc.ncsa.myproxy.oa4mp.server.util.ClientApproverConverter)3 Identifier (edu.uiuc.ncsa.security.core.Identifier)3 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)3 BaseClient (edu.uiuc.ncsa.security.delegation.storage.BaseClient)3 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)3 LinkedList (java.util.LinkedList)3 TypeClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient)2 DSFSClientApprovalStore (edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStore)2 FilePermissionsException (edu.uiuc.ncsa.security.core.exceptions.FilePermissionsException)2 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)2 MyConfigurationException (edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException)2 ClientApprovalStore (edu.uiuc.ncsa.security.delegation.server.storage.ClientApprovalStore)2 FSClientApprovalStore (edu.uiuc.ncsa.security.delegation.server.storage.impl.FSClientApprovalStore)2 OA2ClientApprovalKeys (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientApprovalKeys)2 File (java.io.File)2 Set (java.util.Set)2