Search in sources :

Example 16 with EncodeAction

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));
    }
}
Also used : XMLException(com.iplanet.services.util.XMLException) EncodeAction(com.sun.identity.security.EncodeAction) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList)

Example 17 with EncodeAction

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;
}
Also used : EncodeAction(com.sun.identity.security.EncodeAction) FileNotFoundException(java.io.FileNotFoundException) UMSObject(com.iplanet.ums.UMSObject) PersistentObject(com.iplanet.ums.PersistentObject) IOException(java.io.IOException)

Example 18 with EncodeAction

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;
}
Also used : EncodeAction(com.sun.identity.security.EncodeAction) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 19 with EncodeAction

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);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) EncodeAction(com.sun.identity.security.EncodeAction) Iterator(java.util.Iterator) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 20 with EncodeAction

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
            }
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) EncodeAction(com.sun.identity.security.EncodeAction) FileOutputStream(java.io.FileOutputStream) CLIException(com.sun.identity.cli.CLIException) IOException(java.io.IOException)

Aggregations

EncodeAction (com.sun.identity.security.EncodeAction)23 Iterator (java.util.Iterator)8 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 HashMap (java.util.HashMap)3 NodeList (org.w3c.dom.NodeList)3 DecodeAction (com.sun.identity.security.DecodeAction)2 BufferedReader (java.io.BufferedReader)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStreamReader (java.io.InputStreamReader)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Map (java.util.Map)2 Cookie (javax.servlet.http.Cookie)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Test (org.testng.annotations.Test)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 SessionException (com.iplanet.dpro.session.SessionException)1 View (com.iplanet.jato.view.View)1