Skip to content

Allow PemContent.of to work with untrimmed content #41540

@yingzhuo

Description

@yingzhuo

Hello.
I am currently using Spring Boot 3.3.1, I noticed the utility org.springframework.boot.ssl.pem.PemContent is very useful.

how about add a PropertyEditor to the package? here is my code:

package org.springframework.boot.ssl.pem;

import org.springframework.boot.ssl.pem.PemContent;
import org.springframework.util.StringUtils;

import java.beans.PropertyEditorSupport;
import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @author Ying Zhuo
 */
public class PemContentEditor extends PropertyEditorSupport {

    /**
     * {@inheritDoc}
     */
    @Override
    public final void setAsText(String text) throws IllegalArgumentException {
        try {
            super.setValue(PemContent.of(trimContent(text)));
        } catch (Exception e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    }

    private String trimContent(String text) {
        return Arrays.stream(StringUtils.delimitedListToStringArray(text, "\n"))
                .map(String::trim)
                .collect(Collectors.joining("\n"));
    }
}

so i can config my bean like this:

<bean id="jwtSigner" class="com.mycompany.myproject.jwt.signer.AsymmetricSignerFactoryBean">
    <property name="certificateContent">
        <value>
            <![CDATA[
            -----BEGIN CERTIFICATE-----
            x509 format content here
            -----END CERTIFICATE-----
            ]]>
        </value>
    </property>
    <property name="keyContent">
        <value>
            <![CDATA[
            -----BEGIN PRIVATE KEY-----
            PKCS#8 format content here
            -----END PRIVATE KEY-----
            ]]>
        </value>
    </property>
    <property name="keyPassword">
        <null/>
    </property>
</bean>

@scottfrederick your code of SSL is very cool, thanks.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions