小编Aur*_*e77的帖子

如何使用Spring Security重新加载用户更新的权限

我正在使用Spring Security通过OpenID进行身份验证的应用程序.当用户登录时,会话中会加载某些权限.

我拥有完全权限的用户,可以修改其他用户的权限(撤销,添加角色).我的问题是,如何动态更改用户会话权限?(不能使用SecurityContextHolder,因为我想更改另一个用户会话).

简单方法:使用户会话无效,但如何?更好的方法:刷新用户会话与新权限,但如何?

java spring spring-security

38
推荐指数
4
解决办法
3万
查看次数

如何持久化@ManyToMany关系 - 重复条目或分离实体

我想用ManyToMany关系来保持我的实体.但是在持久化过程中我遇到了一些问题.

我的实体:

@Entity
@Table(name = "USER")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long userId;

    @Column(name = "NAME", unique = true, nullable = false)
    String userName;

    @Column(name = "FORNAME")
    String userForname;

    @Column(name = "EMAIL")
    String userEmail;

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "USER_USER_ROLES", joinColumns = @JoinColumn(name = "ID_USER"), inverseJoinColumns = @JoinColumn(name = "ID_ROLE"))
    List<UserRoles> userRoles = new ArrayList<UserRoles>();

    // getter et setter
}
Run Code Online (Sandbox Code Playgroud)

@Entity …
Run Code Online (Sandbox Code Playgroud)

java many-to-many jpa duplicates unique-constraint

15
推荐指数
2
解决办法
3万
查看次数

在 React Navigation v6 中组织屏幕/组结构

我正在尝试将旧的 React navigation v4 迁移到 v6(超过 100 条路线)。但我面临着如何找到最佳结构来分割单独文件/组件中的屏幕组。

我已经尝试过这样做,以移出模态:

const ModalGroup = () => (
  <Stack.Group screenOptions={{ presentation: "modal" }}>
    <Stack.Screen name="ModalA" component={ModalAScreen} />
    <Stack.Screen name="ModalB" component={ModalBScreen} />
  </Stack.Group>
);

export const RootNavigator = () => (
  <Stack.Navigator initialRouteName="Home">
    <Stack.Screen name="Home" component={HomeScreen} />
    <ModalGroup />
  </Stack.Navigator>
);
Run Code Online (Sandbox Code Playgroud)

但在运行时不允许出现此错误:

错误:导航器只能包含“Screen”、“Group”或“React.Fragment”作为其直接子级(找到“ModalGroup”)。要在导航器中渲染此组件,请将其在 'component' 属性中传递给 'Screen'。

但这是有效的(但对我来说看起来很难看):

export const RootNavigator = () => (
  <Stack.Navigator initialRouteName="Home">
    <Stack.Screen name="Home" component={HomeScreen} />
    {ModalGroup()}
  </Stack.Navigator>
);
Run Code Online (Sandbox Code Playgroud)

那么,在单独的文件中构建/组织屏幕组以避免创建包含所有配置和导入的巨大根导航器的最佳方法是什么?

react-native react-navigation react-navigation-v6

8
推荐指数
0
解决办法
1353
查看次数

如何在单元测试中设置不同的类路径以使用Spring加载资源

我想使用 JUnit 和 Spring 创建 2 个测试用例,它们需要相同的类路径资源batch-configuration.properties,但该文件的内容根据测试而有所不同。

实际上在我的 Maven 项目中,我创建了这些文件树:

  • src/test/resources/test1/batch-configuration.properties
  • src/test/resources/test2/batch-configuration.properties

但是我如何根据我的测试用例定义我的根类路径(文件是在ExtractionBatchConfigurationusing中加载的classpath:batch-configuration.properties

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { ExtractionBatchConfiguration.class }, loader = AnnotationConfigContextLoader.class)
@PropertySource("classpath:test1/batch-configuration.properties") // does not override ExtractionBatchConfiguration declaration
public class ExtractBatchTestCase {
    private static ConfigurableApplicationContext context;

    private JobLauncherTestUtils jobLauncherTestUtils;

    @BeforeClass
    public static void beforeClass() {
        context = SpringApplication.run(ExtractionBatchConfiguration.class);
    }

    @Before
    public void setup() throws Exception {      
        jobLauncherTestUtils = new JobLauncherTestUtils();
        jobLauncherTestUtils.setJobLauncher(context.getBean(JobLauncher.class));
        jobLauncherTestUtils.setJobRepository(context.getBean(JobRepository.class));
    }

