Search in sources :

Example 1 with WebAuthn4JSpringSecurityJSONModule

use of com.webauthn4j.springframework.security.converter.jackson.WebAuthn4JSpringSecurityJSONModule in project webauthn4j-spring-security by webauthn4j.

the class WebAuthnConfigurerUtil method getObjectConverterOrCreateNew.

/**
 * Get {@link ObjectConverter} from SharedObject or ApplicationContext. if nothing hit, create new
 */
public static <H extends HttpSecurityBuilder<H>> ObjectConverter getObjectConverterOrCreateNew(H http) {
    ObjectConverter objectConverter = http.getSharedObject(ObjectConverter.class);
    if (objectConverter != null) {
        return objectConverter;
    }
    ApplicationContext applicationContext = http.getSharedObject(ApplicationContext.class);
    String[] beanNames = applicationContext.getBeanNamesForType(ObjectConverter.class);
    if (beanNames.length == 0) {
        ObjectMapper jsonMapper = new ObjectMapper();
        jsonMapper.registerModule(new WebAuthnMetadataJSONModule());
        jsonMapper.registerModule(new WebAuthn4JSpringSecurityJSONModule());
        ObjectMapper cborMapper = new ObjectMapper(new CBORFactory());
        return new ObjectConverter(jsonMapper, cborMapper);
    } else {
        return applicationContext.getBean(ObjectConverter.class);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ObjectConverter(com.webauthn4j.converter.util.ObjectConverter) CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) WebAuthn4JSpringSecurityJSONModule(com.webauthn4j.springframework.security.converter.jackson.WebAuthn4JSpringSecurityJSONModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebAuthnMetadataJSONModule(com.webauthn4j.metadata.converter.jackson.WebAuthnMetadataJSONModule)

Example 2 with WebAuthn4JSpringSecurityJSONModule

use of com.webauthn4j.springframework.security.converter.jackson.WebAuthn4JSpringSecurityJSONModule in project webauthn4j-spring-security by webauthn4j.

the class WebSecurityBeanConfig method objectConverter.

@Bean
public ObjectConverter objectConverter() {
    ObjectMapper jsonMapper = new ObjectMapper();
    jsonMapper.registerModule(new WebAuthnMetadataJSONModule());
    jsonMapper.registerModule(new WebAuthn4JSpringSecurityJSONModule());
    ObjectMapper cborMapper = new ObjectMapper(new CBORFactory());
    return new ObjectConverter(jsonMapper, cborMapper);
}
Also used : CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) ObjectConverter(com.webauthn4j.converter.util.ObjectConverter) WebAuthn4JSpringSecurityJSONModule(com.webauthn4j.springframework.security.converter.jackson.WebAuthn4JSpringSecurityJSONModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebAuthnMetadataJSONModule(com.webauthn4j.metadata.converter.jackson.WebAuthnMetadataJSONModule) Bean(org.springframework.context.annotation.Bean)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CBORFactory (com.fasterxml.jackson.dataformat.cbor.CBORFactory)2 ObjectConverter (com.webauthn4j.converter.util.ObjectConverter)2 WebAuthnMetadataJSONModule (com.webauthn4j.metadata.converter.jackson.WebAuthnMetadataJSONModule)2 WebAuthn4JSpringSecurityJSONModule (com.webauthn4j.springframework.security.converter.jackson.WebAuthn4JSpringSecurityJSONModule)2 ApplicationContext (org.springframework.context.ApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1