use of org.craftercms.studio.api.v2.service.security.AuthenticationProvider in project studio by craftercms.
the class AuthenticationChainImpl method init.
public void init() {
List<HierarchicalConfiguration<ImmutableNode>> chainConfig = studioConfiguration.getSubConfigs(CONFIGURATION_AUTHENTICATION_CHAIN_CONFIG);
authenticationChain = new ArrayList<AuthenticationProvider>();
chainConfig.forEach(providerConfig -> {
AuthenticationProvider provider = AuthenticationProviderFactory.getAuthenticationProvider(providerConfig);
if (provider != null && provider.isEnabled()) {
authenticationChain.add(provider);
}
});
}
use of org.craftercms.studio.api.v2.service.security.AuthenticationProvider in project studio by craftercms.
the class AuthenticationChainImpl method doAuthenticate.
@Override
public boolean doAuthenticate(HttpServletRequest request, HttpServletResponse response, String username, String password) throws Exception {
boolean authenticated = false;
Iterator<AuthenticationProvider> iterator = authenticationChain.iterator();
Exception lastError = null;
while (iterator.hasNext()) {
AuthenticationProvider authProvider = iterator.next();
if (authProvider.isEnabled()) {
try {
authenticated = authProvider.doAuthenticate(request, response, this, username, password);
} catch (Exception e) {
lastError = e;
}
if (authenticated)
break;
}
}
String ipAddress = request.getRemoteAddr();
SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
if (authenticated) {
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_LOGIN);
auditLog.setActorId(username);
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(username);
auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
auditLog.setPrimaryTargetValue(username);
auditServiceInternal.insertAuditLog(auditLog);
logger.info("User " + username + " logged in from IP: " + ipAddress);
} else {
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_LOGIN_FAILED);
auditLog.setActorId(username);
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(StringUtils.isEmpty(username) ? StringUtils.EMPTY : username);
auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
auditLog.setPrimaryTargetValue(username);
auditServiceInternal.insertAuditLog(auditLog);
logger.info("Failed to authenticate user " + username + " logging in from IP: " + ipAddress);
if (lastError == null) {
lastError = new AuthenticationSystemException("Unknown service error");
}
throw lastError;
}
return authenticated;
}
Aggregations