Search in sources :

Example 1 with BasicAuthenticationEncoder

use of org.springframework.security.rsocket.metadata.BasicAuthenticationEncoder in project spring-security by spring-projects.

the class AuthenticationPayloadInterceptorTests method createRequestPayload.

private Payload createRequestPayload() {
    UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("user", "password");
    BasicAuthenticationEncoder encoder = new BasicAuthenticationEncoder();
    DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
    ResolvableType elementType = ResolvableType.forClass(UsernamePasswordMetadata.class);
    MimeType mimeType = UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE;
    Map<String, Object> hints = null;
    DataBuffer dataBuffer = encoder.encodeValue(credentials, factory, elementType, mimeType, hints);
    ByteBufAllocator allocator = ByteBufAllocator.DEFAULT;
    CompositeByteBuf metadata = allocator.compositeBuffer();
    CompositeMetadataCodec.encodeAndAddMetadata(metadata, allocator, mimeType.toString(), NettyDataBufferFactory.toByteBuf(dataBuffer));
    return DefaultPayload.create(allocator.buffer(), metadata);
}
Also used : CompositeByteBuf(io.netty.buffer.CompositeByteBuf) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) UsernamePasswordMetadata(org.springframework.security.rsocket.metadata.UsernamePasswordMetadata) BasicAuthenticationEncoder(org.springframework.security.rsocket.metadata.BasicAuthenticationEncoder) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) ResolvableType(org.springframework.core.ResolvableType) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType) DataBuffer(org.springframework.core.io.buffer.DataBuffer)

Aggregations

ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)1 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)1 ResolvableType (org.springframework.core.ResolvableType)1 DataBuffer (org.springframework.core.io.buffer.DataBuffer)1 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)1 BasicAuthenticationEncoder (org.springframework.security.rsocket.metadata.BasicAuthenticationEncoder)1 UsernamePasswordMetadata (org.springframework.security.rsocket.metadata.UsernamePasswordMetadata)1 MimeType (org.springframework.util.MimeType)1