Search in sources :

Example 26 with Identifier

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

the class TransactionConverter method fromMap.

@Override
public V fromMap(ConversionMap<String, Object> map, V v) {
    V t = super.fromMap(map, v);
    String CertReqString = map.getString(getDSTK().certReq());
    if (CertReqString != null && 0 < CertReqString.length())
        t.setCertReq(CertUtil.fromStringToCertReq(CertReqString));
    String y = map.getString(getDSTK().cert());
    if (y != null && 0 < y.length()) {
        try {
            ByteArrayInputStream baos = new ByteArrayInputStream(y.getBytes("UTF-8"));
            MyX509Certificates myCert = new MyX509Certificates(fromPEM(baos));
            t.setProtectedAsset(myCert);
        } catch (CertificateException e) {
            throw new GeneralException("Error decoding certificate", e);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    Identifier clientKey = BasicIdentifier.newID(map.getString(getDSTK().clientKey()));
    if (clientKey != null) {
        t.setClient(clientStore.get(clientKey));
    }
    String uName = map.getString(getDSTK().username());
    if (uName != null) {
        t.setUsername(uName);
    }
    String myproxyUsername = map.getString(getDSTK().myproxyUsername());
    if (myproxyUsername != null) {
        t.setMyproxyUsername(myproxyUsername);
    }
    return t;
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CertificateException(java.security.cert.CertificateException) MyX509Certificates(edu.uiuc.ncsa.security.delegation.token.MyX509Certificates)

Example 27 with Identifier

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

the class SQLPermissionStore method getAdmins.

@Override
public List<Identifier> getAdmins(Identifier clientID) {
    ArrayList<Identifier> admins = new ArrayList<>();
    if (clientID == null)
        return admins;
    Connection c = getConnection();
    PermissionKeys permissionKeys = new PermissionKeys();
    try {
        PreparedStatement stmt = c.prepareStatement("select " + permissionKeys.adminID() + "  from " + getTable().getFQTablename() + " where " + permissionKeys.clientID() + "=?");
        stmt.setString(1, clientID.toString());
        // just execute() since executeQuery(x) would throw an exception regardless of content per JDBC spec.
        stmt.execute();
        ResultSet rs = stmt.getResultSet();
        while (rs.next()) {
            String adminID = rs.getString(permissionKeys.adminID());
            admins.add(BasicIdentifier.newID(adminID));
        }
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        destroyConnection(c);
        throw new GeneralException("Error: could not get database object", e);
    } finally {
        releaseConnection(c);
    }
    return admins;
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 28 with Identifier

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

the class OA2StartRequest method doIt.

@Override
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    info("1.a. Starting transaction");
    OA4MPResponse gtwResp = null;
    // Drumroll please: here is the work for this call.
    Identifier id = AssetStoreUtil.createID();
    gtwResp = getOA4MPService().requestCert(id);
    // if there is a store, store something in it.
    Cookie cookie = new Cookie(OA4MP_CLIENT_REQUEST_ID, id.getUri().toString());
    // 15 minutes
    cookie.setMaxAge(15 * 60);
    cookie.setSecure(true);
    debug("id = " + id.getUri());
    response.addCookie(cookie);
    info("1.b. Got response. Creating page with redirect for " + gtwResp.getRedirect().getHost());
    if (getCE().isShowRedirectPage()) {
        request.setAttribute(REDIR, REDIR);
        request.setAttribute("redirectUrl", gtwResp.getRedirect().toString());
        request.setAttribute(ACTION_KEY, ACTION_KEY);
        request.setAttribute("action", ACTION_REDIRECT_VALUE);
        // Normally, we'd just do a redirect, but we will put up a page and show the redirect to the user.
        // The client response contains the generated private key as well
        // In a real application, the private key would be stored. This, however, exceeds the scope of this
        // sample application -- all we need to do to complete the process is send along the redirect url.
        info("1.b. Showing redirect page.");
        JSPUtil.fwd(request, response, getCE().getRedirectPagePath());
        return;
    }
    response.sendRedirect(gtwResp.getRedirect().toString());
}
Also used : Cookie(javax.servlet.http.Cookie) Identifier(edu.uiuc.ncsa.security.core.Identifier) OA4MPResponse(edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse)

Example 29 with Identifier

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

the class AbstractOA4MPService method makeb64Uri.

protected Identifier makeb64Uri(String x) {
    Base64String b64 = new Base64String(x.getBytes());
    Identifier id = BasicIdentifier.newID(BASE64_URI_CAPUT + b64);
    return id;
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) Base64String(edu.uiuc.ncsa.security.util.pkcs.Base64String)

Example 30 with Identifier

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

the class AssetStoreTest method testAsset.

@Test
public void testAsset() throws Exception {
    Identifier id = BasicIdentifier.newID("asset:id:/" + ClientTestStoreUtil.getRandomString());
    Asset asset = new Asset(id);
    PrivateKey privateKey = KeyUtil.generateKeyPair().getPrivate();
    String username = "testUser-" + ClientTestStoreUtil.getRandomString(8);
    URI redirect = URI.create("http://test.foo/test" + ClientTestStoreUtil.getRandomString(8));
    asset.setPrivateKey(privateKey);
    asset.setUsername(username);
    asset.setRedirect(redirect);
    assert asset.getPrivateKey().equals(privateKey);
    assert asset.getUsername().equals(username);
    assert asset.getRedirect().equals(redirect);
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) PrivateKey(java.security.PrivateKey) Asset(edu.uiuc.ncsa.myproxy.oa4mp.client.Asset) URI(java.net.URI) Test(org.junit.Test)

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