View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.pages;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.apache.syncope.client.console.SyncopeConsoleSession;
23  import org.apache.syncope.client.ui.commons.Constants;
24  import org.apache.syncope.client.ui.commons.panels.OIDCC4UIConstants;
25  import org.apache.wicket.authentication.IAuthenticationStrategy;
26  import org.apache.wicket.markup.html.WebPage;
27  import org.apache.wicket.request.mapper.parameter.PageParameters;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  public class OIDCClientLogin extends WebPage {
32  
33      private static final long serialVersionUID = 8581614051773949262L;
34  
35      private static final Logger LOG = LoggerFactory.getLogger(OIDCClientLogin.class);
36  
37      private static final String OIDC_ACCESS_ERROR = "OIDC access error";
38  
39      public OIDCClientLogin(final PageParameters parameters) {
40          super(parameters);
41  
42          String token = parameters.get(OIDCC4UIConstants.OIDCC4UI_JWT).toOptionalString();
43          if (StringUtils.isBlank(token)) {
44              LOG.error("No JWT found, redirecting to default greeter");
45  
46              PageParameters params = new PageParameters();
47              params.add("errorMessage", OIDC_ACCESS_ERROR);
48              setResponsePage(Login.class, params);
49          }
50  
51          IAuthenticationStrategy strategy = getApplication().getSecuritySettings().getAuthenticationStrategy();
52  
53          if (SyncopeConsoleSession.get().authenticate(token)) {
54              if (parameters.get(OIDCC4UIConstants.OIDCC4UI_SLO_SUPPORTED).toBoolean(false)) {
55                  SyncopeConsoleSession.get().setAttribute(Constants.BEFORE_LOGOUT_PAGE, OIDCClientBeforeLogout.class);
56              }
57  
58              // If login has been called because the user was not yet logged in, than continue to the
59              // original destination, otherwise to the Home page
60              continueToOriginalDestination();
61              setResponsePage(getApplication().getHomePage());
62          } else {
63              PageParameters params = new PageParameters();
64              params.add("errorMessage", OIDC_ACCESS_ERROR);
65              setResponsePage(Login.class, params);
66          }
67          strategy.remove();
68      }
69  }