Search in sources :

Example 6 with MyConfigurationException

use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.

the class NewCAStoreTest 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)

Example 7 with MyConfigurationException

use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.

the class ClientLoader method checkPrivateKey.

protected PrivateKey checkPrivateKey() throws IOException {
    String privateKeyFileName = getCfgValue(ClientXMLTags.PRIVATE_KEY);
    if (trivial(privateKeyFileName)) {
        throw new MyConfigurationException("Error: There is no private key specified.");
    }
    File privateKeyFile = new File(privateKeyFileName);
    if (!privateKeyFile.exists()) {
        throw new MyConfigurationException("Error: The specified private key file \"" + privateKeyFileName + "\" does not exist");
    }
    if (!privateKeyFile.isFile()) {
        throw new MyConfigurationException("Error: The specified private key file \"" + privateKeyFileName + "\" is not actually a file");
    }
    if (!privateKeyFile.canRead()) {
        throw new MyConfigurationException("Error: The specified private key file \"" + privateKeyFileName + "\" is not readable. Check the permissions.");
    }
    return KeyUtil.fromPKCS8PEM(new FileReader(privateKeyFile));
}
Also used : MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) FileReader(java.io.FileReader) File(java.io.File)

Example 8 with MyConfigurationException

use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.

the class ClientLoader method createInstance.

/**
 * Factory method. Override this to create the actual instance as needed.
 *
 * @param tokenForgeProvider
 * @param clientProvider
 * @param constants
 * @return
 */
public T createInstance(Provider<TokenForge> tokenForgeProvider, Provider<Client> clientProvider, HashMap<String, String> constants) {
    ClientEnvironment ce = null;
    try {
        ce = new ClientEnvironment(myLogger, constants, getAccessTokenURI(), getAuthorizeURI(), getCallback(), getInitiateURI(), getAssetURI(), checkCertLifetime(), getId(), checkPrivateKey(), checkPublicKey(), getSkin(), isEnableAssetCleanup(), getMaxAssetLifetime(), getKeypairLifetime(), getAssetProvider(), clientProvider, tokenForgeProvider, getDSP(), getAssetStoreProvider(), isShowRedirectPage(), getErrorPagePath(), getRedirectPagePath(), getSuccessPagePath());
    } catch (IOException e) {
        throw new MyConfigurationException("Error; Could not configure environment", e);
    }
    init();
    return (T) ce;
}
Also used : MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) IOException(java.io.IOException) ClientEnvironment(edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment)

Aggregations

MyConfigurationException (edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException)8 File (java.io.File)5 ClientApprovalProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.ClientApprovalProvider)2 DSFSClientApprovalStore (edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStore)2 ClientApproverConverter (edu.uiuc.ncsa.myproxy.oa4mp.server.util.ClientApproverConverter)2 FilePermissionsException (edu.uiuc.ncsa.security.core.exceptions.FilePermissionsException)2 ConfigurationLoader (edu.uiuc.ncsa.security.core.util.ConfigurationLoader)2 ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)2 FSClientApprovalStore (edu.uiuc.ncsa.security.delegation.server.storage.impl.FSClientApprovalStore)2 FileReader (java.io.FileReader)2 ConfigurationNode (org.apache.commons.configuration.tree.ConfigurationNode)2 ClientEnvironment (edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment)1 OA4MPConfigurationLoader (edu.uiuc.ncsa.myproxy.oa4mp.loader.OA4MPConfigurationLoader)1 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)1 MyLoggingFacade (edu.uiuc.ncsa.security.core.util.MyLoggingFacade)1 IOException (java.io.IOException)1 URL (java.net.URL)1 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)1