1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.pages;
20
21 import java.security.AccessControlException;
22 import java.util.ArrayList;
23 import java.util.List;
24 import org.apache.syncope.client.console.SyncopeConsoleSession;
25 import org.apache.syncope.client.console.SyncopeWebApplication;
26 import org.apache.syncope.client.ui.commons.BaseLogin;
27 import org.apache.syncope.client.ui.commons.BaseSession;
28 import org.apache.syncope.client.ui.commons.panels.BaseSSOLoginFormPanel;
29 import org.apache.wicket.ajax.AjaxRequestTarget;
30 import org.apache.wicket.authentication.IAuthenticationStrategy;
31 import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
32 import org.apache.wicket.markup.html.panel.Panel;
33 import org.apache.wicket.request.mapper.parameter.PageParameters;
34
35 public class Login extends BaseLogin {
36
37 private static final long serialVersionUID = 5889157642852559004L;
38
39 public Login(final PageParameters parameters) {
40 super(parameters);
41 }
42
43 @Override
44 protected BaseSession getBaseSession() {
45 return SyncopeConsoleSession.get();
46 }
47
48 @Override
49 protected List<Panel> getSSOLoginFormPanels() {
50 List<Panel> ssoLoginFormPanels = new ArrayList<>();
51 SyncopeWebApplication.get().getLookup().getClasses(BaseSSOLoginFormPanel.class).forEach(ssoLoginFormPanel -> {
52 try {
53 ssoLoginFormPanels.add(ssoLoginFormPanel.getConstructor(String.class, BaseSession.class).newInstance(
54 "ssoLogin", SyncopeConsoleSession.get()));
55 } catch (Exception e) {
56 LOG.error("Could not initialize the provided SSO login form panel", e);
57 }
58 });
59 return ssoLoginFormPanels;
60 }
61
62 @Override
63 protected void sendError(final String error) {
64 SyncopeConsoleSession.get().error(error);
65 }
66
67 @Override
68 protected void authenticate(final String username, final String password, final AjaxRequestTarget target)
69 throws AccessControlException {
70
71 if (SyncopeWebApplication.get().getAnonymousUser().equals(username)) {
72 throw new AccessControlException("Illegal username");
73 }
74
75 IAuthenticationStrategy strategy = getApplication().getSecuritySettings().getAuthenticationStrategy();
76
77 if (AuthenticatedWebSession.get().signIn(username, password)) {
78
79
80 continueToOriginalDestination();
81 setResponsePage(getApplication().getHomePage());
82 } else {
83 SyncopeConsoleSession.get().error(getString("login-error"));
84 notificationPanel.refresh(target);
85 }
86 strategy.remove();
87 }
88 }