File tree 2 files changed +11
-3
lines changed 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 6
6
import org .springframework .boot .autoconfigure .domain .EntityScan ;
7
7
import org .springframework .data .jpa .domain .support .AuditingEntityListener ;
8
8
9
+ import java .util .HashSet ;
9
10
import java .util .Set ;
10
11
11
12
@ Entity
@@ -23,7 +24,7 @@ public class User {
23
24
private String username ;
24
25
private int logins ;
25
26
private int failedLogins ;
26
- private Set <Project > projects ;
27
+ private Set <Project > projects = new HashSet <>(); ;
27
28
private String apiKey ;
28
29
29
30
@ Column (name = "apikey" )
@@ -35,7 +36,7 @@ public void setApiKey(String apiKey) {
35
36
this .apiKey = apiKey ;
36
37
}
37
38
38
- @ ManyToMany
39
+ @ ManyToMany ( fetch = FetchType . EAGER )
39
40
@ JoinTable (
40
41
name = "user_project" ,
41
42
joinColumns = { @ JoinColumn (name = "users_id" ) },
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ public class PermissionFactory {
34
34
* @return boolean
35
35
*/
36
36
public boolean canUserAccessProject (Principal principal , Project project ){
37
+ if (project == null || project .getId () == null ) {
38
+ // Handle null project appropriately
39
+ return false ;
40
+ }
37
41
User user = getUserFromPrincipal (principal );
38
42
if (apiKeyAccessProject (principal ,project )){
39
43
return true ;
@@ -44,7 +48,10 @@ else if (user != null && (
44
48
user .getPermisions ().equals (Constants .ROLE_AUDITOR ))){
45
49
return true ;
46
50
} else if ( user != null && (user .getPermisions ().equals (Constants .ROLE_USER ) || user .getPermisions ().equals (Constants .ROLE_PROJECT_OWNER ) || user .getPermisions ().equals (Constants .ROLE_EDITOR_RUNNER ))){
47
- return user .getProjects ().stream ().map (Project ::getId ).collect (Collectors .toList ()).contains (project .getId ());
51
+ return user .getProjects () != null && user .getProjects ().stream ()
52
+ .map (Project ::getId )
53
+ .anyMatch (id -> id .equals (project .getId ()));
54
+
48
55
} else if (principal .getName ().equals (Constants .STRATEGY_SCHEDULER )) {
49
56
return true ;
50
57
}else
You can’t perform that action at this time.
0 commit comments