@Test public void getUserAuthoritiesForToken() { BPermission p1 = permissionRepository.save(EntityUtil.getSamplePermission(random.nextString())); assertNotNull(p1); BPermission p2 = permissionRepository.save(EntityUtil.getSamplePermission(random.nextString())); assertNotNull(p2); BRole r1 = EntityUtil.getSampleRole(random.nextString()); r1.addPermission(p1, p2); assertNotNull(roleRepository.save(r1)); BPermission p3 = permissionRepository.save(EntityUtil.getSamplePermission(random.nextString())); assertNotNull(p3); BPermission p4 = permissionRepository.save(EntityUtil.getSamplePermission(random.nextString())); assertNotNull(p4); BRole r2 = EntityUtil.getSampleRole(random.nextString()); r2.addPermission(p3, p4); assertNotNull(roleRepository.save(r2)); EUser u = userRepository.save(EntityUtil.getSampleUser(random.nextString())); assertNotNull(u); EOwnedEntity e = entityRepository.save(EntityUtil.getSampleEntity(random.nextString())); assertNotNull(e); BAuthorization.BAuthorizationPk pk1 = new BAuthorization.BAuthorizationPk(u.getId(), e.getId(), r1.getId()); BAuthorization auth1 = new BAuthorization(pk1, u, e, r1); assertNotNull(authorizationRepository.save(auth1)); BAuthorization.BAuthorizationPk pk2 = new BAuthorization.BAuthorizationPk(u.getId(), e.getId(), r2.getId()); BAuthorization auth2 = new BAuthorization(pk2, u, e, r2); assertNotNull(authorizationRepository.save(auth2)); String separator = "--<<" + random.nextString() + ">>--"; String authForToken = userService.getUserAuthoritiesForToken(u.getUsername(), separator); assertNotNull(authForToken); assertNotEquals("", authForToken); List<String> permissionNames = Arrays.asList(authForToken.split(separator)); assertTrue(permissionNames.contains(p1.getName())); assertTrue(permissionNames.contains(p2.getName())); assertTrue(permissionNames.contains(p3.getName())); assertTrue(permissionNames.contains(p4.getName())); }
public String getUserAuthoritiesForToken(final String usernameOrEmail, final String separator) { StringBuilder authBuilder = new StringBuilder(); EUser u = (EUser) loadUserByUsername(usernameOrEmail); if (u != null) { Long entityId = getEntityIdByUser(u); if (entityId == null) { return ""; } List<BPermission> pFromDB = permissionService.findPermissionsByUserIdAndEntityId(u.getId(), entityId); for (BPermission p : pFromDB) { authBuilder.append(p.getName()).append(separator); } } return authBuilder.toString(); }
UserService implements UserDetailsService { public String getUserAuthoritiesForToken(final String usernameOrEmail, final String separator) { StringBuilder authBuilder = new StringBuilder(); EUser u = (EUser) loadUserByUsername(usernameOrEmail); if (u != null) { Long entityId = getEntityIdByUser(u); if (entityId == null) { return ""; } List<BPermission> pFromDB = permissionService.findPermissionsByUserIdAndEntityId(u.getId(), entityId); for (BPermission p : pFromDB) { authBuilder.append(p.getName()).append(separator); } } return authBuilder.toString(); } }
UserService implements UserDetailsService { public String getUserAuthoritiesForToken(final String usernameOrEmail, final String separator) { StringBuilder authBuilder = new StringBuilder(); EUser u = (EUser) loadUserByUsername(usernameOrEmail); if (u != null) { Long entityId = getEntityIdByUser(u); if (entityId == null) { return ""; } List<BPermission> pFromDB = permissionService.findPermissionsByUserIdAndEntityId(u.getId(), entityId); for (BPermission p : pFromDB) { authBuilder.append(p.getName()).append(separator); } } return authBuilder.toString(); }  }
UserService implements UserDetailsService { public String getUserAuthoritiesForToken(final String usernameOrEmail, final String separator) { StringBuilder authBuilder = new StringBuilder(); EUser u = (EUser) loadUserByUsername(usernameOrEmail); if (u != null) { Long entityId = getEntityIdByUser(u); if (entityId == null) { return ""; } List<BPermission> pFromDB = permissionService.findPermissionsByUserIdAndEntityId(u.getId(), entityId); for (BPermission p : pFromDB) { authBuilder.append(p.getName()).append(separator); } } return authBuilder.toString(); }  EUser createDefaultUser(); EUser signUp(final EUser u, final EmailStatus emailStatus); EUser signUp(final EUser u, final EmailStatus emailStatus,
                        final RegistrationPrivilege registrationPrivilege); List<Long> addRolesToUser(final Long userId, final Long entityId,
                                     final Iterable<Long> rolesId); List<Long> removeRolesFromUser(final Long userId, final Long entityId, final Iterable<Long> rolesId); @Override UserDetails loadUserByUsername(final String usernameOrEmail); String getUserAuthoritiesForToken(final String usernameOrEmail, final String separator); Map<String, List<BRole>> getRolesForUser(final Long id); List<BRole> getRolesForUserOverEntity(final Long userId, final Long entityId); Long getEntityIdByUser(final EUser u); }
UserService implements UserDetailsService { public String getUserAuthoritiesForToken(final String usernameOrEmail, final String separator) { StringBuilder authBuilder = new StringBuilder(); EUser u = (EUser) loadUserByUsername(usernameOrEmail); if (u != null) { Long entityId = getEntityIdByUser(u); if (entityId == null) { return ""; } List<BPermission> pFromDB = permissionService.findPermissionsByUserIdAndEntityId(u.getId(), entityId); for (BPermission p : pFromDB) { authBuilder.append(p.getName()).append(separator); } } return authBuilder.toString(); }  EUser createDefaultUser(); EUser signUp(final EUser u, final EmailStatus emailStatus); EUser signUp(final EUser u, final EmailStatus emailStatus,
                        final RegistrationPrivilege registrationPrivilege); List<Long> addRolesToUser(final Long userId, final Long entityId,
                                     final Iterable<Long> rolesId); List<Long> removeRolesFromUser(final Long userId, final Long entityId, final Iterable<Long> rolesId); @Override UserDetails loadUserByUsername(final String usernameOrEmail); String getUserAuthoritiesForToken(final String usernameOrEmail, final String separator); Map<String, List<BRole>> getRolesForUser(final Long id); List<BRole> getRolesForUserOverEntity(final Long userId, final Long entityId); Long getEntityIdByUser(final EUser u);  }