fineract-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nazeer1100126 <...@git.apache.org>
Subject [GitHub] fineract pull request #374: Two-Factor Authentication
Date Thu, 17 Aug 2017 14:02:50 GMT
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/fineract/pull/374#discussion_r133721774
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/service/TwoFactorServiceImpl.java
---
    @@ -0,0 +1,221 @@
    +/**
    + * 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 java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.List;
    +
    +import org.apache.commons.lang.StringUtils;
    +import org.apache.fineract.infrastructure.core.api.JsonCommand;
    +import org.apache.fineract.infrastructure.core.domain.EmailDetail;
    +import org.apache.fineract.infrastructure.core.service.PlatformEmailService;
    +import org.apache.fineract.infrastructure.security.constants.TwoFactorConstants;
    +import org.apache.fineract.infrastructure.security.data.OTPDeliveryMethod;
    +import org.apache.fineract.infrastructure.security.data.OTPRequest;
    +import org.apache.fineract.infrastructure.security.domain.OTPRequestRepository;
    +import org.apache.fineract.infrastructure.security.domain.TFAccessToken;
    +import org.apache.fineract.infrastructure.security.domain.TFAccessTokenRepository;
    +import org.apache.fineract.infrastructure.security.exception.AccessTokenInvalidIException;
    +import org.apache.fineract.infrastructure.security.exception.OTPDeliveryMethodInvalidException;
    +import org.apache.fineract.infrastructure.security.exception.OTPTokenInvalidException;
    +import org.apache.fineract.infrastructure.sms.domain.SmsMessage;
    +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.cache.annotation.Cacheable;
    +import org.springframework.context.annotation.Profile;
    +import org.springframework.stereotype.Service;
    +
    +@Service
    +@Profile("twofactor")
    +public class TwoFactorServiceImpl implements TwoFactorService {
    +
    +
    +
    +    private final AccessTokenGenerationService accessTokenGenerationService;
    +    private final PlatformEmailService emailService;
    +    private final SmsMessageScheduledJobService smsMessageScheduledJobService;
    +
    +    private final OTPRequestRepository otpRequestRepository;
    +    private final TFAccessTokenRepository tfAccessTokenRepository;
    +    private final SmsMessageRepository smsMessageRepository;
    +
    +    private final TwoFactorConfigurationService configurationService;
    +
    +    @Autowired
    +    public TwoFactorServiceImpl(AccessTokenGenerationService accessTokenGenerationService,
    +            PlatformEmailService emailService,
    +            SmsMessageScheduledJobService smsMessageScheduledJobService,
    +            OTPRequestRepository otpRequestRepository,
    +            TFAccessTokenRepository tfAccessTokenRepository,
    +            SmsMessageRepository smsMessageRepository,
    +            TwoFactorConfigurationService configurationService) {
    +        this.accessTokenGenerationService = accessTokenGenerationService;
    +        this.emailService = emailService;
    +        this.smsMessageScheduledJobService = smsMessageScheduledJobService;
    +        this.otpRequestRepository = otpRequestRepository;
    +        this.tfAccessTokenRepository = tfAccessTokenRepository;
    +        this.smsMessageRepository = smsMessageRepository;
    +        this.configurationService = configurationService;
    +    }
    +
    +
    +    @Override
    +    public List<OTPDeliveryMethod> getDeliveryMethodsForUser(final AppUser user)
{
    +        List<OTPDeliveryMethod> deliveryMethods = new ArrayList<>();
    +
    +        OTPDeliveryMethod smsMethod = getSMSDeliveryMethodForUser(user);
    +        if(smsMethod != null) {
    +            deliveryMethods.add(smsMethod);
    +        }
    +        OTPDeliveryMethod emailDelivery = getEmailDeliveryMethodForUser(user);
    +        if(emailDelivery != null) {
    +            deliveryMethods.add(emailDelivery);
    +        }
    +
    +        return deliveryMethods;
    +    }
    +
    +    @Override
    +    public OTPRequest createNewOTPToken(final AppUser user, final String deliveryMethodName,
    +                                        final boolean extendedAccessToken) {
    +        if(TwoFactorConstants.SMS_DELIVERY_METHOD_NAME.equalsIgnoreCase(deliveryMethodName))
{
    +            OTPDeliveryMethod smsDelivery = getSMSDeliveryMethodForUser(user);
    +            if(smsDelivery == null) {
    +                throw new OTPDeliveryMethodInvalidException();
    +            }
    +            final OTPRequest request = generateNewToken(smsDelivery, extendedAccessToken);
    +            final String smsText = configurationService.getFormattedSmsTextFor(user,
request);
    +            SmsMessage smsMessage = SmsMessage.pendingSms(null, null, null, user.getStaff(),
smsText,
    +                    user.getStaff().mobileNo(), null);
    +            this.smsMessageRepository.save(smsMessage);
    +            smsMessageScheduledJobService.sendTriggeredMessage(Collections.singleton(smsMessage),
    +                    configurationService.getSMSProviderId());
    +            otpRequestRepository.addOTPRequest(user, request);
    +            return request;
    +        } else if(TwoFactorConstants.EMAIL_DELIVERY_METHOD_NAME.equalsIgnoreCase(deliveryMethodName))
{
    +            OTPDeliveryMethod emailDelivery = getEmailDeliveryMethodForUser(user);
    +            if(emailDelivery == null) {
    +                throw new OTPDeliveryMethodInvalidException();
    +            }
    +            final OTPRequest request = generateNewToken(emailDelivery, extendedAccessToken);
    +            final String emailSubject = configurationService.getFormattedEmailSubjectFor(user,
request);
    +            final String emailBody = configurationService.getFormattedEmailBodyFor(user,
request);
    +            final EmailDetail emailData = new EmailDetail(emailSubject, emailBody, user.getEmail(),
    +                    user.getFirstname() + " " + user.getLastname());
    +            emailService.sendDefinedEmail(emailData);
    +            otpRequestRepository.addOTPRequest(user, request);
    +            return request;
    +        } else {
    --- End diff --
    
    unnecessary else block.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message