/
StandardAuthenticationManagerImpl.java
84 lines (74 loc) · 3.65 KB
/
StandardAuthenticationManagerImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright (C) 2011 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.console.common.server.auth.impl.standard;
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import org.apache.commons.lang3.StringUtils;
import org.bonitasoft.console.common.server.auth.AuthenticationFailedException;
import org.bonitasoft.console.common.server.auth.AuthenticationManager;
import org.bonitasoft.console.common.server.login.HttpServletRequestAccessor;
import org.bonitasoft.console.common.server.login.TenantIdAccessorFactory;
import org.bonitasoft.console.common.server.login.credentials.Credentials;
import org.bonitasoft.console.common.server.utils.TenantsManagementUtils;
/**
* @author Chong Zhao
*/
public class StandardAuthenticationManagerImpl implements AuthenticationManager {
/**
* Logger
*/
private static final Logger LOGGER = Logger.getLogger(StandardAuthenticationManagerImpl.class.getName());
@Override
public String getLoginPageURL(final HttpServletRequestAccessor request, final String redirectURL) throws ServletException {
final StringBuilder url = new StringBuilder();
String context = request.asHttpServletRequest().getContextPath();
final String servletPath = request.asHttpServletRequest().getServletPath();
if (StringUtils.isNotBlank(servletPath) && servletPath.startsWith("/mobile")) {
context += "/mobile";
}
url.append(context).append(AuthenticationManager.LOGIN_PAGE).append("?");
long tenantId = getTenantId(request);
if (tenantId != getDefaultTenantId()) {
url.append(AuthenticationManager.TENANT).append("=").append(tenantId).append("&");
}
url.append(AuthenticationManager.REDIRECT_URL).append("=").append(redirectURL);
return url.toString();
}
private long getTenantId(HttpServletRequestAccessor request) throws ServletException {
return TenantIdAccessorFactory.getTenantIdAccessor(request).getTenantIdFromRequestOrCookie();
}
/**
* protected for test purpose
*/
protected long getDefaultTenantId() {
return TenantsManagementUtils.getDefaultTenantId();
}
@Override
public Map<String, Serializable> authenticate(final HttpServletRequestAccessor requestAccessor, final Credentials credentials)
throws AuthenticationFailedException {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "#authenticate (this implementation of " + AuthenticationManager.class.getName()
+ " does nothing. The subsequent engine login is enough to authenticate the user.)");
}
return Collections.emptyMap();
}
@Override
public String getLogoutPageURL(final HttpServletRequestAccessor request, final String redirectURL) throws ServletException {
return null;
}
}