66import io .quarkus .security .identity .SecurityIdentity ;
77import io .smallrye .common .annotation .Blocking ;
88import jakarta .inject .Inject ;
9+ import jakarta .inject .Named ;
910import jakarta .validation .Validator ;
1011import jakarta .ws .rs .*;
1112import jakarta .ws .rs .core .Context ;
1819import no .java .submit .service .ConferenceService ;
1920import no .java .submit .service .TalksService ;
2021import no .java .submit .service .TimelineService ;
22+ import no .java .submit .util .SessionSecretHelper ;
2123import no .java .submit .util .UserHelper ;
2224import org .eclipse .microprofile .config .inject .ConfigProperty ;
2325import org .jboss .resteasy .reactive .ClientWebApplicationException ;
26+ import org .jboss .resteasy .reactive .RestResponse ;
2427
2528import java .util .ArrayList ;
2629import java .util .Collections ;
30+ import java .util .List ;
2731import java .util .stream .Collectors ;
2832
2933@ Path ("talk" )
30- @ Authenticated
3134@ Blocking
3235@ Produces (MediaType .TEXT_HTML )
3336public class TalkController {
@@ -44,6 +47,9 @@ public class TalkController {
4447 @ Inject
4548 TimelineService timelineService ;
4649
50+ @ Inject
51+ SessionSecretHelper sessionSecrets ;
52+
4753 @ Inject
4854 Template talk ;
4955
@@ -59,13 +65,19 @@ public class TalkController {
5965 @ Inject
6066 Validator validator ;
6167
68+ @ Inject
69+ @ Named ("app.admins" )
70+ List <String > appAdmins ;
71+
6272 @ GET
73+ @ Authenticated
6374 public TemplateInstance all () {
6475 return all .instance ();
6576 }
6677
6778 @ GET
6879 @ Path ("{sessionId}" )
80+ @ Authenticated
6981 public TemplateInstance view (@ PathParam ("sessionId" ) String sessionId , @ Context SecurityIdentity securityIdentity ) {
7082 var email = UserHelper .getEmail (securityIdentity );
7183
@@ -75,14 +87,47 @@ public TemplateInstance view(@PathParam("sessionId") String sessionId, @Context
7587 if (!session .containsEmail (email ))
7688 throw new NotAuthorizedException ("Not allowed to view this session" );
7789
78- return talk .data ("session" , session );
90+ return talk
91+ .data ("session" , session )
92+ .data ("secret" , null );
93+ } catch (ClientWebApplicationException e ) {
94+ throw new NotAuthorizedException ("Not allowed to view this session" , e );
95+ }
96+ }
97+
98+ @ GET
99+ @ Path ("{sessionId}/{secret}" )
100+ public TemplateInstance view (@ PathParam ("sessionId" ) String sessionId , @ PathParam ("secret" ) String secret ) {
101+ sessionSecrets .validate (sessionId , secret );
102+
103+ try {
104+ var session = talksService .getSession ("" , sessionId );
105+
106+ return talk
107+ .data ("session" , session )
108+ .data ("secret" , secret );
79109 } catch (ClientWebApplicationException e ) {
80110 throw new NotAuthorizedException ("Not allowed to view this session" , e );
81111 }
82112 }
83113
114+ @ GET
115+ @ Path ("{sessionId}/secret" )
116+ @ Authenticated
117+ public RestResponse <?> redirectWithSecret (@ PathParam ("sessionId" ) String sessionId , @ Context SecurityIdentity securityIdentity ) {
118+ var email = UserHelper .getEmail (securityIdentity );
119+
120+ if (!appAdmins .contains (email ))
121+ throw new NotAuthorizedException ("Not admin" );
122+
123+ return RestResponse .seeOther (UriBuilder
124+ .fromUri (String .format ("/talk/%s/%s" , sessionId , sessionSecrets .get (sessionId )))
125+ .build ());
126+ }
127+
84128 @ GET
85129 @ Path ("new" )
130+ @ Authenticated
86131 public TemplateInstance newSession (@ Context SecurityIdentity securityIdentity ) {
87132 if (timelineService .isClosed (UserHelper .hasExtension (securityIdentity )))
88133 return error
@@ -106,6 +151,7 @@ public TemplateInstance newSession(@Context SecurityIdentity securityIdentity) {
106151 @ POST
107152 @ Path ("new" )
108153 @ Consumes (MediaType .APPLICATION_FORM_URLENCODED )
154+ @ Authenticated
109155 public Object newSessionPost (SessionForm form , @ Context SecurityIdentity securityIdentity ) {
110156 if (timelineService .isClosed (UserHelper .hasExtension (securityIdentity )))
111157 return error
@@ -138,13 +184,26 @@ public Object newSessionPost(SessionForm form, @Context SecurityIdentity securit
138184
139185 @ GET
140186 @ Path ("{sessionId}/edit" )
187+ @ Authenticated
141188 public TemplateInstance editSession (@ PathParam ("sessionId" ) String sessionId , @ Context SecurityIdentity securityIdentity ) {
142189 var email = UserHelper .getEmail (securityIdentity );
143190
191+ return editSession (sessionId , email , null );
192+ }
193+
194+ @ GET
195+ @ Path ("{sessionId}/{secret}/edit" )
196+ public TemplateInstance editSession (@ PathParam ("sessionId" ) String sessionId , @ PathParam ("secret" ) String secret ) {
197+ sessionSecrets .validate (sessionId , secret );
198+
199+ return editSession (sessionId , "" , secret );
200+ }
201+
202+ public TemplateInstance editSession (String sessionId , String email , String secret ) {
144203 try {
145204 var session = talksService .getSession (email , sessionId );
146205
147- if (!session .containsEmail (email ))
206+ if (!email . isEmpty () && ! session .containsEmail (email ))
148207 throw new NotAuthorizedException ("Not allowed to view this session" );
149208
150209 if (!conferenceService .current ().id .equals (session .conferenceId ))
@@ -153,7 +212,8 @@ public TemplateInstance editSession(@PathParam("sessionId") String sessionId, @C
153212 return sessionForm
154213 .data ("form" , SessionForm .parse (session ))
155214 .data ("val" , Collections .emptyMap ())
156- .data ("sessionId" , sessionId );
215+ .data ("sessionId" , sessionId )
216+ .data ("secret" , secret );
157217 } catch (ClientWebApplicationException e ) {
158218 throw new NotAuthorizedException ("Not allowed to view this session" , e );
159219 }
@@ -162,6 +222,7 @@ public TemplateInstance editSession(@PathParam("sessionId") String sessionId, @C
162222 @ POST
163223 @ Path ("{sessionId}/edit" )
164224 @ Consumes (MediaType .APPLICATION_FORM_URLENCODED )
225+ @ Authenticated
165226 public Object editSessionPost (@ PathParam ("sessionId" ) String sessionId , SessionForm form , @ Context SecurityIdentity securityIdentity ) {
166227 // Validate form and present form if there are any errors
167228 var validation = validator .validate (form );
0 commit comments