OadrSecurityRoleService { public User grantBasicRole(String username, CharSequence rawPassword) { AbstractUser abstractUser = saveFindUser(username); if (!encoder.matches(rawPassword, abstractUser.getBasicPassword())) { throw new BadCredentialsException("Bad credentials given for user: '" + username + "'"); } return this.grantRole(abstractUser, abstractUser.getBasicPassword()); }  User digestUserDetail(String username); User grantDigestRole(String username, String password); User grantBasicRole(String username, CharSequence rawPassword); User grantX509Role(String username);  }
@Test public void grantBasicRoleTest() { User grantBasicRole = oadrSecurityRoleService.grantBasicRole("passUser", "passUser"); List<GrantedAuthority> authorities = new ArrayList<>(grantBasicRole.getAuthorities()); assertEquals(1, authorities.size()); assertEquals("ROLE_USER", authorities.get(0).getAuthority()); grantBasicRole = oadrSecurityRoleService.grantBasicRole(appUser.getUsername(), appUser.getUsername()); authorities = new ArrayList<>(grantBasicRole.getAuthorities()); assertEquals(2, authorities.size()); assertTrue(authorities.get(0).getAuthority().equals("ROLE_APP") || authorities.get(0).getAuthority().equals("ROLE_DEVICE_MANAGER")); assertTrue(authorities.get(1).getAuthority().equals("ROLE_APP") || authorities.get(1).getAuthority().equals("ROLE_DEVICE_MANAGER")); grantBasicRole = oadrSecurityRoleService.grantBasicRole(adminUser.getUsername(), adminUser.getUsername()); authorities = new ArrayList<>(grantBasicRole.getAuthorities()); assertEquals(2, authorities.size()); assertTrue(authorities.get(0).getAuthority().equals("ROLE_USER") || authorities.get(0).getAuthority().equals("ROLE_ADMIN")); assertTrue(authorities.get(1).getAuthority().equals("ROLE_USER") || authorities.get(1).getAuthority().equals("ROLE_ADMIN")); boolean exception = false; try { oadrSecurityRoleService.grantBasicRole("passUser", "mouaiccool"); } catch (Exception e) { exception = true; } assertTrue(exception); }