use of edu.uiuc.ncsa.security.core.exceptions.GeneralException 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;
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException 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;
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class OA2MPService method getCert.
public AssetResponse getCert(OA2Asset a, ATResponse2 atResponse2) {
KeyPair keyPair = getNextKeyPair();
MyPKCS10CertRequest certReq = null;
try {
certReq = CertUtil.createCertRequest(keyPair, a.getUsername());
} catch (Throwable e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new GeneralException("Could no create cert request", e);
}
a.setPrivateKey(keyPair.getPrivate());
a.setCertReq(certReq);
Map<String, String> m1 = getAssetParameters(a);
preGetCert(a, m1);
if (MANUAL_TEST) {
return manualTest(a, m1);
}
DelegatedAssetResponse daResp = getEnvironment().getDelegationService().getCert(atResponse2, getEnvironment().getClient(), m1);
AssetResponse par = new AssetResponse();
MyX509Certificates myX509Certificate = (MyX509Certificates) daResp.getProtectedAsset();
par.setX509Certificates(myX509Certificate.getX509Certificates());
postGetCert(a, par);
a.setCertificates(par.getX509Certificates());
getEnvironment().getAssetStore().save(a);
return par;
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class OA2ClientExceptionHandler method parseContent.
/**
* This will parse the standard error reponse from an OIDC server.
*
* @param content
* @param request
* @return
*/
protected void parseContent(String content, HttpServletRequest request) {
// This will take the payload and parse it as follows. The assumption is that it is of the form
// X0=Y0
// X1=Y1
// X2=Y2
// etc. where X's are standard OIDB error indicators (e.g. error_description, state) and Y's are the value
// These are set in the response as attributes, so there is no limit on them.
boolean hasValidContent = false;
StringTokenizer st = new StringTokenizer(content, "\n");
while (st.hasMoreElements()) {
String currentLine = st.nextToken();
StringTokenizer clST = new StringTokenizer(currentLine, "=");
if (!clST.hasMoreTokens() || clST.countTokens() != 2) {
continue;
}
try {
request.setAttribute(clST.nextToken(), URLDecoder.decode(clST.nextToken(), "UTF-8"));
} catch (UnsupportedEncodingException xx) {
// ok, try it without decoding it. (This case should never really happen)
request.setAttribute(clST.nextToken(), clST.nextToken());
}
hasValidContent = true;
}
if (!hasValidContent) {
getLogger().warn("Body or error was not parseable");
throw new GeneralException();
}
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class OA4MPService method preRequestCert.
@Override
public void preRequestCert(Asset asset, Map additionalParameters) {
KeyPair keyPair = getNextKeyPair();
MyPKCS10CertRequest certReq = null;
try {
certReq = CertUtil.createCertRequest(keyPair);
} catch (Throwable e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new GeneralException("Could not create cert request", e);
}
asset.setPrivateKey(keyPair.getPrivate());
asset.setCertReq(certReq);
additionalParameters.put(ClientEnvironment.CERT_REQUEST_KEY, Base64.encodeBase64String(asset.getCertReq().getEncoded()));
// additionalParameters.put(ClientEnvironment.CERT_REQUEST_KEY, "Mairzy doates and does eat stoats.");
if (!additionalParameters.containsKey(getEnvironment().getConstants().get(CALLBACK_URI_KEY))) {
additionalParameters.put(getEnvironment().getConstants().get(CALLBACK_URI_KEY), getEnvironment().getCallback().toString());
}
if (0 <= getEnvironment().getCertLifetime()) {
additionalParameters.put(ClientEnvironment.CERT_LIFETIME_KEY, getEnvironment().getCertLifetime());
}
}
Aggregations