-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from privacyidea/21-feature-send-empty-pass
21 feature send empty pass
- Loading branch information
Showing
8 changed files
with
213 additions
and
109 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
111 changes: 111 additions & 0 deletions
111
privacyIDEA-impl/src/main/java/org/privacyidea/action/AlternativeAuthenticationFlows.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,111 @@ | ||
package org.privacyidea.action; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import javax.annotation.Nonnull; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.opensaml.profile.action.ActionSupport; | ||
import org.opensaml.profile.context.ProfileRequestContext; | ||
import org.privacyidea.PIResponse; | ||
import org.privacyidea.context.PIContext; | ||
import org.privacyidea.context.PIServerConfigContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class AlternativeAuthenticationFlows extends AbstractChallengeResponseAction | ||
{ | ||
private static final Logger LOGGER = LoggerFactory.getLogger(AlternativeAuthenticationFlows.class); | ||
|
||
public AlternativeAuthenticationFlows() {} | ||
|
||
@Override | ||
protected final void doExecute(@Nonnull ProfileRequestContext profileRequestContext, @Nonnull PIContext piContext, @Nonnull PIServerConfigContext piServerConfigContext) | ||
{ | ||
if (piServerConfigContext.getConfigParams().getAuthenticationFlow().equals("triggerChallenge")) | ||
{ | ||
if (debug) | ||
{ | ||
LOGGER.info("{} Authentication flow - triggerChallenge.", this.getLogPrefix()); | ||
} | ||
|
||
HttpServletRequest request = Objects.requireNonNull(this.getHttpServletRequestSupplier()).get(); | ||
Map<String, String> headers = this.getHeadersToForward(request); | ||
PIResponse piResponse = privacyIDEA.triggerChallenges(piContext.getUsername(), headers); | ||
|
||
if (piResponse != null) | ||
{ | ||
if (piResponse.error != null) | ||
{ | ||
LOGGER.error("{} privacyIDEA server error: {}!", this.getLogPrefix(), piResponse.error.message); | ||
ActionSupport.buildEvent(profileRequestContext, "AuthenticationException"); | ||
return; | ||
} | ||
|
||
if (!piResponse.multichallenge.isEmpty()) | ||
{ | ||
if (debug) | ||
{ | ||
LOGGER.info("{} Extracting the form data from triggered challenges...", this.getLogPrefix()); | ||
} | ||
extractChallengeData(piResponse); | ||
} | ||
} | ||
else | ||
{ | ||
LOGGER.error("{} triggerChallenge failed. Response was null. Fallback to standard procedure.", this.getLogPrefix()); | ||
} | ||
} | ||
else if (piServerConfigContext.getConfigParams().getAuthenticationFlow().equals("sendStaticPass")) | ||
{ | ||
if (debug) | ||
{ | ||
LOGGER.info("{} Authentication flow - sendStaticPass.", this.getLogPrefix()); | ||
} | ||
|
||
if (piServerConfigContext.getConfigParams().getStaticPass() == null) | ||
{ | ||
LOGGER.error("{} Static pass isn't set. Fallback to default authentication flow...", this.getLogPrefix()); | ||
} | ||
else | ||
{ | ||
// Call /validate/check with a static pass from the configuration | ||
// This could already end the authentication if the "passOnNoToken" policy is set. | ||
// Otherwise, it might trigger the challenges. | ||
HttpServletRequest request = Objects.requireNonNull(this.getHttpServletRequestSupplier()).get(); | ||
Map<String, String> headers = this.getHeadersToForward(request); | ||
PIResponse piResponse = privacyIDEA.validateCheck(piContext.getUsername(), piServerConfigContext.getConfigParams().getStaticPass(), headers); | ||
|
||
if (piResponse != null) | ||
{ | ||
if (piResponse.error != null) | ||
{ | ||
LOGGER.error("{} privacyIDEA server error: {}!", this.getLogPrefix(), piResponse.error.message); | ||
ActionSupport.buildEvent(profileRequestContext, "AuthenticationException"); | ||
return; | ||
} | ||
|
||
if (piResponse.value) | ||
{ | ||
if (debug) | ||
{ | ||
LOGGER.info("{} Authentication succeeded!", this.getLogPrefix()); | ||
} | ||
ActionSupport.buildEvent(profileRequestContext, "success"); | ||
} | ||
|
||
if (!piResponse.multichallenge.isEmpty()) | ||
{ | ||
extractChallengeData(piResponse); | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (debug) | ||
{ | ||
LOGGER.info("{} Authentication flow: default.", this.getLogPrefix()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.