-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES-418] Added password based auth support. (#1132)
Signed-off-by: Mahammed Taheer <[email protected]>
- Loading branch information
1 parent
88e95da
commit 8e265d5
Showing
35 changed files
with
1,078 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...on/src/main/java/io/mosip/authentication/common/service/impl/PasswordAuthServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.mosip.authentication.common.service.impl; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import io.mosip.authentication.common.service.builder.AuthStatusInfoBuilder; | ||
import io.mosip.authentication.common.service.builder.MatchInputBuilder; | ||
import io.mosip.authentication.common.service.config.IDAMappingConfig; | ||
import io.mosip.authentication.common.service.helper.IdInfoHelper; | ||
import io.mosip.authentication.common.service.impl.match.PasswordAuthType; | ||
import io.mosip.authentication.common.service.impl.match.PasswordMatchType; | ||
import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants; | ||
import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; | ||
import io.mosip.authentication.core.indauth.dto.AuthRequestDTO; | ||
import io.mosip.authentication.core.indauth.dto.AuthStatusInfo; | ||
import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO; | ||
import io.mosip.authentication.core.spi.indauth.match.MatchInput; | ||
import io.mosip.authentication.core.spi.indauth.match.MatchOutput; | ||
import io.mosip.authentication.core.spi.indauth.service.PasswordAuthService; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Service | ||
@NoArgsConstructor | ||
public class PasswordAuthServiceImpl implements PasswordAuthService { | ||
|
||
@Autowired | ||
private IdInfoHelper idInfoHelper; | ||
|
||
/** The id info helper. */ | ||
@Autowired | ||
private MatchInputBuilder matchInputBuilder; | ||
|
||
/** The ida mapping config. */ | ||
@Autowired | ||
private IDAMappingConfig idaMappingConfig; | ||
|
||
public AuthStatusInfo authenticate(AuthRequestDTO authRequestDTO,String individualId, | ||
Map<String,List<IdentityInfoDTO>> idInfo,String partnerId) | ||
throws IdAuthenticationBusinessException { | ||
|
||
if (idInfo == null || idInfo.isEmpty()) { | ||
throw new IdAuthenticationBusinessException(IdAuthenticationErrorConstants.SERVER_ERROR); | ||
} | ||
|
||
List<MatchInput> listMatchInputs = constructMatchInput(authRequestDTO, idInfo); | ||
|
||
List<MatchOutput> listMatchOutputs = constructMatchOutput(authRequestDTO, listMatchInputs, idInfo, | ||
partnerId); | ||
// Using AND condition on the match output for Bio auth. | ||
boolean isMatched = !listMatchOutputs.isEmpty() && listMatchOutputs.stream().allMatch(MatchOutput::isMatched); | ||
return AuthStatusInfoBuilder.buildStatusInfo(isMatched, listMatchInputs, listMatchOutputs, | ||
PasswordAuthType.values(), idaMappingConfig); | ||
|
||
} | ||
|
||
public List<MatchInput> constructMatchInput(AuthRequestDTO authRequestDTO, | ||
Map<String, List<IdentityInfoDTO>> idInfo) { | ||
return matchInputBuilder.buildMatchInput(authRequestDTO, PasswordAuthType.values(), PasswordMatchType.values(), | ||
idInfo); | ||
} | ||
|
||
private List<MatchOutput> constructMatchOutput(AuthRequestDTO authRequestDTO, List<MatchInput> listMatchInputs, | ||
Map<String,List<IdentityInfoDTO>> idInfo, String partnerId) | ||
throws IdAuthenticationBusinessException { | ||
return idInfoHelper.matchIdentityData(authRequestDTO, idInfo, listMatchInputs, partnerId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...mon/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordAuthType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.mosip.authentication.common.service.impl.match; | ||
|
||
import io.mosip.authentication.common.service.impl.AuthTypeImpl; | ||
import io.mosip.authentication.core.indauth.dto.AuthRequestDTO; | ||
import io.mosip.authentication.core.indauth.dto.KycAuthRequestDTO; | ||
import io.mosip.authentication.core.spi.indauth.match.AuthType; | ||
import io.mosip.authentication.core.spi.indauth.match.ComparePasswordFunction; | ||
import io.mosip.authentication.core.spi.indauth.match.IdInfoFetcher; | ||
import io.mosip.authentication.core.spi.indauth.match.MatchType; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public enum PasswordAuthType implements AuthType { | ||
|
||
PASSWORD(IdaIdMapping.PASSWORD.getIdname(), AuthType.setOf(PasswordMatchType.PASSWORD), "PASSWORD"); | ||
|
||
private AuthTypeImpl authTypeImpl; | ||
|
||
/** | ||
* Instantiates a new demo auth type. | ||
* | ||
* @param type the type | ||
* @param associatedMatchTypes the associated match types | ||
*/ | ||
private PasswordAuthType(String type, Set<MatchType> associatedMatchTypes, String displayName) { | ||
authTypeImpl = new AuthTypeImpl(type, associatedMatchTypes, displayName); | ||
} | ||
|
||
|
||
@Override | ||
public boolean isAuthTypeInfoAvailable(AuthRequestDTO authRequestDTO) { | ||
if(authRequestDTO instanceof KycAuthRequestDTO) { | ||
KycAuthRequestDTO kycAuthRequestDTO = (KycAuthRequestDTO) authRequestDTO; | ||
return Objects.nonNull(kycAuthRequestDTO.getRequest().getPassword()); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getMatchProperties(AuthRequestDTO authRequestDTO, IdInfoFetcher idInfoFetcher, | ||
String language) { | ||
Map<String, Object> valueMap = new HashMap<>(); | ||
if(isAuthTypeInfoAvailable(authRequestDTO)) { | ||
ComparePasswordFunction func = idInfoFetcher.getMatchPasswordFunction(); | ||
valueMap.put(IdaIdMapping.PASSWORD.getIdname(), func); | ||
} | ||
return valueMap; | ||
} | ||
|
||
@Override | ||
public AuthType getAuthTypeImpl() { | ||
return authTypeImpl; | ||
} | ||
} |
Oops, something went wrong.