use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class AssetConverter method fromMap.
@Override
public Asset fromMap(ConversionMap<String, Object> map, Asset asset) {
super.fromMap(map, asset);
asset.setUsername(map.getString(getAR().username()));
try {
String rawCert = map.getString(getAR().certificates());
if (rawCert != null && 0 < rawCert.length()) {
asset.setCertificates(CertUtil.fromX509PEM(rawCert));
}
} catch (CertificateException e) {
throw new GeneralException("Error: could not create certificate", e);
}
String temp = map.getString(getAR().privateKey());
if (temp != null) {
asset.setPrivateKey(KeyUtil.fromPKCS8PEM(temp));
}
asset.setRedirect(map.getURI(getAR().redirect()));
asset.setCreationTime(map.getDate(getAR().creationTime()));
asset.setToken(map.getIdentifier(getAR().token()));
String rawCertReq = map.getString(getAR().certReq());
if (rawCertReq != null) {
asset.setCertReq(CertUtil.fromStringToCertReq(rawCertReq));
}
return asset;
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class SQLAssetStore method getByToken.
@Override
public Asset getByToken(Identifier token) {
if (token == null) {
return null;
}
Connection c = getConnection();
Asset t = null;
try {
PreparedStatement stmt = c.prepareStatement(getAST().getByTokenStatement());
stmt.setString(1, token.toString());
stmt.executeQuery();
ResultSet rs = stmt.getResultSet();
// Now we have to pull in all the values.
if (!rs.next()) {
rs.close();
stmt.close();
// returning a null fulfills contract for this being a map.
return null;
}
ColumnMap map = rsToMap(rs);
rs.close();
stmt.close();
t = create();
populate(map, t);
} catch (SQLException e) {
destroyConnection(c);
throw new GeneralException("Error getting object with identifier \"" + token + "\"", e);
} finally {
releaseConnection(c);
}
return t;
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project airavata by apache.
the class CredentialStoreCallbackServlet method doIt.
@Override
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
String gatewayName = request.getParameter(CredentialStoreConstants.GATEWAY_NAME_QUERY_PARAMETER);
String portalUserName = request.getParameter(CredentialStoreConstants.PORTAL_USER_QUERY_PARAMETER);
String durationParameter = request.getParameter(CredentialStoreConstants.DURATION_QUERY_PARAMETER);
String contactEmail = request.getParameter(CredentialStoreConstants.PORTAL_USER_EMAIL_QUERY_PARAMETER);
String portalTokenId = request.getParameter(CredentialStoreConstants.PORTAL_TOKEN_ID_ASSIGNED);
// TODO remove hard coded values, once passing query parameters is
// fixed in OA4MP client api
long duration = 864000;
if (durationParameter != null) {
duration = Long.parseLong(durationParameter);
}
if (portalTokenId == null) {
error("Token given by portal is invalid.");
GeneralException ge = new GeneralException("Error: The token presented by portal is null.");
request.setAttribute("exception", ge);
JSPUtil.fwd(request, response, configurationReader.getErrorUrl());
return;
}
info("Gateway name " + gatewayName);
info("Portal user name " + portalUserName);
info("Community user contact email " + contactEmail);
info("Token id presented " + portalTokenId);
info("2.a. Getting token and verifier.");
String token = request.getParameter(CONST(ClientEnvironment.TOKEN));
String verifier = request.getParameter(CONST(ClientEnvironment.VERIFIER));
if (token == null || verifier == null) {
warn("2.a. The token is " + (token == null ? "null" : token) + " and the verifier is " + (verifier == null ? "null" : verifier));
GeneralException ge = new GeneralException("Error: This servlet requires parameters for the token and verifier. It cannot be called directly.");
request.setAttribute("exception", ge);
JSPUtil.fwd(request, response, configurationReader.getErrorUrl());
return;
}
info("2.a Token and verifier found.");
X509Certificate[] certificates;
AssetResponse assetResponse = null;
PrivateKey privateKey;
try {
PrivateKeyStore privateKeyStore = PrivateKeyStore.getPrivateKeyStore();
privateKey = privateKeyStore.getKey(portalTokenId);
if (privateKey != null) {
info("Found private key for token " + portalTokenId);
} else {
info("Could not find private key for token " + portalTokenId);
}
info("2.a. Getting the cert(s) from the service");
assetResponse = getOA4MPService().getCert(token, verifier);
certificates = assetResponse.getX509Certificates();
} catch (Throwable t) {
warn("2.a. Exception from the server: " + t.getCause().getMessage());
error("Exception while trying to get cert. message:" + t.getMessage());
request.setAttribute("exception", t);
JSPUtil.fwd(request, response, configurationReader.getErrorUrl());
return;
}
info("2.b. Done! Displaying success page.");
CertificateCredential certificateCredential = new CertificateCredential();
// TODO check this is correct
certificateCredential.setNotBefore(Utility.convertDateToString(certificates[0].getNotBefore()));
certificateCredential.setNotAfter(Utility.convertDateToString(certificates[0].getNotAfter()));
certificateCredential.setCertificates(certificates);
certificateCredential.setPrivateKey(privateKey);
certificateCredential.setCommunityUser(new CommunityUser(gatewayName, assetResponse.getUsername(), contactEmail));
certificateCredential.setPortalUserName(portalUserName);
certificateCredential.setLifeTime(duration);
certificateCredential.setToken(portalTokenId);
certificateCredentialWriter.writeCredentials(certificateCredential);
StringBuilder stringBuilder = new StringBuilder("Certificate for community user ");
stringBuilder.append(assetResponse.getUsername()).append(" successfully persisted.");
stringBuilder.append(" Certificate DN - ").append(certificates[0].getSubjectDN());
info(stringBuilder.toString());
if (isUrlInSameServer(configurationReader.getSuccessUrl())) {
String contextPath = request.getContextPath();
if (!contextPath.endsWith("/")) {
contextPath = contextPath + "/";
}
request.setAttribute("action", contextPath);
request.setAttribute("tokenId", portalTokenId);
JSPUtil.fwd(request, response, configurationReader.getSuccessUrl());
} else {
String urlToRedirect = decorateUrlWithToken(configurationReader.getSuccessUrl(), portalTokenId);
info("Redirecting to url - " + urlToRedirect);
response.sendRedirect(urlToRedirect);
}
info("2.a. Completely finished with delegation.");
}
Aggregations