Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/650#discussion_r36737719
  
    --- Diff: 
plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
 ---
    @@ -322,21 +306,11 @@ public String authenticate(final String command, 
final Map<String, Object[]> par
                             if (_apiServer.verifyUser(userAccount.getId())) {
                                 LoginCmdResponse loginResponse = 
(LoginCmdResponse) _apiServer.loginUser(session, userAccount.getUsername(), 
userAccount.getUsername() + userAccount.getSource().toString(),
                                         userAccount.getDomainId(), null, 
remoteAddress, params);
    -                            resp.addCookie(new Cookie("userid", 
URLEncoder.encode(loginResponse.getUserId(), HttpUtils.UTF_8)));
    -                            resp.addCookie(new Cookie("domainid", 
URLEncoder.encode(loginResponse.getDomainId(), HttpUtils.UTF_8)));
    -                            resp.addCookie(new Cookie("role", 
URLEncoder.encode(loginResponse.getType(), HttpUtils.UTF_8)));
    -                            resp.addCookie(new Cookie("username", 
URLEncoder.encode(loginResponse.getUsername(), HttpUtils.UTF_8)));
    -                            resp.addCookie(new Cookie("account", 
URLEncoder.encode(loginResponse.getAccount(), HttpUtils.UTF_8)));
    -                            String timezone = loginResponse.getTimeZone();
    -                            if (timezone != null) {
    -                                resp.addCookie(new Cookie("timezone", 
URLEncoder.encode(timezone, HttpUtils.UTF_8)));
    -                            }
    -                            resp.addCookie(new Cookie("userfullname", 
URLEncoder.encode(loginResponse.getFirstName() + " " + 
loginResponse.getLastName(), HttpUtils.UTF_8).replace("+", "%20")));
    -                            resp.addHeader("SET-COOKIE", 
String.format("%s=%s;HttpOnly", ApiConstants.SESSIONKEY, 
loginResponse.getSessionKey()));
    +                            SAMLUtils.setupSamlUserCookies(loginResponse, 
resp);
                                 
resp.sendRedirect(SAML2AuthManager.SAMLCloudStackRedirectionUrl.value());
                                 return 
ApiResponseSerializer.toSerializedString(loginResponse, responseType);
                             }
    -                    } catch (final CloudAuthenticationException ignored) {
    +                    } catch (final Exception ignored) {
    --- End diff --
    
    Java7 supports multi-catch[1] to avoid boilerplate error handling logic.  
However, some code duplication would be preferable to an overly broad catch 
that swallows errors.  
    
    Personally, I think all ignored exceptions should be logged to WARN.  Many 
times, a pattern of ignored exceptions is a symptom of pending and current 
systemic issue.  Having the information in the log as warning helps operators 
detect these types of errors and often avoid larger issues.
    
    [1]: 
https://docs.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html
 
<https://docs.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html>
    > On Aug 11, 2015, at 1:26 AM, Rohit Yadav <notificati...@github.com> wrote:
    > 
    > In 
plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
 <https://github.com/apache/cloudstack/pull/650#discussion_r36712694>:
    > 
    > >                              
resp.sendRedirect(SAML2AuthManager.SAMLCloudStackRedirectionUrl.value());
    > >                              return 
ApiResponseSerializer.toSerializedString(loginResponse, responseType);
    > >                          }
    > > -                    } catch (final CloudAuthenticationException 
ignored) {
    > > +                    } catch (final Exception ignored) {
    > @jburwell <https://github.com/jburwell> @DaanHoogland 
<https://github.com/DaanHoogland> catching pokemons allows to reduce redundant 
error handling code, in case of any auth or IO exception (as the plugin is 
conversing with the IDP server) an API authentication error is thrown at the 
bottom; not sure what could be the best way of handling this without 
duplicating code
    > 
    > —
    > Reply to this email directly or view it on GitHub 
<https://github.com/apache/cloudstack/pull/650/files#r36712694>.
    > 
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to