Skip to content

Commit

Permalink
changes to get to the PageAttributeVerification
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Dec 23, 2022
1 parent d8a8307 commit 8e4e3d9
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import java.util.List;

@PageDescriptor(urls = {
@Url(mountUrl = "/verification/attributes", matchUrlForSecurity = "/verification/attributes")
@Url(mountUrl = "/attributeVerification", matchUrlForSecurity = "/attributeVerification")
}, permitAll = true, loginPage = true, authModule = AuthenticationModuleNameConstants.ATTRIBUTE_VERIFICATION)
public class PageAttributeVerification extends PageAuthenticationBase {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -177,20 +177,6 @@ private void updateAttributeValue(ItemPathType path, String value) {
}

private void initButtons(MidpointForm form) {

AjaxButton back = new AjaxButton(ID_BACK_BUTTON) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
userModel.detach();
attributesPathModel.detach();
target.add();
}
};
form.add(back);

AjaxSubmitButton submit = new AjaxSubmitButton(ID_SUBMIT_BUTTON, createStringResource("PageAttributeVerification.verifyAttributeButton")) {

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,7 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="attributeVerification" type="tns:AttributeVerificationCredentialsType" minOccurs="0" />
<!-- More credential types may be here, such as OTP seeds, X.509 credentials, etc. -->
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long"/>
Expand Down Expand Up @@ -2466,6 +2467,18 @@
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="AttributeVerificationCredentialsType">
<xsd:annotation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:AbstractCredentialType">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="SecurityQuestionAnswerType">
<xsd:annotation>
<xsd:documentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,7 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="attributeVerification" type="tns:AttributeVerificationCredentialsPolicyType" minOccurs="0" />
<!-- More credential types may come here in the future. -->
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long"/>
Expand Down Expand Up @@ -2557,6 +2558,13 @@
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="AttributeVerificationCredentialsPolicyType">
<xsd:complexContent>
<xsd:extension base="tns:CredentialPolicyType">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="SecurityQuestionDefinitionType">
<xsd:annotation>
<xsd:documentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ protected boolean supportsAuthzCheck() {
}

@Override
protected SecurityQuestionsCredentialsType getCredential(CredentialsType credentials) {
return credentials.getSecurityQuestions();
protected AttributeVerificationCredentialsType getCredential(CredentialsType credentials) {
return credentials.getAttributeVerification();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.authentication.impl.filter;

import com.evolveum.midpoint.authentication.api.util.AuthConstants;
import com.evolveum.midpoint.authentication.impl.module.authentication.token.AttributeVerificationToken;
import com.evolveum.midpoint.authentication.impl.util.AuthSequenceUtil;

import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

public class AttributeVerificationAuthenticationFilter extends MidpointUsernamePasswordAuthenticationFilter {

private static final String SPRING_SECURITY_FORM_ANSWER_KEY = "answer";
private static final String SPRING_SECURITY_FORM_USER_KEY = "user";

public Authentication attemptAuthentication(
HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
if (isPostOnly() && !request.getMethod().equals("POST")) {
throw new AuthenticationServiceException(
"Authentication method not supported: " + request.getMethod());
}

setUsernameParameter(SPRING_SECURITY_FORM_USER_KEY);
String username = obtainUsername(request);
if (username == null) {
username = "";
}

username = username.trim();

UsernamePasswordAuthenticationToken authRequest =
new AttributeVerificationToken(username, null);

return this.getAuthenticationManager().authenticate(authRequest);
}

protected Map<String, String> obtainAnswers(HttpServletRequest request) {
String answers = request.getParameter(SPRING_SECURITY_FORM_ANSWER_KEY);

return AuthSequenceUtil.obtainAnswers(answers, AuthConstants.SEC_QUESTION_J_QID, AuthConstants.SEC_QUESTION_J_QANS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.evolveum.midpoint.authentication.api.util.AuthUtil;
import com.evolveum.midpoint.authentication.impl.entry.point.WicketLoginUrlAuthenticationEntryPoint;
import com.evolveum.midpoint.authentication.impl.filter.SecurityQuestionsAuthenticationFilter;
import com.evolveum.midpoint.authentication.impl.filter.AttributeVerificationAuthenticationFilter;
import com.evolveum.midpoint.authentication.impl.filter.configurers.MidpointExceptionHandlingConfigurer;
import com.evolveum.midpoint.authentication.impl.filter.configurers.MidpointFormLoginConfigurer;
import com.evolveum.midpoint.authentication.impl.handler.MidPointAuthenticationSuccessHandler;
Expand All @@ -27,14 +27,14 @@ public AttributeVerificationModuleWebSecurityConfigurer(C configuration) {
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.antMatcher(AuthUtil.stripEndingSlashes(getPrefix()) + "/**");
getOrApply(http, new MidpointFormLoginConfigurer<>(new SecurityQuestionsAuthenticationFilter()))
.loginPage("/verification/attribute")
getOrApply(http, new MidpointFormLoginConfigurer<>(new AttributeVerificationAuthenticationFilter()))
.loginPage("/attributeVerification")
.loginProcessingUrl(AuthUtil.stripEndingSlashes(getPrefix()) + "/spring_security_login")
.failureHandler(new MidpointAuthenticationFailureHandler())
.successHandler(getObjectPostProcessor().postProcess(
new MidPointAuthenticationSuccessHandler())).permitAll();
getOrApply(http, new MidpointExceptionHandlingConfigurer<>())
.authenticationEntryPoint(new WicketLoginUrlAuthenticationEntryPoint("/verification/attribute"));
.authenticationEntryPoint(new WicketLoginUrlAuthenticationEntryPoint("/attributeVerification"));

http.logout().clearAuthentication(true)
.logoutRequestMatcher(getLogoutMatcher(http, getPrefix() +"/logout"))
Expand Down

0 comments on commit 8e4e3d9

Please sign in to comment.