在组织中创建 jasper 用户

Create jasper user in an organizaition

我正在努力实现我的 Web 应用程序和 jasper 像微服务一样工作的目标。我使用 rabbitmq 将用户详细信息从我的网络应用程序传递到 jasper。我已经成功地为 jasper 开发了一个消费者,现在我在组织中创建用户时遇到了麻烦。我跟着碧玉的 API 写了我的代码。(Users and Roles API)

我收到这个错误,

java.lang.IllegalArgumentException: This implementation does not support tenants
    at com.jaspersoft.jasperserver.api.metadata.user.service.impl.UserAuthorityServiceImpl.getPersistentTenant(UserAuthorityServiceImpl.java:2029)
    at com.jaspersoft.jasperserver.api.metadata.user.service.impl.UserAuthorityServiceImpl.getRepoUser(UserAuthorityServiceImpl.java:175)
    at com.jaspersoft.jasperserver.api.metadata.user.service.impl.UserAuthorityServiceImpl.getRepoUser(UserAuthorityServiceImpl.java:232)
    at com.jaspersoft.jasperserver.api.metadata.user.service.impl.UserAuthorityServiceImpl.doPutUser(UserAuthorityServiceImpl.java:327)
    at com.jaspersoft.jasperserver.api.metadata.user.service.impl.UserAuthorityServiceImpl.putUser(UserAuthorityServiceImpl.java:316)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)

我只有下面类.

UserConsumer.java

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UsersConsumer implements MessageListener {

    @Autowired
    JasperUserManager jasperUserManager;

    @Override
    public void onMessage(Message message) {
        try {
            System.out.println("==========MESSAGE========>>>>>>>>>> : "+message.toString());
            jasperUserManager.saveUser();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

JasperUserManager.java

import com.jaspersoft.jasperserver.api.common.domain.ExecutionContext;
import com.jaspersoft.jasperserver.api.metadata.user.domain.User;
import com.jaspersoft.jasperserver.api.metadata.user.service.ObjectPermissionService;
import com.jaspersoft.jasperserver.api.metadata.user.service.UserAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class JasperUserManagerImpl implements JasperUserManager {

    @Autowired
    private UserAuthorityService userAuthorityService;

    @Override
    public void saveUser() {
        User user = userAuthorityService.newUser(null);
        user.setUsername("thusira");
        user.setTenantId("ACT");
        user.setPassword("123");
        user.setFullName("Thusira Dissanayake");
        user.setEnabled(true);
        user.setExternallyDefined(false);
        userAuthorityService.putUser(null, user);
        System.out.println("================SSSSSSSSSUUCESSS================================");
    }

}

请帮我看看我的实现中会出现什么问题。

提前致谢

BR, 图西拉

使用 MTUserAuthorityService 后得到这个异常,

org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:339)
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:198)
    at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:60)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy70.putUser(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy70.putUser(Unknown Source)
    at com.cinglevue.veip.report.users.JasperUserManagerImpl.saveUser(JasperUserManagerImpl.java:33)
    at com.cinglevue.veip.report.users.UsersConsumer.onMessage(UsersConsumer.java:20)

问题是 UserAuthorityService 有两个实现。其中之一是一个简单的 UserAuthorityServiceImpl,它对租户一无所知,这与 MTUserAuthorityServiceImpl 不同,后者可以节省租户的用户。

  • 所以首先你应该检查你的 XML 配置。 js.spring.properties 应该包含这一行: bean.userAuthorityService=mtUserAuthorityService

  • 作为第二种方法,您可以直接注入MTUserAuthorityServiceImpl bean。 例如这样:

@Component
public class JasperUserManagerImpl implements JasperUserManager {

    @Resource(name="")
    private UserAuthorityService userAuthorityService;

    @Override
    public void saveUser() {
        User user = userAuthorityService.newUser(null);
        user.setUsername("thusira");
        user.setTenantId("ACT");
        user.setPassword("123");
        user.setFullName("Thusira Dissanayake");
        user.setEnabled(true);
        user.setExternallyDefined(false);
        userAuthorityService.putUser(null, user);  
    }
}
  • 在最后一种情况下,您可能没有 Jasperserver MultipleTenancy 许可证(例如,如果您使用社区版),因此您根本无法使用租户。