Search in sources :

Example 26 with GeneralException

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

the class OA4MPServletInitializer method init.

@Override
public void init() throws ServletException {
    if (isInitRun)
        return;
    isInitRun = true;
    MyProxyDelegationServlet mps = (MyProxyDelegationServlet) getServlet();
    try {
        // mps.storeUpdates();
        mps.processStoreCheck(mps.getTransactionStore());
        mps.processStoreCheck(mps.getServiceEnvironment().getClientStore());
        mps.processStoreCheck(mps.getServiceEnvironment().getClientApprovalStore());
    } catch (IOException | SQLException e) {
        e.printStackTrace();
        throw new ServletException("Could not update table", e);
    }
    Cleanup transactionCleanup = MyProxyDelegationServlet.transactionCleanup;
    ServiceEnvironmentImpl env = (ServiceEnvironmentImpl) getEnvironment();
    MyLoggingFacade logger = env.getMyLogger();
    logger.info("Cleaning up incomplete client registrations");
    if (transactionCleanup == null) {
        transactionCleanup = new Cleanup<>(logger);
        // set it in the servlet
        MyProxyDelegationServlet.transactionCleanup = transactionCleanup;
        transactionCleanup.setStopThread(false);
        transactionCleanup.setMap(env.getTransactionStore());
        transactionCleanup.addRetentionPolicy(new ValidTimestampPolicy());
        transactionCleanup.start();
        logger.info("Starting transaction store cleanup thread");
    }
    Cleanup<Identifier, CachedObject> myproxyConnectionCleanup = MyProxyDelegationServlet.myproxyConnectionCleanup;
    if (myproxyConnectionCleanup == null) {
        myproxyConnectionCleanup = new Cleanup<Identifier, CachedObject>(logger) {

            @Override
            public List<CachedObject> age() {
                List<CachedObject> x = super.age();
                // is just trying to clean up afterwards.
                for (CachedObject co : x) {
                    Object mp = co.getValue();
                    if (mp instanceof MyProxyConnectable) {
                        try {
                            ((MyProxyConnectable) mp).close();
                        } catch (Throwable t) {
                        // don't care if it fails, get rid of it.
                        }
                    }
                }
                return x;
            }
        };
        // set it in the servlet
        MyProxyDelegationServlet.myproxyConnectionCleanup = myproxyConnectionCleanup;
        myproxyConnectionCleanup.setStopThread(false);
        Cache myproxyConnectionCache = MyProxyDelegationServlet.myproxyConnectionCache;
        if (myproxyConnectionCache == null) {
            myproxyConnectionCache = new Cache();
            // set it in the servlet
            MyProxyDelegationServlet.myproxyConnectionCache = myproxyConnectionCache;
        }
        myproxyConnectionCleanup.setMap(myproxyConnectionCache);
        myproxyConnectionCleanup.addRetentionPolicy(new ConnectionCacheRetentionPolicy(myproxyConnectionCache, env.getTransactionStore()));
        myproxyConnectionCleanup.start();
        logger.info("Starting myproxy connection cache cleanup thread");
    }
    AbstractCLIApprover.ClientApprovalThread caThread = MyProxyDelegationServlet.caThread;
    if (caThread != null && !caThread.isAlive()) {
        caThread.setStopThread(false);
        caThread.start();
    }
    KeyPairPopulationThread kpt = MyProxyDelegationServlet.kpt;
    if (kpt != null && !kpt.isAlive()) {
        kpt.setStopThread(false);
        kpt.start();
    }
    try {
        setupNotifiers();
    } catch (IOException e) {
        throw new GeneralException("Error: could not set up notifiers ", e);
    }
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) CachedObject(edu.uiuc.ncsa.security.core.cache.CachedObject) SQLException(java.sql.SQLException) ServiceEnvironmentImpl(edu.uiuc.ncsa.myproxy.oa4mp.server.ServiceEnvironmentImpl) ConnectionCacheRetentionPolicy(edu.uiuc.ncsa.myproxy.oa4mp.server.util.ConnectionCacheRetentionPolicy) IOException(java.io.IOException) Cleanup(edu.uiuc.ncsa.security.core.cache.Cleanup) KeyPairPopulationThread(edu.uiuc.ncsa.security.util.pkcs.KeyPairPopulationThread) ServletException(javax.servlet.ServletException) MyLoggingFacade(edu.uiuc.ncsa.security.core.util.MyLoggingFacade) MyProxyConnectable(edu.uiuc.ncsa.myproxy.MyProxyConnectable) Identifier(edu.uiuc.ncsa.security.core.Identifier) AbstractCLIApprover(edu.uiuc.ncsa.myproxy.oa4mp.server.util.AbstractCLIApprover) List(java.util.List) CachedObject(edu.uiuc.ncsa.security.core.cache.CachedObject) ValidTimestampPolicy(edu.uiuc.ncsa.security.core.cache.ValidTimestampPolicy) Cache(edu.uiuc.ncsa.security.core.cache.Cache)

