OadrSecurityRoleService { public User grantX509Role(String username) { if (username.equals(vtnConfig.getOadr20bFingerprint())) { return new User(username, "", Lists.newArrayList(new SimpleGrantedAuthority("ROLE_VTN"))); } return this.grantRole(saveFindUser(username), ""); }  User digestUserDetail(String username); User grantDigestRole(String username, String password); User grantBasicRole(String username, CharSequence rawPassword); User grantX509Role(String username);  }
@Test public void grantX509RoleTest() throws OadrSecurityException { X509Certificate cert = OadrPKISecurity.parseCertificate("src/test/resources/cert/test.crt"); String fingerprint = OadrFingerprintSecurity.getOadr20bFingerprint(cert); User grantX509Role = oadrSecurityRoleService.grantX509Role(fingerprint); List<GrantedAuthority> authorities = new ArrayList<>(grantX509Role.getAuthorities()); assertEquals(1, authorities.size()); assertEquals("ROLE_VEN", authorities.get(0).getAuthority()); venX509.setRegistrationId("registrationId"); venService.save(venX509); grantX509Role = oadrSecurityRoleService.grantX509Role(fingerprint); authorities = new ArrayList<>(grantX509Role.getAuthorities()); assertEquals(2, authorities.size()); assertTrue(authorities.get(1).getAuthority().equals("ROLE_VEN") || authorities.get(1).getAuthority().equals("ROLE_REGISTERED")); assertTrue(authorities.get(0).getAuthority().equals("ROLE_VEN") || authorities.get(0).getAuthority().equals("ROLE_REGISTERED")); grantX509Role = oadrSecurityRoleService.grantX509Role(vtnConfig.getOadr20bFingerprint()); authorities = new ArrayList<>(grantX509Role.getAuthorities()); assertEquals(1, authorities.size()); assertEquals("ROLE_VTN", authorities.get(0).getAuthority()); boolean exception = false; try { oadrSecurityRoleService.grantX509Role("mouaiccool"); } catch (Exception e) { exception = true; } assertTrue(exception); }