Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2015 JBoss Inc
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * 
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package org.kie.remote.services.jms.request;
import  javax.enterprise.context.RequestScoped;
import  javax.enterprise.inject.Produces;
import  org.jbpm.kie.services.impl.audit.ServicesAwareAuditEventBuilder;
import  org.jbpm.services.cdi.RequestScopedBackupIdentityProvider;
import  org.kie.internal.identity.IdentityProvider;
import  org.slf4j.Logger;
import  org.slf4j.LoggerFactory;

See the ServicesAwareAuditEventBuilder bean for more context. This bean provides a RequestScopedBackupIdentityProvider instance for JMS requests, which have a Request scope but for which the "normally" provided ("normally" as in with REST requests) IdentityProvider is not available. This due to vagaries of the code, as always.
@RequestScoped
    private static final Logger logger = LoggerFactory.getLogger(RequestMessageBean.class);
    
    private RequestScopedBackupIdentityProvider identityProvider = null;
    
    public RequestScopedBackupIdentityProvider createBackupIdentityProvider(String commandUserList<Stringroles) {
        .debug( "Creating identity provider for user: {}"commandUser);
        ifcommandUser == null ) { 
            commandUser = RequestScopedBackupIdentityProvider.UNKNOWN;
        }
        final String nameValue = commandUser;
        
        this. =  new RequestScopedBackupIdentityProvider() {
            
            private String name = nameValue;
            
            @Override
            public String getName() {
                return ;
            }
        };
        
        return this.;
    }
    
    @Produces
    @RequestScoped
    public RequestScopedBackupIdentityProvider getJmsRequestScopeIdentityProvider() {
        if (this. != null) {
            .debug( "Producing backup identity bean for user: {}" , this..getName() );
            return this.;
        } else {
            .debug( "Unknown user during JMS request" );
            // in case there is none set return dummy one as @RequestScoped producers cannot return null
            return new RequestScopedBackupIdentityProvider() {
                
                @Override
                public String getName() {
                    return RequestScopedBackupIdentityProvider.UNKNOWN;
                }
            };
        }
    }
New to GrepCode? Check out our FAQ X