9
9
import main .model .db .dao .project .UserDao ;
10
10
import main .model .db .imports .Importer ;
11
11
import main .model .db .imports .TestNameNodeType ;
12
- import main .model .dto .ProjectUserDto ;
13
- import main .model .dto .TestRunDto ;
14
- import main .model .dto .UserDto ;
12
+ import main .model .dto .*;
15
13
import main .model .email .TestRunEmails ;
16
- import org .xml .sax .SAXException ;
17
14
18
- import javax .xml .parsers .ParserConfigurationException ;
15
+ import javax .naming .AuthenticationException ;
16
+ import java .util .Collections ;
19
17
import java .util .List ;
20
18
import java .util .stream .Collectors ;
21
19
@@ -25,19 +23,32 @@ public class Session {
25
23
private String session ;
26
24
public ControllerFactory controllerFactory ;
27
25
28
- public Session (String sessionId ) throws AqualityException {
29
- if (isSessionValid (sessionId )){
30
- setUserMembership ();
26
+ public Session (String sessionId ) throws AqualityException , AuthenticationException {
27
+ if (isSessionValid (sessionId )) {
28
+ controllerFactory = new ControllerFactory (user );
29
+ return ;
31
30
}
32
- controllerFactory = new ControllerFactory (user );
31
+ throw new AuthenticationException ("Your session is not valid!" );
32
+ }
33
+
34
+ public Session (UserDto user ) throws AqualityException {
35
+ this .user = user ;
36
+ setUserMembership ();
37
+ controllerFactory = new ControllerFactory (this .user );
33
38
}
34
39
35
- public Session (){
40
+ @ Deprecated
41
+ public Session (String importToken , int projectId ) throws AqualityException {
36
42
user = new UserDto ();
37
- user .setAdmin (1 );
38
- user .setUnit_coordinator (1 );
39
- user .setManager (1 );
40
43
controllerFactory = new ControllerFactory (user );
44
+ if (controllerFactory .getHandler (new ImportTokenDto ()).isTokenValid (importToken , projectId )){
45
+ ProjectUserDto projectUser = new ProjectUserDto ();
46
+ projectUser .setProject_id (projectId );
47
+ projectUser .setEngineer (1 );
48
+ projectUser .setViewer (1 );
49
+ user .setProjectUsers (Collections .singletonList (projectUser ));
50
+ controllerFactory = new ControllerFactory (user );
51
+ }
41
52
}
42
53
43
54
public List <ProjectUserDto > getProjectPermissions (){
@@ -49,11 +60,7 @@ public List<ProjectUserDto> getProjectPermissions(Integer projectId){
49
60
}
50
61
51
62
public Importer getImporter (List <String > filePaths , TestRunDto testRunTemplate , String pattern , String format , TestNameNodeType nodeType , boolean singleTestRun ) throws AqualityException {
52
- try {
53
- return new Importer (filePaths , testRunTemplate , pattern , format , nodeType , singleTestRun , user );
54
- } catch (ParserConfigurationException | SAXException e ) {
55
- throw new AqualityException ("Some Internal SAX error: " + e .getMessage ());
56
- }
63
+ return new Importer (filePaths , testRunTemplate , pattern , format , nodeType , singleTestRun , user );
57
64
}
58
65
59
66
public TestRunEmails getTestRunEmails (){
@@ -68,7 +75,7 @@ public AdministrationController getAdministrationController() {
68
75
return new AdministrationController (user );
69
76
}
70
77
71
- public ProjectController getProjectController () throws AqualityException {
78
+ public ProjectController getProjectController (){
72
79
return new ProjectController (user );
73
80
}
74
81
@@ -84,29 +91,20 @@ public UserDto getCurrentUser() {
84
91
return user ;
85
92
}
86
93
87
- public void setCurrentUser (UserDto user ) throws AqualityException {
88
- this .user = user ;
89
- setUserMembership ();
90
- }
91
-
92
94
private void setUserMembership () throws AqualityException {
93
95
ProjectUserDto projectUserDto = new ProjectUserDto ();
94
96
projectUserDto .setUser_id (user .getId ());
95
97
user .setProjectUsers (new ProjectUserController (user ).getProjectUserForPermissions (projectUserDto ));
96
98
}
97
99
98
100
public boolean isSessionValid () throws AqualityException {
99
- return isSessionValid (session );
101
+ return isSessionValid (session );
100
102
}
101
103
102
104
private boolean isSessionValid (String sessionId ) throws AqualityException {
103
- if (sessionId != null ){
104
- UserDao userDao = new UserDao ();
105
- user = userDao .IsAuthorized (sessionId );
106
- session = sessionId ;
107
- return user != null ;
108
- }
109
- user = null ;
110
- return false ;
105
+ UserDao userDao = new UserDao ();
106
+ user = userDao .GetAuthorizedUser (sessionId );
107
+ session = sessionId ;
108
+ return user != null ;
111
109
}
112
110
}
0 commit comments