use of com.sun.identity.security.EncodeAction in project OpenAM by OpenRock.
the class ServerConfigMgr method setUserPassword.
private void setUserPassword(String userType, String password) throws Exception {
Node pwdNode = XMLUtils.getChildNode(getUserNode(userType), DSConfigMgr.AUTH_PASSWD);
if (pwdNode == null) {
throw (new XMLException(i18n.getString("dscfg-corrupted-serverconfig")));
}
// Encrypt the new password and store
String encPassword = (String) AccessController.doPrivileged(new EncodeAction(password));
NodeList textNodes = pwdNode.getChildNodes();
Node textNode = textNodes.item(0);
textNode.setNodeValue(encPassword);
// Delete the remaining text nodes
for (int i = 1; i < textNodes.getLength(); i++) {
pwdNode.removeChild(textNodes.item(i));
}
}
use of com.sun.identity.security.EncodeAction in project OpenAM by OpenRock.
the class ServerConfigMgr method encryptPassword.
private static boolean encryptPassword(String[] args) {
boolean processed = false;
if (args[0].equals(S_ENCRYPT) || args[0].equals(ENCRYPT)) {
processed = true;
String password = null;
if (args.length > 1) {
try {
password = readOneLinerFromFile(args[1]);
if ((password == null) || (password.length() == 0)) {
Object[] messageArgs = { args[1] };
System.err.println(MessageFormat.format(i18n.getString("dscfg-null-password"), messageArgs));
System.err.println(i18n.getString("dscfg-usage"));
System.exit(1);
}
System.out.println((String) AccessController.doPrivileged(new EncodeAction(password)));
} catch (FileNotFoundException e) {
Object[] messageArgs = { args[1] };
System.err.println(MessageFormat.format(i18n.getString("dscfg-passwd-file-not-found"), messageArgs));
System.exit(1);
} catch (IOException ioe) {
Object[] messageArgs = { args[1] };
System.err.println(MessageFormat.format(i18n.getString("dscfg-passwd-file-not-found"), messageArgs));
System.exit(1);
}
} else {
Object[] messageArgs = { args[0] };
System.err.println(MessageFormat.format(i18n.getString("dscfg-incorrect-usage"), messageArgs));
System.err.println(i18n.getString("dscfg-usage"));
System.exit(1);
}
}
return processed;
}
use of com.sun.identity.security.EncodeAction in project OpenAM by OpenRock.
the class AuthXMLUtils method getSerializedSubject.
/**
* Serialize the subject.
*
* @param subject Subject to be serialized.
* @return serialized subject.
*/
public static String getSerializedSubject(Subject subject) {
byte[] sSerialized = null;
String encodedString = null;
ByteArrayOutputStream byteOut;
ObjectOutputStream objOutStream;
try {
byteOut = new ByteArrayOutputStream();
objOutStream = new ObjectOutputStream(byteOut);
//convert object to byte using streams
objOutStream.writeObject(subject);
sSerialized = byteOut.toByteArray();
// base 64 encoding & encrypt
encodedString = (String) AccessController.doPrivileged(new EncodeAction(Base64.encode(sSerialized).trim()));
if (debug.messageEnabled()) {
debug.message("encoded Subject is : " + encodedString);
}
} catch (Exception e) {
debug.message("Exception : ", e);
}
return encodedString;
}
use of com.sun.identity.security.EncodeAction in project OpenAM by OpenRock.
the class FilesRepo method processAttributes.
static Map processAttributes(Map attrs, Set hashAttrs, Set encAttrs) {
// Convert to CaseInsensitiveHashMap
Map answer = new CaseInsensitiveHashMap();
for (Iterator items = attrs.keySet().iterator(); items.hasNext(); ) {
Object key = items.next();
Set ovalue = (Set) attrs.get(key);
Set nvalue = new CaseInsensitiveHashSet();
if (hashAttrs.contains(key)) {
for (Iterator i = ovalue.iterator(); i.hasNext(); ) {
nvalue.add(Hash.hash((String) i.next()));
}
} else if (encAttrs.contains(key)) {
try {
for (Iterator i = ovalue.iterator(); i.hasNext(); ) {
nvalue.add((String) AccessController.doPrivileged(new EncodeAction((String) i.next())));
}
} catch (Throwable e) {
// Printing the attribute value could be security issue
debug.error("FilesRepo.processAttributes: unable to encode", e);
}
} else {
nvalue.addAll(ovalue);
}
answer.put(key, nvalue);
}
return (answer);
}
use of com.sun.identity.security.EncodeAction in project OpenAM by OpenRock.
the class CreateServerConfigXML 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);
FileOutputStream fout = null;
String[] param = { "tty" };
String[] paramException = { "tty", "" };
dsHost = getStringOptionValue(DS_HOST);
dsPort = getStringOptionValue(DS_PORT);
dsAdmin = getStringOptionValue(DS_ADMIN);
String dsPasswordFile = getStringOptionValue(DS_PWD_FILE);
basedn = getStringOptionValue(DS_BASEDN);
if ((dsHost == null) || (dsHost.length() == 0)) {
dsHost = "ds.opensso.java.net";
}
if ((dsPort == null) || (dsPort.length() == 0)) {
dsPort = "389";
}
if ((dsAdmin == null) || (dsAdmin.length() == 0)) {
dsAdmin = "cn=Directory Manager";
}
if ((dsPasswordFile == null) || (dsPasswordFile.length() == 0)) {
dsPassword = "11111111";
} else {
dsPassword = CLIUtil.getFileContent(getCommandManager(), dsPasswordFile);
}
if ((basedn == null) || (basedn.length() == 0)) {
basedn = DEFAULT_ROOT_SUFFIX;
}
dsPassword = (String) AccessController.doPrivileged(new EncodeAction(dsPassword));
try {
if ((outputFile != null) && (outputFile.length() > 0)) {
fout = new FileOutputStream(outputFile);
param[0] = outputFile;
paramException[0] = outputFile;
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_SERVERCONFIG_XML", param);
String template = getResource("serverconfig.xml");
String modified = modifyXML(template);
if (fout != null) {
fout.write(modified.getBytes());
} else {
getOutputWriter().printlnMessage(modified);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_CREATE_SERVERCONFIG_XML", param);
} catch (IOException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_SERVERCONFIG_XML", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if (fout != null) {
try {
fout.close();
} catch (IOException ioe) {
//ignored
}
}
}
}
Aggregations