    @Test
    public void testGeneratedFiles() throws Exception {     
        jobLauncherTestUtils.setJob(context.getBean("extractJob1", Job.class));
        JobExecution …
Run Code Online (Sandbox Code Playgroud)

java spring unit-testing spring-batch spring-boot

7
推荐指数
1
解决办法
2万
查看次数

如何在 Prettier v2 中禁用运算符等于后的换行符

我刚刚使用 eslint-plugin-prettier 将我的应用程序从 prettier 1.19.1 升级到 2.5.1。但我面临着巨大的变化。我希望之前的行为符合此规则:

// prettier v1
const [
  currentRouteName,
  currentParams
] = getActiveRoute(currentState);

// prettier v2 - note line break after "="
const [currentRouteName, currentParams] =
  getActiveRoute(currentState);
Run Code Online (Sandbox Code Playgroud)

是否可以覆盖此更改换行符的规则(似乎与 printWith 有关,但此设置在我的 .prettierrc 中没有更改)?

prettier prettier-eslint

7
推荐指数
0
解决办法
421
查看次数

使用自定义模式定义进行Spring Ldap单元测试

我正在尝试使用Spring Ldap为嵌入式ldap进行单元测试.但是我需要为自定义objectClasses/attributes定义使用自定义模式.如何使用Spring Ldap测试(LdapTestUtils?)进行配置?

实际上,如果我运行测试,它失败说我的自定义objectClass"myOb"未在模式中定义,并带有以下消息:

org.springframework.ldap.UncategorizedLdapException: Failed to populate LDIF; nested exception is javax.naming.directory.NoSuchAttributeException: [LDAP: error code 16 - NO_SUCH_ATTRIBUTE: failed for     Add Request :
...
: OID for name 'myOb' was not found within the OID registry]; remaining name 'cn=123456, ou=MyUser, o=company.com'
Run Code Online (Sandbox Code Playgroud)

如果我objectClass: myOb从ldif 发表评论,则测试失败并显示空值(未读取属性).

这是我的测试类:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = LdapConfiguration.class, loader = AnnotationConfigContextLoader.class)
public class LdapTest {

    // Ldap port
    private static final int LDAP_PORT = 18880;

    // Base DN for test data
    private static final …
Run Code Online (Sandbox Code Playgroud)

java spring unit-testing ldap spring-ldap

6
推荐指数
1
解决办法
2597
查看次数

Spring Batch如何在将重复项发送到ItemWriter之前对其进行过滤

我读了一个平面文件(例如.csv文件,每个用户1行,Ex:UserId; Data1; Date2).

但是如何在阅读器中处理重复的用户项目(哪里没有previus readed用户列表......)

stepBuilderFactory.get("createUserStep1")
.<User, User>chunk(1000)
.reader(flatFileItemReader) // FlatFileItemReader
.writer(itemWriter) // For example JDBC Writer
.build();
Run Code Online (Sandbox Code Playgroud)

spring batch-processing spring-batch

5
推荐指数
2
解决办法
1万
查看次数

如何更改接受 Firebase 应用分发邀请的 Google 帐户?

我在我的公司Google 帐户中收到了 Firebase 应用分发邀请。但是,当我通过单击电子邮件中的“开始设置”接受邀请时,我错误地使用我的 Android 手机中的个人谷歌帐户接受了邀请。我试图用我的公司谷歌帐户重新接受邀请,但App Tester应用程序说:

邀请已被接受

我试图撤销我在 Firebase 控制台中的访问权限,并再次添加我的公司google 帐户。但它保持邀请状态已“接受”。有没有办法从谷歌帐户中删除应用程序,以便能够再次接受另一个帐户的邀请?谢谢。

android google-account firebase google-fabric firebase-app-distribution

5
推荐指数
1
解决办法
1147
查看次数

检测文本中的 IBAN

有一个简单的正则表达式模式可以检测文本中的 IBAN(包括特定国家/地区格式?)

实际上我正在用这个正则表达式找到 IBAN :

[a-zA-Z]{2}[0-9]{2}[0-9a-zA-Z]{10,30}
Run Code Online (Sandbox Code Playgroud)

但这与格式化的 IBAN 不匹配(正常,我没有引入空格检测):

FR76 30003 02420 002202XXXXX 77
Run Code Online (Sandbox Code Playgroud)

或者

PT50 0002 0123 1234 5678 9015 4
Run Code Online (Sandbox Code Playgroud)

你能帮助我吗 ?在哪里可以找到按国家/地区划分的所有格式化 IBAN 模式?

例子 :

“我的 IBAN 是 PT50 0002 0123 1234 5678 9015 1 用正则表达式捕获它,这也是 PT50000201231234567890151 !”

我想提取/处理“PT50 0002 0123 1234 5678 9015 1”和“PT50000201231234567890151”。

编辑: 解决方案 1 - 很长的模式:

((NO)[0-9A-Z]{2}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{3}|(NO)[0-9A-Z]{13}|(BE)[0-9A-Z]{2}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}|(BE)[0-9A-Z]{14}|(DK|FO|FI|GL|NL)[0-9A-Z]{2}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{2}|(DK|FO|FI|GL|NL)[0-9A-Z]{16}|(MK|SI)[0-9A-Z]{2}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{3}|(MK|SI)[0-9A-Z]{17}|(BA|EE|KZ|LT|LU|AT)[0-9A-Z]{2}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}|(BA|EE|KZ|LT|LU|AT)[0-9A-Z]{18}|(HR|LI|LV|CH)[0-9A-Z]{2}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{1}|(HR|LI|LV|CH)[0-9A-Z]{19}|(BG|DE|IE|ME|RS|GB)[0-9A-Z]{2}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ ][0-9A-Z]{4}[ …
Run Code Online (Sandbox Code Playgroud)

javascript regex iban detection

1
推荐指数
1
解决办法
1万
查看次数