use of java.io.UnsupportedEncodingException in project OpenAM by OpenRock.
the class SoapSTSInstanceModule method getEncryptionProperties.
private Properties getEncryptionProperties() {
Properties properties = new Properties();
properties.put("org.apache.ws.security.crypto.provider", "org.apache.ws.security.components.crypto.Merlin");
String keystorePassword;
if (stsInstanceConfig.getKeystoreConfig() != null) {
try {
keystorePassword = new String(stsInstanceConfig.getKeystoreConfig().getKeystorePassword(), AMSTSConstants.UTF_8_CHARSET_ID);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unsupported string encoding for keystore password: " + e);
}
properties.put("org.apache.ws.security.crypto.merlin.keystore.password", keystorePassword);
properties.put("org.apache.ws.security.crypto.merlin.keystore.file", stsInstanceConfig.getKeystoreConfig().getKeystoreFileName());
properties.put("org.apache.ws.security.crypto.merlin.keystore.type", "jks");
}
return properties;
}
use of java.io.UnsupportedEncodingException in project OpenAM by OpenRock.
the class JCECrypt method encode.
private static String encode(String clearText, AMEncryption encr) {
if (clearText == null || clearText.length() == 0) {
return null;
}
// Encrypt the data
byte[] encData = null;
try {
encData = encr.encrypt(clearText.getBytes("utf-8"));
} catch (UnsupportedEncodingException uee) {
Debug debug = Debug.getInstance("amSDK");
debug.error("Crypt:: utf-8 encoding is not supported");
encData = encryptor.encrypt(clearText.getBytes());
}
// BASE64 encode the data
String str = null;
// Perf Improvement : Removed the sync block and newed up the Encoder
// object for every call. Its a trade off b/w CPU and mem usage.
str = Base64.encode(encData).trim();
// Serialize the data, i.e., remove \n and \r
BufferedReader bufReader = new BufferedReader(new StringReader(str));
StringBuilder strClean = new StringBuilder(str.length());
String strTemp = null;
try {
while ((strTemp = bufReader.readLine()) != null) {
strClean.append(strTemp);
}
} catch (IOException ioe) {
Debug debug = Debug.getInstance("amSDK");
debug.error("Crypt:: Error while base64 encoding", ioe);
}
return (strClean.toString());
}
use of java.io.UnsupportedEncodingException in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method buildUsernameTokenTransformValidatorParameters.
private RestTokenTransformValidatorParameters<RestUsernameToken> buildUsernameTokenTransformValidatorParameters(JsonValue receivedToken) throws TokenMarshalException {
if (!receivedToken.get(AMSTSConstants.USERNAME_TOKEN_USERNAME).isString()) {
final String message = "Exception: json representation of UNT does not contain a username field. The representation: " + receivedToken;
throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
}
if (!receivedToken.get(AMSTSConstants.USERNAME_TOKEN_PASSWORD).isString()) {
final String message = "Exception: json representation of UNT does not contain a password field. The representation: \n" + receivedToken;
throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
}
final String username = receivedToken.get(AMSTSConstants.USERNAME_TOKEN_USERNAME).asString();
final String password = receivedToken.get(AMSTSConstants.USERNAME_TOKEN_PASSWORD).asString();
try {
final RestUsernameToken restUsernameToken = new RestUsernameToken(username.getBytes(AMSTSConstants.UTF_8_CHARSET_ID), password.getBytes(AMSTSConstants.UTF_8_CHARSET_ID));
return new RestTokenTransformValidatorParameters<RestUsernameToken>() {
@Override
public RestUsernameToken getInputToken() {
return restUsernameToken;
}
};
} catch (UnsupportedEncodingException e) {
throw new TokenMarshalException(ResourceException.INTERNAL_ERROR, "Unable to marshal username token state to strings: " + e.getMessage(), e);
}
}
use of java.io.UnsupportedEncodingException in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method pullClientCertFromHeader.
private X509Certificate[] pullClientCertFromHeader(HttpContext httpContext) throws TokenMarshalException {
List<String> clientCertHeader = httpContext.getHeader(offloadedTlsClientCertKey);
if (clientCertHeader.isEmpty()) {
return null;
} else {
int ndx = 0;
X509Certificate[] certificates = new X509Certificate[clientCertHeader.size()];
final CertificateFactory certificateFactory;
try {
certificateFactory = CertificateFactory.getInstance("X.509");
} catch (CertificateException e) {
throw new TokenMarshalException(ResourceException.INTERNAL_ERROR, "Exception caught creating X.509 CertificateFactory: " + e, e);
}
for (String headerCertValue : clientCertHeader) {
try {
certificates[ndx++] = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(Base64.decode(headerCertValue.getBytes(AMSTSConstants.UTF_8_CHARSET_ID))));
} catch (CertificateException | UnsupportedEncodingException e) {
throw new TokenMarshalException(ResourceException.BAD_REQUEST, "Exception caught marshalling X509 cert from value set in " + offloadedTlsClientCertKey + " header: " + e, e);
}
}
return certificates;
}
}
use of java.io.UnsupportedEncodingException in project OpenAM by OpenRock.
the class ExportServiceConfiguration method handleRequest.
/**
* Handles request.
*
* @param rc Request Context.
* @throws CLIException if request cannot be processed.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
String outputFile = getStringOptionValue(IArgument.OUTPUT_FILE);
String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
FileOutputStream fout = null;
String[] param = { "tty" };
String[] paramException = { "tty", "" };
try {
if ((outputFile != null) && (outputFile.length() > 0)) {
fout = new FileOutputStream(outputFile);
param[0] = outputFile;
paramException[0] = outputFile;
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_EXPORT_SM_CONFIG_DATA", param);
ServiceManager sm = new ServiceManager(adminSSOToken);
AMEncryption encryptObj = new JCEEncryption();
((ConfigurableKey) encryptObj).setPassword(encryptSecret);
String resultXML = sm.toXML(encryptObj);
resultXML += "<!-- " + Hash.hash(encryptSecret) + " -->";
if (fout != null) {
fout.write(resultXML.getBytes("UTF-8"));
} else {
System.out.write(resultXML.getBytes("UTF-8"));
}
getOutputWriter().printlnMessage(getResourceString("export-service-configuration-succeeded"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_SM_CONFIG_DATA", param);
} catch (UnsupportedEncodingException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (Exception e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if (fout != null) {
try {
fout.close();
} catch (IOException ioe) {
//ignored
}
}
}
}
Aggregations