Example 27 with GeneralException

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

the class RequestFactory method convertToRequest.

public static AbstractDDRequest convertToRequest(JSONObject json) {
    AbstractDDRequest req = null;
    BaseClient client = SATFactory.getSubject(json);
    Action action = SATFactory.getMethod(json);
    if (action instanceof MissingAction) {
        throw new GeneralException("Error: no valid method found");
    }
    Type type = SATFactory.getType(json);
    BaseClient target = SATFactory.getTarget(json);
    switch(SATFactory.getSubjectValue(json)) {
        case SUBJECT_ADMIN_VALUE:
        // return createSubjectAdminRequest(json);
        case SUBJECT_CLIENT_VALUE:
            break;
        case SUBJECT_UNKNOWN_VALUE:
        default:
            throw new GeneralException("Unknown subject type");
    }
    return req;
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) BaseClient(edu.uiuc.ncsa.security.delegation.storage.BaseClient)

Example 28 with GeneralException

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

the class RequestFactory method createRequest.

/* ***** Attribute requests */
public static AttributeGetRequest createRequest(AdminClient aSubj, TypeAttribute typeAttribute, ActionGet actionGet, OA2Client cTarget, JSON content) {
    // JSON content = SATFactory.getContent(json);
    if (!content.isArray()) {
        throw new GeneralException("Content must be a list of attributes to get");
    }
    JSONArray array = (JSONArray) content;
    String[] arrayString = (String[]) array.toArray(new String[array.size()]);
    return new AttributeGetRequest(aSubj, cTarget, Arrays.asList(arrayString));
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) JSONArray(net.sf.json.JSONArray) AttributeGetRequest(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.attributes.AttributeGetRequest)

Example 29 with GeneralException

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

the class RequestFactory method createRequest.

public static AttributeRemoveRequest createRequest(AdminClient aSubj, TypeAttribute typeAttribute, ActionRemove actionRemove, OA2Client cTarget, JSON content) {
    // JSON content = SATFactory.getContent(json);
    if (!content.isArray()) {
        throw new GeneralException("Content must be a list of attributes to get");
    }
    JSONArray array = (JSONArray) content;
    String[] arrayString = (String[]) array.toArray(new String[array.size()]);
    return new AttributeRemoveRequest(aSubj, cTarget, Arrays.asList(arrayString));
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) AttributeRemoveRequest(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.attributes.AttributeRemoveRequest) JSONArray(net.sf.json.JSONArray)

Example 30 with GeneralException

use of edu.uiuc.ncsa.security.core.exceptions.GeneralException 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)

Aggregations

GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)53 ServiceTransaction (edu.uiuc.ncsa.security.delegation.server.ServiceTransaction)9 SQLException (java.sql.SQLException)8 Connection (java.sql.Connection)7 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 Identifier (edu.uiuc.ncsa.security.core.Identifier)5 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)5 MyPKCS10CertRequest (edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)5 X509Certificate (java.security.cert.X509Certificate)5 AssetResponse (edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse)4 TransactionState (edu.uiuc.ncsa.security.delegation.servlet.TransactionState)4 AccessToken (edu.uiuc.ncsa.security.delegation.token.AccessToken)4 AuthorizationGrant (edu.uiuc.ncsa.security.delegation.token.AuthorizationGrant)4 OA2SE (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2SE)3 OA2ServiceTransaction (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2ServiceTransaction)3 ColumnMap (edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap)3 File (java.io.File)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3