11/*
2- * To change this license header, choose License Headers in Project Properties.
3- * To change this template file, choose Tools | Templates
4- * and open the template in the editor.
2+ * Copyright (c) 2019 Parallax Inc.
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5+ * and associated documentation files (the “Software”), to deal in the Software without
6+ * restriction, including without limitation the rights to use, copy, modify, merge, publish,
7+ * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
8+ * Software is furnished to do so, subject to the following conditions:
9+ *
10+ * The above copyright notice and this permission notice shall be included in all copies or
11+ * substantial portions of the Software.
12+ *
13+ * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+ * SOFTWARE.
520 */
21+
622package com .parallax .server .blocklyprop .servlets ;
723
824import com .google .common .base .Strings ;
1228import com .parallax .client .cloudsession .exceptions .EmailNotConfirmedException ;
1329import com .parallax .client .cloudsession .exceptions .ServerException ;
1430import com .parallax .client .cloudsession .exceptions .UnknownUserIdException ;
15- import com .parallax .client .cloudsession .exceptions .EmailNotConfirmedException ;
1631import com .parallax .server .blocklyprop .db .generated .tables .pojos .User ;
1732import com .parallax .server .blocklyprop .services .UserService ;
1833import com .parallax .server .blocklyprop .services .impl .SecurityServiceImpl ;
@@ -50,7 +65,9 @@ public void setConfiguration(Configuration configuration) {
5065 }
5166
5267 @ Override
53- protected void doGet (HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException {
68+ protected void doGet (HttpServletRequest req , HttpServletResponse resp ) throws
69+ ServletException , IOException {
70+
5471 String idUserString = req .getParameter ("id-user" );
5572 Long idUser = null ;
5673
@@ -61,14 +78,14 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
6178 if (SecurityUtils .getSubject ().isAuthenticated ()) {
6279 idUser = SecurityServiceImpl .getSessionData ().getIdUser ();
6380 } else {
64- LOG .info ("Getting current user while not authenticated" );
81+ LOG .warn ("Getting current user while not authenticated" );
6582 resp .sendError (404 );
6683 }
6784 } else {
6885 idUser = Long .parseLong (idUserString );
6986 }
7087 } catch (NumberFormatException nfe ) {
71- LOG .info ("id-user is not a valid number: {}" , idUserString );
88+ LOG .warn ("id-user is not a valid number: {}" , idUserString );
7289 resp .sendError (500 );
7390 }
7491 try {
@@ -77,27 +94,39 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
7794 if (user == null ) {
7895 LOG .info ("Get public profile for user {} (Does not exist!)" , idUser );
7996 resp .sendError (404 );
80- return ;
8197 }
8298
83- LOG .info ("Get public profile for user {}: Cloud-session user: {}" , idUser , user .getIdcloudsession ());
84-
8599 com .parallax .client .cloudsession .objects .User cloudSessionUser =
86100 cloudSessionUserService .getUser (user .getIdcloudsession ());
87101
102+ // It is possible to receive an empty, non-null object
103+ if (cloudSessionUser == null ) {
104+ LOG .warn ("User object is null" );
105+ resp .sendError (404 , "User profile is unavailable" );
106+ }
107+ if (cloudSessionUser .getScreenname () == null ) {
108+ LOG .warn ("Unable to decode result from Cloud Session call" );
109+ resp .sendError (404 , "User object is empty" );
110+ }
111+
88112 req .setAttribute ("screenname" , cloudSessionUser .getScreenname ());
89113 req .getRequestDispatcher ("/WEB-INF/servlet/public-profile.jsp" ).forward (req , resp );
90- } catch (EmailNotConfirmedException ex ) {
91- LOG .info ("User not known in cloud-session" );
114+ }
115+ catch (EmailNotConfirmedException ex ) {
116+ LOG .info ("User email is unconfirmed cloud-session" );
92117 resp .sendError (404 );
93- } catch (UnknownUserIdException ex ) {
118+ }
119+ catch (UnknownUserIdException ex ) {
94120 LOG .info ("User not known in cloud-session" );
95121 resp .sendError (404 );
96- } catch (ServerException ex ) {
122+ }
123+ catch (NullPointerException ex ) {
124+ LOG .warn ("Unexpected Null Pointer Exception encountered. Message is: {}" , ex .getMessage ());
125+ resp .sendError (404 , "NPE error. User not found" );
126+ }
127+ catch (ServerException ex ) {
97128 LOG .error ("Communication problem with Cloud-session" , ex );
98129 resp .sendError (500 );
99130 }
100-
101131 }
102-
103132}
0 commit comments