Simplify build for different auth strategies
This commit is contained in:
committed by
Petri Tuomola
parent
c691c11699
commit
907f932abe
+2
-2
@@ -29,10 +29,10 @@ import org.apache.fineract.infrastructure.security.filter.TwoFactorAuthenticatio
|
||||
import org.apache.fineract.infrastructure.security.service.TenantAwareJpaPlatformUserDetailsService;
|
||||
import org.apache.fineract.infrastructure.security.vote.SelfServiceUserAccessVote;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.access.AccessDecisionManager;
|
||||
@@ -59,7 +59,7 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi
|
||||
import org.springframework.security.web.context.SecurityContextPersistenceFilter;
|
||||
|
||||
@Configuration
|
||||
@Profile("oauth")
|
||||
@ConditionalOnProperty("fineract.security.oauth.enabled")
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class OAuth2SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
|
||||
+2
-2
@@ -23,10 +23,10 @@ import org.apache.fineract.infrastructure.security.filter.TenantAwareBasicAuthen
|
||||
import org.apache.fineract.infrastructure.security.filter.TwoFactorAuthenticationFilter;
|
||||
import org.apache.fineract.infrastructure.security.service.TenantAwareJpaPlatformUserDetailsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi
|
||||
import org.springframework.security.web.context.SecurityContextPersistenceFilter;
|
||||
|
||||
@Configuration
|
||||
@Profile("basicauth")
|
||||
@ConditionalOnProperty("fineract.security.basicauth.enabled")
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.fineract.infrastructure.core.config;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SecurityValidationConfig {
|
||||
|
||||
@Value("${fineract.security.basicauth.enabled}")
|
||||
private Boolean basicAuthEnabled;
|
||||
|
||||
@Value("${fineract.security.oauth.enabled}")
|
||||
private Boolean oauthEnabled;
|
||||
|
||||
@PostConstruct
|
||||
public void validate() {
|
||||
// NOTE: avoid NPE if these values are not set
|
||||
if (!Boolean.TRUE.equals(basicAuthEnabled) && !Boolean.TRUE.equals(oauthEnabled)) {
|
||||
// NOTE: while we are already doing consistency checks we might as well cover this case; should not happen
|
||||
// as defaults are set in application.properties
|
||||
throw new IllegalArgumentException(
|
||||
"No authentication scheme selected. Please decide if you want to use basic OR OAuth2 authentication.");
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(basicAuthEnabled) && Boolean.TRUE.equals(oauthEnabled)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Too many authentication schemes selected. Please decide if you want to use basic OR OAuth2 authentication.");
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -44,14 +44,14 @@ import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer
|
||||
import org.apache.fineract.infrastructure.security.constants.TwoFactorConstants;
|
||||
import org.apache.fineract.infrastructure.security.data.AuthenticatedUserData;
|
||||
import org.apache.fineract.infrastructure.security.service.SpringSecurityPlatformSecurityContext;
|
||||
import org.apache.fineract.infrastructure.security.service.TwoFactorUtils;
|
||||
import org.apache.fineract.portfolio.client.service.ClientReadPlatformService;
|
||||
import org.apache.fineract.useradministration.data.RoleData;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.apache.fineract.useradministration.domain.Role;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||
@@ -61,11 +61,14 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
@Profile("basicauth")
|
||||
@ConditionalOnProperty("fineract.security.basicauth.enabled")
|
||||
@Path("/authentication")
|
||||
@Tag(name = "Authentication HTTP Basic", description = "An API capability that allows client applications to verify authentication details using HTTP Basic Authentication.")
|
||||
public class AuthenticationApiResource {
|
||||
|
||||
@Value("${fineract.security.2fa.enabled}")
|
||||
private boolean twoFactorEnabled;
|
||||
|
||||
public static class AuthenticateRequest {
|
||||
|
||||
public String username;
|
||||
@@ -75,19 +78,17 @@ public class AuthenticationApiResource {
|
||||
private final DaoAuthenticationProvider customAuthenticationProvider;
|
||||
private final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService;
|
||||
private final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext;
|
||||
private final TwoFactorUtils twoFactorUtils;
|
||||
private final ClientReadPlatformService clientReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
public AuthenticationApiResource(
|
||||
@Qualifier("customAuthenticationProvider") final DaoAuthenticationProvider customAuthenticationProvider,
|
||||
final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService,
|
||||
final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext, TwoFactorUtils twoFactorUtils,
|
||||
final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext,
|
||||
ClientReadPlatformService aClientReadPlatformService) {
|
||||
this.customAuthenticationProvider = customAuthenticationProvider;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.springSecurityPlatformSecurityContext = springSecurityPlatformSecurityContext;
|
||||
this.twoFactorUtils = twoFactorUtils;
|
||||
clientReadPlatformService = aClientReadPlatformService;
|
||||
}
|
||||
|
||||
@@ -143,7 +144,7 @@ public class AuthenticationApiResource {
|
||||
|
||||
final EnumOptionData organisationalRole = principal.organisationalRoleData();
|
||||
|
||||
boolean isTwoFactorRequired = twoFactorUtils.isTwoFactorAuthEnabled()
|
||||
boolean isTwoFactorRequired = this.twoFactorEnabled
|
||||
&& !principal.hasSpecificPermissionTo(TwoFactorConstants.BYPASS_TWO_FACTOR_PERMISSION);
|
||||
Long userId = principal.getId();
|
||||
if (this.springSecurityPlatformSecurityContext.doesPasswordHasToBeRenewed(principal)) {
|
||||
|
||||
+2
-2
@@ -45,13 +45,13 @@ import org.apache.fineract.infrastructure.security.service.PlatformSecurityConte
|
||||
import org.apache.fineract.infrastructure.security.service.TwoFactorService;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/twofactor")
|
||||
@Component
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
@Scope("singleton")
|
||||
@Tag(name = "Two Factor", description = "")
|
||||
public class TwoFactorApiResource {
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSer
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.infrastructure.security.service.TwoFactorConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.springframework.stereotype.Component;
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
public class TwoFactorConfigurationApiResource {
|
||||
|
||||
private final String resourceNameForPermissions = "TWOFACTOR_CONFIG";
|
||||
|
||||
+10
-11
@@ -37,12 +37,12 @@ import org.apache.fineract.infrastructure.security.constants.TwoFactorConstants;
|
||||
import org.apache.fineract.infrastructure.security.data.AuthenticatedOauthUserData;
|
||||
import org.apache.fineract.infrastructure.security.data.FineractJwtAuthenticationToken;
|
||||
import org.apache.fineract.infrastructure.security.service.SpringSecurityPlatformSecurityContext;
|
||||
import org.apache.fineract.infrastructure.security.service.TwoFactorUtils;
|
||||
import org.apache.fineract.useradministration.data.RoleData;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.apache.fineract.useradministration.domain.Role;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
@@ -54,22 +54,22 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Path("/userdetails")
|
||||
@Component
|
||||
@Profile("oauth")
|
||||
@ConditionalOnProperty("fineract.security.oauth.enabled")
|
||||
@Scope("singleton")
|
||||
|
||||
@Tag(name = "Fetch authenticated user details", description = "")
|
||||
public class UserDetailsApiResource {
|
||||
|
||||
private final ToApiJsonSerializer<AuthenticatedOauthUserData> apiJsonSerializerService;
|
||||
private final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext;
|
||||
private final TwoFactorUtils twoFactorUtils;
|
||||
|
||||
@Value("${fineract.security.2fa.enabled}")
|
||||
private boolean twoFactorEnabled;
|
||||
|
||||
@Autowired
|
||||
public UserDetailsApiResource(final ToApiJsonSerializer<AuthenticatedOauthUserData> apiJsonSerializerService,
|
||||
final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext, final TwoFactorUtils twoFactorUtils) {
|
||||
final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext) {
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.springSecurityPlatformSecurityContext = springSecurityPlatformSecurityContext;
|
||||
this.twoFactorUtils = twoFactorUtils;
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -116,16 +116,15 @@ public class UserDetailsApiResource {
|
||||
|
||||
final EnumOptionData organisationalRole = principal.organisationalRoleData();
|
||||
|
||||
final boolean requireTwoFactorAuth = twoFactorUtils.isTwoFactorAuthEnabled()
|
||||
boolean isTwoFactorRequired = this.twoFactorEnabled
|
||||
&& !principal.hasSpecificPermissionTo(TwoFactorConstants.BYPASS_TWO_FACTOR_PERMISSION);
|
||||
|
||||
if (this.springSecurityPlatformSecurityContext.doesPasswordHasToBeRenewed(principal)) {
|
||||
authenticatedUserData = new AuthenticatedOauthUserData(principal.getUsername(), principal.getId(),
|
||||
authentication.getToken().getTokenValue(), requireTwoFactorAuth);
|
||||
authentication.getToken().getTokenValue(), isTwoFactorRequired);
|
||||
} else {
|
||||
authenticatedUserData = new AuthenticatedOauthUserData(principal.getUsername(), officeId, officeName, staffId, staffDisplayName,
|
||||
organisationalRole, roles, permissions, principal.getId(), authentication.getToken().getTokenValue(),
|
||||
requireTwoFactorAuth);
|
||||
isTwoFactorRequired);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serialize(authenticatedUserData);
|
||||
|
||||
+2
-2
@@ -43,13 +43,13 @@ import org.apache.fineract.infrastructure.security.service.PlatformSecurityConte
|
||||
import org.apache.fineract.infrastructure.security.service.TwoFactorService;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@CommandType(entity = "TWOFACTOR_ACCESSTOKEN", action = "INVALIDATE")
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
public class InvalidateTFAccessTokenCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final TwoFactorService twoFactorService;
|
||||
|
||||
+2
-2
@@ -27,13 +27,13 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuild
|
||||
import org.apache.fineract.infrastructure.security.data.TwoFactorConfigurationValidator;
|
||||
import org.apache.fineract.infrastructure.security.service.TwoFactorConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@CommandType(entity = "TWOFACTOR_CONFIGURATION", action = "UPDATE")
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
public class UpdateTwoFactorConfigCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final TwoFactorConfigurationService configurationService;
|
||||
|
||||
+2
-2
@@ -32,11 +32,11 @@ import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidati
|
||||
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.apache.fineract.infrastructure.security.constants.TwoFactorConfigurationConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
public class TwoFactorConfigurationValidator {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
+2
-2
@@ -21,12 +21,12 @@ package org.apache.fineract.infrastructure.security.domain;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.apache.fineract.infrastructure.security.data.OTPRequest;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@Repository
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
@SuppressWarnings({ "MemberName" })
|
||||
public class OTPRequestRepository {
|
||||
|
||||
|
||||
+2
-2
@@ -19,11 +19,11 @@
|
||||
package org.apache.fineract.infrastructure.security.domain;
|
||||
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
public interface TFAccessTokenRepository extends JpaRepository<TFAccessToken, Long>, JpaSpecificationExecutor<TFAccessToken> {
|
||||
|
||||
TFAccessToken findByUserAndToken(AppUser user, String token);
|
||||
|
||||
+2
-2
@@ -19,11 +19,11 @@
|
||||
package org.apache.fineract.infrastructure.security.domain;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
public interface TwoFactorConfigurationRepository
|
||||
extends JpaRepository<TwoFactorConfiguration, Long>, JpaSpecificationExecutor<TwoFactorConfiguration> {
|
||||
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import org.apache.fineract.infrastructure.security.data.FineractJwtAuthenticationToken;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
@@ -43,7 +43,7 @@ import org.springframework.stereotype.Service;
|
||||
* This filter adds 'TWOFACTOR_AUTHENTICATED' authority to every authenticated platform user.
|
||||
*/
|
||||
@Service
|
||||
@Profile("!twofactor")
|
||||
@ConditionalOnProperty(name = "fineract.security.2fa.enabled", havingValue = "false")
|
||||
public class InsecureTwoFactorAuthenticationFilter extends TwoFactorAuthenticationFilter {
|
||||
|
||||
public InsecureTwoFactorAuthenticationFilter() {
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -59,7 +59,7 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi
|
||||
* If multi-tenant and basic auth credentials are invalid, a http error response is returned.
|
||||
*/
|
||||
|
||||
@Profile("basicauth")
|
||||
@ConditionalOnProperty("fineract.security.basicauth.enabled")
|
||||
public class TenantAwareBasicAuthenticationFilter extends BasicAuthenticationFilter {
|
||||
|
||||
private static boolean firstRequestProcessed = false;
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ import org.apache.fineract.infrastructure.security.service.BasicAuthTenantDetail
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
@@ -55,7 +55,7 @@ import org.springframework.web.filter.GenericFilterBean;
|
||||
* Used to support Oauth2 authentication and the service is loaded only when "oauth" profile is active.
|
||||
*/
|
||||
@Service
|
||||
@Profile("oauth")
|
||||
@ConditionalOnProperty("fineract.security.oauth.enabled")
|
||||
public class TenantAwareTenantIdentifierFilter extends GenericFilterBean {
|
||||
|
||||
private static boolean firstRequestProcessed = false;
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ import org.apache.fineract.infrastructure.security.domain.TFAccessToken;
|
||||
import org.apache.fineract.infrastructure.security.service.TwoFactorService;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
@@ -57,7 +57,7 @@ import org.springframework.web.filter.GenericFilterBean;
|
||||
* authority regardless of the value of the 'Fineract-Platform-TFA-Token' header.
|
||||
*/
|
||||
@Service
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
public class TwoFactorAuthenticationFilter extends GenericFilterBean {
|
||||
|
||||
private final TwoFactorService twoFactorService;
|
||||
|
||||
+2
-2
@@ -36,13 +36,13 @@ import org.apache.fineract.infrastructure.security.domain.TwoFactorConfiguration
|
||||
import org.apache.fineract.infrastructure.security.domain.TwoFactorConfigurationRepository;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
public class TwoFactorConfigurationServiceImpl implements TwoFactorConfigurationService {
|
||||
|
||||
private static final String DEFAULT_EMAIL_SUBJECT = "Fineract Two-Factor Authentication Token";
|
||||
|
||||
+2
-2
@@ -39,14 +39,14 @@ import org.apache.fineract.infrastructure.sms.domain.SmsMessageRepository;
|
||||
import org.apache.fineract.infrastructure.sms.scheduler.SmsMessageScheduledJobService;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Profile("twofactor")
|
||||
@ConditionalOnProperty("fineract.security.2fa.enabled")
|
||||
public class TwoFactorServiceImpl implements TwoFactorService {
|
||||
|
||||
private final AccessTokenGenerationService accessTokenGenerationService;
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.security.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TwoFactorUtils {
|
||||
|
||||
private static final String TWO_FACTOR_PROFILE_NAME = "twofactor";
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
@Autowired
|
||||
public TwoFactorUtils(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public boolean isTwoFactorAuthEnabled() {
|
||||
for (final String profile : this.environment.getActiveProfiles()) {
|
||||
if (TWO_FACTOR_PROFILE_NAME.equals(profile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -31,13 +31,13 @@ import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.infrastructure.security.api.AuthenticationApiResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
@Profile("basicauth")
|
||||
@ConditionalOnProperty("fineract.security.basicauth.enabled")
|
||||
@Path("/self/authentication")
|
||||
@Tag(name = "Self Authentication", description = "Authenticates the credentials provided and returns the set roles and permissions allowed")
|
||||
public class SelfAuthenticationApiResource {
|
||||
|
||||
+2
-2
@@ -30,13 +30,13 @@ import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.infrastructure.security.api.UserDetailsApiResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/self/userdetails")
|
||||
@Component
|
||||
@Profile("oauth")
|
||||
@ConditionalOnProperty("fineract.security.oauth.enabled")
|
||||
@Scope("singleton")
|
||||
|
||||
@Tag(name = "Self User Details", description = "")
|
||||
|
||||
Reference in New Issue
Block a user