简体   繁体   English

带有令牌存储的CXF自定义安全令牌提供程序

[英]CXF Custom Security Token provider with Token Store

I try to implement a Security Token Service (Server side) with a requested UsernameToken and my service should response a token, which is generated by cxf. 我尝试使用请求的UsernameToken实现安全令牌服务(服务器端),我的服务应该响应由cxf生成的令牌。 I use JAVA, Spring Boot and a java-based configuration. 我使用JAVA,Spring Boot和基于java的配置。

I have some problems to implement a custom Token Provider and using the default tokenstore from cxf. 我在实现自定义令牌提供程序和使用cxf中的默认令牌存储时遇到一些问题。

My custom SCTProvider: 我的自定义SCTProvider:

public class BiPROTokenProvider extends SCTProvider{

private static final String WSC_IDENTIFIER = "wsc:Identifier";
private static final String BIPRO_PRAEFIX = "bipro:";

@Override
public TokenProviderResponse createToken(TokenProviderParameters tokenParameters) {
    TokenProviderResponse response = super.createToken(tokenParameters);

    String biproId = BIPRO_PRAEFIX + response.getTokenId().split(":")[1];


    //NodeList identifier = ((Element) response.getToken()).getElementsByTagName(WSC_IDENTIFIER);
    //identifier.item(0).setTextContent(biproId);
    //Element identifier = response.getTokenId().getElementsByTagName(WSC_IDENTIFIER);

    //super.createToken(tokenParameters).setTokenId(biproId);
    response.setTokenId(biproId);

    return response;
}

} }

My first problem is, that I do not know where I should include my custom SCT Provider? 我的第一个问题是,我不知道应该在哪里包含我的自定义SCT提供程序? - is it possible do to it at my endpoint publish? - 我的端点发布是否可以做到?

    @Bean
    public Endpoint endpoint() {
    EndpointImpl endpoint = new EndpointImpl(springBus(), securityTokenServicePortType());
   endpoint.setServiceName(securityTokenService26010().getServiceName());
      endpoint.setWsdlLocation(securityTokenService26010().getWSDLDocumentLocation().toString());  
   endpoint.publish("/SecurityTokenService-2.6.0.1.0");
   endpoint.getOutFaultInterceptors().add(soapInterceptor());
   return endpoint;
   }
    @Bean
    public DefaultInMemoryTokenStore defaulttokenStore(){
    return new DefaultInMemoryTokenStore();
    }
    @Bean 
    SCTProvider customSCTProvider(){
    return new BiPROTokenProvider();
    }

Second problem: I want to store my generated token in a default tokenstore from cxf. 第二个问题:我想将生成的令牌存储在cxf的默认令牌库中。 I read something about a tokenstore. 我读了一些关于令牌库的内容。 http://cxf.apache.org/docs/ws-securitypolicy.html In my opinion I have to include the tokenstore in the enpointproperties from service implementation. http://cxf.apache.org/docs/ws-securitypolicy.html在我看来,我必须在服务实现的enpointproperties中包含tokenstore。

    @WebService
    (
       portName = "wst:UserPasswordLogin",
       serviceName = "SecurityTokenService_2.6.0.1.0",
       wsdlLocation = "src/main/resources/wsdl/SecurityTokenService-   2.6.0.1.0.wsdl",
      endpointInterface = "net.bipro.namespace.SecurityTokenServicePortType"
       )
@EndpointProperties({

@EndpointProperty(key = "ws-security.callback-handler", value="com.muki.endpoint.STSCallbackHandler"),
//@EndpointProperty(key = "ws-security.add.inclusive.prefixes", value="false"),
@EndpointProperty(key = "org.apache.cxf.ws.security.tokenstore.TokenStore", value="TOKEN_STORE_CACHE_INSTANCE"),
  })
  public class SecurityTokenEndpoint implements SecurityTokenServicePortType {
  ...
  }

But if I include the tokenstore via the endpoint properties, I receive the following error. 但是如果我通过端点属性包含tokenstore,我会收到以下错误。

    <faultstring>java.lang.String cannot be cast to org.apache.cxf.ws.security.tokenstore.TokenStore</faultstring>

Can anybody help how I include a tokenstore and my custom SCT Provider? 任何人都可以帮助我如何包含令牌库和我的自定义SCT提供程序吗?

I had similar issue but I use xml configuration. 我有类似的问题,但我使用xml配置。 Instead of value I used value-ref and passed bean there: 而不是value我使用value-ref并在那里传递bean:

<jaxws:endpoint 
    id="endpointId" 
    address="/foo/bar" 
    ...
    serviceName="ns1:ServiceName">
    <jaxws:properties>
        ...
        <entry key="org.apache.cxf.ws.security.tokenstore.TokenStore" value-ref="tokenStore" />
    </jaxws:properties>
</jaxws:endpoint>

<bean id="tokenStore" class="org.apache.cxf.ws.security.tokenstore.MemoryTokenStore"/>

The error was gone but it wasn't working correctly - TokenStore wasn't set. 错误消失但它无法正常工作 - TokenStore未设置。 So I tried another approach. 所以我尝试了另一种方法。 Instead of editing endpoint I added that entry to bus config: 我没有编辑端点,而是将该条目添加到总线配置:

<cxf:bus>
    <cxf:properties>
        <entry key="org.apache.cxf.ws.security.tokenstore.TokenStore" value-ref="tokenStore" />
    </cxf:properties>
</cxf:bus>

<bean id="tokenStore" class="org.apache.cxf.ws.security.tokenstore.MemoryTokenStore"/>

As for your question, I believe your syntax would look like: 至于你的问题,我相信你的语法看起来像:

@EndpointProperty(key = "org.apache.cxf.ws.security.tokenstore.TokenStore", ref="bean-name")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.springframework.security.oauth2.provider.token.store.MongoDBTokenStore - org.springframework.security.oauth2.provider.token.store.MongoDBTokenStore 使用Spring Security 3在我的Grails OAuth提供程序上存储访问令牌 - Store access token on my Grails OAuth provider using Spring Security 3 从 AWS Credentials Provider 获取安全令牌 - Get security token from AWS Credentials Provider Spring 安全自定义令牌过滤器 - Spring security custom token filter 使用Apache CXF为Java中的Azure Pack获取安全令牌 - Getting a Security Token for Azure Pack in Java Using Apache CXF 没有签名令牌Java CXF客户端 - No signature token Java CXF Client Spring Security Oauth 2。 在服务器端存储refresh_token - Spring Security Oauth2. Store refresh_token on server side Spring-请求上下文或仅用于存储访问令牌的安全上下文? - Spring - Request context or Security context for store only the access token? 生成自定义jwt令牌并验证用户,Spring Security - Generate custom jwt-token and Authenticate user, Spring Security Spring Security和OAuth2使用自定义授权类型生成令牌 - Spring Security and OAuth2 generate token with custom grant type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM