简体   繁体   中英

Jaxb: Passing parameter to @XmlJavaTypeAdapter

I am creating soap webservice using: Spring Boot / JAX-WS (CXF) I want to encrypt one field. I am using XmlJavaTypeAdapter for this. For example:

   @XmlJavaTypeAdapter(CypherStringAdapter.class)
   private String cryptedField;

The CypherStringAdapter class:

package fr.hop.meta4;

import java.io.UnsupportedEncodingException;    
import javax.xml.bind.annotation.adapters.XmlAdapter;    
import org.springframework.beans.factory.annotation.Value;    
import fr.hop.aes.AESEncryptor;

public class CypherStringAdapter extends XmlAdapter<String, String> {

    @Value("${cypher.key}") 
    private String key;

    private AESEncryptor cypher;

    public CypherStringAdapter() throws UnsupportedEncodingException {    
        cypher = new AESEncryptor(key);        
    }

    @Override
    public String marshal(String v) throws Exception {

        if (v != null)
            return cypher.encrypt(v);

        return null; 
    }

    @Override
    public String unmarshal(String v) throws Exception {
        if (v != null)
              return cypher.decrypt(v);

        return null;        
    }
}

I want to externalize the key value. I am try with @value annotation but it's not working (always null value). How i could achieve to send key to XmlJavaTypeAdapter ?

Regards

I think XmlJavaTypeAdapter is not a good place for encryption. I change my code to put encryption in my object creation, it make more sense, more easy to implement and it works.

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM