Search in sources :

Example 11 with Identifier

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

the class PermissionServerTest method testGetAdmins.

public void testGetAdmins(CMTestStoreProvider tp2) throws Exception {
    int clientCount = 4;
    CC cc = setupClients(tp2);
    List<AdminClient> admins = new LinkedList<>();
    for (int i = 0; i < clientCount; i++) {
        AdminClient ac2 = getAdminClient(tp2.getAdminClientStore());
        Permission p = tp2.getPermissionStore().create();
        p.setDelete(true);
        p.setRead(true);
        p.setApprove(true);
        p.setCreate(true);
        p.setWrite(true);
        p.setAdminID(ac2.getIdentifier());
        p.setClientID(cc.client.getIdentifier());
        tp2.getPermissionStore().save(p);
        admins.add(ac2);
    }
    admins.add(cc.adminClient);
    // need this list of identifiers later for checking that the returned result is correct.
    List<Identifier> adminIDs = new LinkedList<>();
    for (AdminClient ac : admins) {
        adminIDs.add(ac.getIdentifier());
    }
    PermissionServer permissionServer = new PermissionServer(tp2.getCOSE());
    // ListAdminsRequest req = new ListAdminsRequest(cc.adminClient, cc.client);
    ListAdminsRequest req = (ListAdminsRequest) RequestFactory.createRequest(null, new TypePermission(), new ActionList(), cc.client, null);
    ListAdminsResponse resp = (ListAdminsResponse) permissionServer.process(req);
    // so add a bunch of admins for a single client and check that they all come back.
    List<AdminClient> returnedACs = resp.getAdmins();
    assert returnedACs.size() == admins.size();
    for (AdminClient x : returnedACs) {
        assert adminIDs.contains(x.getIdentifier());
    }
}
Also used : LinkedList(java.util.LinkedList) Identifier(edu.uiuc.ncsa.security.core.Identifier) TypePermission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission) TypePermission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission) Permission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.permissions.Permission) ActionList(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionList) AdminClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)

Example 12 with Identifier

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

the class OA2CertServlet method getClient.

/**
 * This looks for the information about the client and checks the secret.
 *
 * @param req
 * @return
 */
@Override
public Client getClient(HttpServletRequest req) {
    String rawID = req.getParameter(CONST(CONSUMER_KEY));
    String rawSecret = getFirstParameterValue(req, CLIENT_SECRET);
    // According to the spec. this must be in a Basic Authz header if it is not sent as parameter
    List<String> basicTokens = HeaderUtils.getAuthHeader(req, "Basic");
    if (2 < basicTokens.size()) {
        // too many tokens to unscramble
        throw new OA2GeneralError(OA2Errors.INVALID_TOKEN, "Error: Too many authorization tokens.", HttpStatus.SC_UNAUTHORIZED);
    // throw new GeneralException("Too many authorization tokens");
    }
    if (rawID == null) {
        for (String x : basicTokens) {
            try {
                // Here is some detective work. We get up to TWO basic Authz headers with the id and secret.
                // Since ids are valid URIs the idea here is anything that is uri must be an id and the other
                // one is the secret. This also handles the case that one of these is sent as a parameter
                // in the call and the other is in the header.
                URI test = URI.create(x);
                // be the secret.
                if (test.getScheme() != null) {
                    rawID = x;
                } else {
                    rawSecret = x;
                }
            } catch (Throwable t) {
                if (rawSecret == null) {
                    rawSecret = x;
                }
            }
        }
    }
    if (rawID == null) {
        throw new UnknownClientException("No client id");
    }
    Identifier id = BasicIdentifier.newID(rawID);
    OA2Client client = (OA2Client) getClient(id);
    if (client.isPublicClient()) {
        throw new GeneralException("Error: public clients not supported for this operation.");
    }
    if (rawSecret == null) {
        throw new GeneralException("Error: No secret. request refused.");
    }
    if (!client.getSecret().equals(DigestUtils.shaHex(rawSecret))) {
        throw new GeneralException("Error: Secret is incorrect. request refused.");
    }
    return client;
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) UnknownClientException(edu.uiuc.ncsa.security.core.exceptions.UnknownClientException) OA2GeneralError(edu.uiuc.ncsa.security.oauth_2_0.OA2GeneralError) URI(java.net.URI)

Example 13 with Identifier

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

the class MyProxyDelegationServlet method getClient.

public Client getClient(Identifier identifier) {
    if (identifier == null) {
        throw new UnknownClientException("no client id");
    }
    Client c = getServiceEnvironment().getClientStore().get(identifier);
    if (c == null) {
        DebugUtil.dbg(this, "client name is " + getServiceEnvironment().getClientStore().getClass().getSimpleName());
        DebugUtil.dbg(this, "client store is a " + getServiceEnvironment().getClientStore());
        if (getServiceEnvironment().getClientStore().size() == 0) {
            System.err.println("NO ENTRIES IN CLIENT STORE");
        } else {
            System.err.println("Store contains " + getServiceEnvironment().getClientStore().size() + " entries.");
        }
        System.err.println("printing identifiers...");
        for (Identifier x : getServiceEnvironment().getClientStore().keySet()) {
            System.err.println(x);
        }
        System.err.println("done!");
        String ww = "The client with identifier \"" + identifier.toString() + "\"  cannot be found.";
        warn(ww + " Client store is " + getServiceEnvironment().getClientStore());
        throw new UnknownClientException(ww + "  Is the value in the client config correct?", identifier);
    }
    checkClientApproval(c);
    return c;
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) UnknownClientException(edu.uiuc.ncsa.security.core.exceptions.UnknownClientException) Client(edu.uiuc.ncsa.security.delegation.storage.Client)

Example 14 with Identifier

use of edu.uiuc.ncsa.security.core.Identifier 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 15 with Identifier

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

the class OA2ATServlet method populateClaims.

protected Map<String, String> populateClaims(HttpServletRequest request, Map<String, String> p, OA2ServiceTransaction st) {
    OA2SE oa2se = (OA2SE) getServiceEnvironment();
    String issuer = null;
    // So in order
    // 1. get the issuer from the admin client
    List<Identifier> admins = oa2se.getPermissionStore().getAdmins(st.getClient().getIdentifier());
    for (Identifier adminID : admins) {
        AdminClient ac = oa2se.getAdminClientStore().get(adminID);
        if (ac != null) {
            if (ac.getIssuer() != null) {
                issuer = ac.getIssuer();
                break;
            }
        }
    }
    // 2. If the admin client does not have an issuer set, see if the client has one
    if (issuer == null) {
        issuer = ((OA2Client) st.getClient()).getIssuer();
    }
    // The discovery servlet will try to use the server default or construct the issuer
    if (issuer == null) {
        issuer = OA2DiscoveryServlet.getIssuer(request);
    }
    p.put(OA2Claims.ISSUER, issuer);
    p.put(OA2Claims.SUBJECT, st.getUsername());
    if (st.hasAuthTime()) {
        // convert the date to a time if needed.
        p.put(OA2Constants.AUTHORIZATION_TIME, Long.toString(st.getAuthTime().getTime() / 1000));
    }
    return p;
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) OA2SE(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2SE) AdminClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)

Aggregations

Identifier (edu.uiuc.ncsa.security.core.Identifier)33 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)18 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)5 Client (edu.uiuc.ncsa.security.delegation.storage.Client)5 Asset (edu.uiuc.ncsa.myproxy.oa4mp.client.Asset)4 AdminClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)4 Permission (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.permissions.Permission)4 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)4 URI (java.net.URI)4 SQLException (java.sql.SQLException)4 LinkedList (java.util.LinkedList)4 OA4MPResponse (edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse)3 TypePermission (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission)3 ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)3 PrivateKey (java.security.PrivateKey)3 Date (java.util.Date)3 ActionList (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionList)2 ValidTimestampPolicy (edu.uiuc.ncsa.security.core.cache.ValidTimestampPolicy)2 UnknownClientException (edu.uiuc.ncsa.security.core.exceptions.UnknownClientException)2 MyLoggingFacade (edu.uiuc.ncsa.security.core.util.MyLoggingFacade)2