Search in sources :

Example 1 with Saml2Error

use of org.springframework.security.saml2.core.Saml2Error in project spring-security by spring-projects.

the class OpenSamlAuthenticationProviderTests method authenticateWhenDelegatingToDefaultAssertionValidatorThenUses.

@Test
public void authenticateWhenDelegatingToDefaultAssertionValidatorThenUses() {
    OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
    // @formatter:off
    provider.setAssertionValidator((assertionToken) -> OpenSamlAuthenticationProvider.createDefaultAssertionValidator((token) -> new ValidationContext()).convert(assertionToken).concat(new Saml2Error("wrong error", "wrong error")));
    // @formatter:on
    Response response = response();
    Assertion assertion = assertion();
    OneTimeUse oneTimeUse = build(OneTimeUse.DEFAULT_ELEMENT_NAME);
    assertion.getConditions().getConditions().add(oneTimeUse);
    response.getAssertions().add(assertion);
    TestOpenSamlObjects.signed(response, TestSaml2X509Credentials.assertingPartySigningCredential(), ASSERTING_PARTY_ENTITY_ID);
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    // @formatter:off
    assertThatExceptionOfType(Saml2AuthenticationException.class).isThrownBy(() -> provider.authenticate(token)).isInstanceOf(Saml2AuthenticationException.class).satisfies((error) -> assertThat(error.getSaml2Error().getErrorCode()).isEqualTo(Saml2ErrorCodes.INVALID_ASSERTION));
// @formatter:on
}
Also used : Arrays(java.util.Arrays) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) EncryptedDataBuilder(org.opensaml.xmlsec.encryption.impl.EncryptedDataBuilder) EncryptedID(org.opensaml.saml.saml2.core.EncryptedID) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) BDDMockito.given(org.mockito.BDDMockito.given) Map(java.util.Map) SignatureConstants(org.opensaml.xmlsec.signature.support.SignatureConstants) Marshaller(org.opensaml.core.xml.io.Marshaller) XSDateTimeBuilder(org.opensaml.core.xml.schema.impl.XSDateTimeBuilder) Response(org.opensaml.saml.saml2.core.Response) Saml2ResponseValidatorResult(org.springframework.security.saml2.core.Saml2ResponseValidatorResult) EncryptedAssertionBuilder(org.opensaml.saml.saml2.core.impl.EncryptedAssertionBuilder) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Instant(java.time.Instant) EncryptedIDBuilder(org.opensaml.saml.saml2.core.impl.EncryptedIDBuilder) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) SubjectConfirmationData(org.opensaml.saml.saml2.core.SubjectConfirmationData) Test(org.junit.jupiter.api.Test) List(java.util.List) XSDateTime(org.opensaml.core.xml.schema.XSDateTime) OneTimeUse(org.opensaml.saml.saml2.core.OneTimeUse) ValidationContext(org.opensaml.saml.common.assertion.ValidationContext) QName(javax.xml.namespace.QName) Authentication(org.springframework.security.core.Authentication) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SubjectConfirmation(org.opensaml.saml.saml2.core.SubjectConfirmation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Duration(org.joda.time.Duration) HashMap(java.util.HashMap) Conditions(org.opensaml.saml.saml2.core.Conditions) LinkedHashMap(java.util.LinkedHashMap) StatusCode(org.opensaml.saml.saml2.core.StatusCode) SerializeSupport(net.shibboleth.utilities.java.support.xml.SerializeSupport) SAML2AssertionValidationParameters(org.opensaml.saml.saml2.assertion.SAML2AssertionValidationParameters) Assertion(org.opensaml.saml.saml2.core.Assertion) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ObjectOutputStream(java.io.ObjectOutputStream) AttributeValue(org.opensaml.saml.saml2.core.AttributeValue) XMLObject(org.opensaml.core.xml.XMLObject) MarshallingException(org.opensaml.core.xml.io.MarshallingException) Converter(org.springframework.core.convert.converter.Converter) Saml2ErrorCodes(org.springframework.security.saml2.core.Saml2ErrorCodes) DateTime(org.joda.time.DateTime) Saml2Error(org.springframework.security.saml2.core.Saml2Error) EncryptedAttribute(org.opensaml.saml.saml2.core.EncryptedAttribute) Saml2Exception(org.springframework.security.saml2.Saml2Exception) IOException(java.io.IOException) TestSaml2X509Credentials(org.springframework.security.saml2.core.TestSaml2X509Credentials) XMLObjectProviderRegistrySupport(org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport) NameIDBuilder(org.opensaml.saml.saml2.core.impl.NameIDBuilder) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Element(org.w3c.dom.Element) ResponseToken(org.springframework.security.saml2.provider.service.authentication.OpenSamlAuthenticationProvider.ResponseToken) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Collections(java.util.Collections) TestRelyingPartyRegistrations(org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations) NameID(org.opensaml.saml.saml2.core.NameID) StringUtils(org.springframework.util.StringUtils) Saml2Error(org.springframework.security.saml2.core.Saml2Error) Response(org.opensaml.saml.saml2.core.Response) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) OneTimeUse(org.opensaml.saml.saml2.core.OneTimeUse) ValidationContext(org.opensaml.saml.common.assertion.ValidationContext) Test(org.junit.jupiter.api.Test)

Example 2 with Saml2Error

use of org.springframework.security.saml2.core.Saml2Error in project spring-security by spring-projects.

the class OpenSaml4AuthenticationProvider method process.

private void process(Saml2AuthenticationToken token, Response response) {
    String issuer = response.getIssuer().getValue();
    this.logger.debug(LogMessage.format("Processing SAML response from %s", issuer));
    boolean responseSigned = response.isSigned();
    ResponseToken responseToken = new ResponseToken(response, token);
    Saml2ResponseValidatorResult result = this.responseSignatureValidator.convert(responseToken);
    if (responseSigned) {
        this.responseElementsDecrypter.accept(responseToken);
    } else if (!response.getEncryptedAssertions().isEmpty()) {
        result = result.concat(new Saml2Error(Saml2ErrorCodes.INVALID_SIGNATURE, "Did not decrypt response [" + response.getID() + "] since it is not signed"));
    }
    result = result.concat(this.responseValidator.convert(responseToken));
    boolean allAssertionsSigned = true;
    for (Assertion assertion : response.getAssertions()) {
        AssertionToken assertionToken = new AssertionToken(assertion, token);
        result = result.concat(this.assertionSignatureValidator.convert(assertionToken));
        allAssertionsSigned = allAssertionsSigned && assertion.isSigned();
        if (responseSigned || assertion.isSigned()) {
            this.assertionElementsDecrypter.accept(new AssertionToken(assertion, token));
        }
        result = result.concat(this.assertionValidator.convert(assertionToken));
    }
    if (!responseSigned && !allAssertionsSigned) {
        String description = "Either the response or one of the assertions is unsigned. " + "Please either sign the response or all of the assertions.";
        result = result.concat(new Saml2Error(Saml2ErrorCodes.INVALID_SIGNATURE, description));
    }
    Assertion firstAssertion = CollectionUtils.firstElement(response.getAssertions());
    if (firstAssertion != null && !hasName(firstAssertion)) {
        Saml2Error error = new Saml2Error(Saml2ErrorCodes.SUBJECT_NOT_FOUND, "Assertion [" + firstAssertion.getID() + "] is missing a subject");
        result = result.concat(error);
    }
    if (result.hasErrors()) {
        Collection<Saml2Error> errors = result.getErrors();
        if (this.logger.isTraceEnabled()) {
            this.logger.debug("Found " + errors.size() + " validation errors in SAML response [" + response.getID() + "]: " + errors);
        } else if (this.logger.isDebugEnabled()) {
            this.logger.debug("Found " + errors.size() + " validation errors in SAML response [" + response.getID() + "]");
        }
        Saml2Error first = errors.iterator().next();
        throw createAuthenticationException(first.getErrorCode(), first.getDescription(), null);
    } else {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Successfully processed SAML Response [" + response.getID() + "]");
        }
    }
}
Also used : Saml2Error(org.springframework.security.saml2.core.Saml2Error) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) XSString(org.opensaml.core.xml.schema.XSString) Saml2ResponseValidatorResult(org.springframework.security.saml2.core.Saml2ResponseValidatorResult)

Example 3 with Saml2Error

use of org.springframework.security.saml2.core.Saml2Error in project spring-security by spring-projects.

the class Saml2LogoutResponseFilter method doFilterInternal.

/**
 * {@inheritDoc}
 */
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
    if (!this.logoutRequestMatcher.matches(request)) {
        chain.doFilter(request, response);
        return;
    }
    if (request.getParameter(Saml2ParameterNames.SAML_RESPONSE) == null) {
        chain.doFilter(request, response);
        return;
    }
    Saml2LogoutRequest logoutRequest = this.logoutRequestRepository.removeLogoutRequest(request, response);
    if (logoutRequest == null) {
        this.logger.trace("Did not process logout response since could not find associated LogoutRequest");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Failed to find associated LogoutRequest");
        return;
    }
    RelyingPartyRegistration registration = this.relyingPartyRegistrationResolver.resolve(request, logoutRequest.getRelyingPartyRegistrationId());
    if (registration == null) {
        this.logger.trace("Did not process logout request since failed to find associated RelyingPartyRegistration");
        Saml2Error error = new Saml2Error(Saml2ErrorCodes.RELYING_PARTY_REGISTRATION_NOT_FOUND, "Failed to find associated RelyingPartyRegistration");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, error.toString());
        return;
    }
    if (registration.getSingleLogoutServiceResponseLocation() == null) {
        this.logger.trace("Did not process logout response since RelyingPartyRegistration has not been configured with a logout response endpoint");
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }
    if (!isCorrectBinding(request, registration)) {
        this.logger.trace("Did not process logout request since used incorrect binding");
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }
    String serialized = request.getParameter(Saml2ParameterNames.SAML_RESPONSE);
    Saml2LogoutResponse logoutResponse = Saml2LogoutResponse.withRelyingPartyRegistration(registration).samlResponse(serialized).relayState(request.getParameter(Saml2ParameterNames.RELAY_STATE)).binding(registration.getSingleLogoutServiceBinding()).location(registration.getSingleLogoutServiceResponseLocation()).parameters((params) -> params.put(Saml2ParameterNames.SIG_ALG, request.getParameter(Saml2ParameterNames.SIG_ALG))).parameters((params) -> params.put(Saml2ParameterNames.SIGNATURE, request.getParameter(Saml2ParameterNames.SIGNATURE))).build();
    Saml2LogoutResponseValidatorParameters parameters = new Saml2LogoutResponseValidatorParameters(logoutResponse, logoutRequest, registration);
    Saml2LogoutValidatorResult result = this.logoutResponseValidator.validate(parameters);
    if (result.hasErrors()) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, result.getErrors().iterator().next().toString());
        this.logger.debug(LogMessage.format("Failed to validate LogoutResponse: %s", result.getErrors()));
        return;
    }
    this.logoutSuccessHandler.onLogoutSuccess(request, response, null);
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Saml2Error(org.springframework.security.saml2.core.Saml2Error) Saml2ErrorCodes(org.springframework.security.saml2.core.Saml2ErrorCodes) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) RelyingPartyRegistrationResolver(org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver) FilterChain(jakarta.servlet.FilterChain) Saml2Error(org.springframework.security.saml2.core.Saml2Error) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) Saml2LogoutResponse(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponse) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Saml2LogoutResponseValidatorParameters(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponseValidatorParameters) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Saml2MessageBinding(org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding) LogMessage(org.springframework.core.log.LogMessage) Saml2LogoutValidatorResult(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutValidatorResult) Saml2ParameterNames(org.springframework.security.saml2.core.Saml2ParameterNames) Saml2LogoutResponseValidator(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponseValidator) LogoutSuccessHandler(org.springframework.security.web.authentication.logout.LogoutSuccessHandler) Log(org.apache.commons.logging.Log) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) LogFactory(org.apache.commons.logging.LogFactory) Saml2LogoutRequest(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) Assert(org.springframework.util.Assert) Saml2LogoutValidatorResult(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutValidatorResult) Saml2LogoutResponseValidatorParameters(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponseValidatorParameters) Saml2LogoutRequest(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest) Saml2LogoutResponse(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponse)

Example 4 with Saml2Error

use of org.springframework.security.saml2.core.Saml2Error in project spring-security by spring-projects.

the class OpenSaml4AuthenticationProviderTests method authenticateWhenDelegatingToDefaultAssertionValidatorThenUses.

@Test
public void authenticateWhenDelegatingToDefaultAssertionValidatorThenUses() {
    OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
    // @formatter:off
    provider.setAssertionValidator((assertionToken) -> OpenSaml4AuthenticationProvider.createDefaultAssertionValidator((token) -> new ValidationContext()).convert(assertionToken).concat(new Saml2Error("wrong error", "wrong error")));
    // @formatter:on
    Response response = response();
    Assertion assertion = assertion();
    OneTimeUse oneTimeUse = build(OneTimeUse.DEFAULT_ELEMENT_NAME);
    assertion.getConditions().getConditions().add(oneTimeUse);
    response.getAssertions().add(assertion);
    TestOpenSamlObjects.signed(response, TestSaml2X509Credentials.assertingPartySigningCredential(), ASSERTING_PARTY_ENTITY_ID);
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    // @formatter:off
    assertThatExceptionOfType(Saml2AuthenticationException.class).isThrownBy(() -> provider.authenticate(token)).isInstanceOf(Saml2AuthenticationException.class).satisfies((error) -> assertThat(error.getSaml2Error().getErrorCode()).isEqualTo(Saml2ErrorCodes.INVALID_ASSERTION));
// @formatter:on
}
Also used : Arrays(java.util.Arrays) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) EncryptedDataBuilder(org.opensaml.xmlsec.encryption.impl.EncryptedDataBuilder) ResponseToken(org.springframework.security.saml2.provider.service.authentication.OpenSaml4AuthenticationProvider.ResponseToken) EncryptedID(org.opensaml.saml.saml2.core.EncryptedID) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) BDDMockito.given(org.mockito.BDDMockito.given) Duration(java.time.Duration) Map(java.util.Map) SignatureConstants(org.opensaml.xmlsec.signature.support.SignatureConstants) Marshaller(org.opensaml.core.xml.io.Marshaller) XSDateTimeBuilder(org.opensaml.core.xml.schema.impl.XSDateTimeBuilder) Response(org.opensaml.saml.saml2.core.Response) Saml2ResponseValidatorResult(org.springframework.security.saml2.core.Saml2ResponseValidatorResult) EncryptedAssertionBuilder(org.opensaml.saml.saml2.core.impl.EncryptedAssertionBuilder) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Instant(java.time.Instant) EncryptedIDBuilder(org.opensaml.saml.saml2.core.impl.EncryptedIDBuilder) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) SubjectConfirmationData(org.opensaml.saml.saml2.core.SubjectConfirmationData) Test(org.junit.jupiter.api.Test) List(java.util.List) XSDateTime(org.opensaml.core.xml.schema.XSDateTime) OneTimeUse(org.opensaml.saml.saml2.core.OneTimeUse) ValidationContext(org.opensaml.saml.common.assertion.ValidationContext) QName(javax.xml.namespace.QName) Authentication(org.springframework.security.core.Authentication) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SubjectConfirmation(org.opensaml.saml.saml2.core.SubjectConfirmation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HashMap(java.util.HashMap) Conditions(org.opensaml.saml.saml2.core.Conditions) LinkedHashMap(java.util.LinkedHashMap) StatusCode(org.opensaml.saml.saml2.core.StatusCode) SerializeSupport(net.shibboleth.utilities.java.support.xml.SerializeSupport) SAML2AssertionValidationParameters(org.opensaml.saml.saml2.assertion.SAML2AssertionValidationParameters) Assertion(org.opensaml.saml.saml2.core.Assertion) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ObjectOutputStream(java.io.ObjectOutputStream) AttributeValue(org.opensaml.saml.saml2.core.AttributeValue) XMLObject(org.opensaml.core.xml.XMLObject) MarshallingException(org.opensaml.core.xml.io.MarshallingException) Converter(org.springframework.core.convert.converter.Converter) Saml2ErrorCodes(org.springframework.security.saml2.core.Saml2ErrorCodes) CustomOpenSamlObject(org.springframework.security.saml2.provider.service.authentication.TestCustomOpenSamlObjects.CustomOpenSamlObject) Saml2Error(org.springframework.security.saml2.core.Saml2Error) EncryptedAttribute(org.opensaml.saml.saml2.core.EncryptedAttribute) Saml2Exception(org.springframework.security.saml2.Saml2Exception) IOException(java.io.IOException) TestSaml2X509Credentials(org.springframework.security.saml2.core.TestSaml2X509Credentials) XMLObjectProviderRegistrySupport(org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport) NameIDBuilder(org.opensaml.saml.saml2.core.impl.NameIDBuilder) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Element(org.w3c.dom.Element) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Collections(java.util.Collections) TestRelyingPartyRegistrations(org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations) NameID(org.opensaml.saml.saml2.core.NameID) StringUtils(org.springframework.util.StringUtils) Saml2Error(org.springframework.security.saml2.core.Saml2Error) Response(org.opensaml.saml.saml2.core.Response) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) OneTimeUse(org.opensaml.saml.saml2.core.OneTimeUse) ValidationContext(org.opensaml.saml.common.assertion.ValidationContext) Test(org.junit.jupiter.api.Test)

Example 5 with Saml2Error

use of org.springframework.security.saml2.core.Saml2Error in project spring-security by spring-projects.

the class Saml2AuthenticationTokenConverter method samlInflate.

private String samlInflate(byte[] b) {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(out, new Inflater(true));
        inflaterOutputStream.write(b);
        inflaterOutputStream.finish();
        return out.toString(StandardCharsets.UTF_8.name());
    } catch (Exception ex) {
        throw new Saml2AuthenticationException(new Saml2Error(Saml2ErrorCodes.INVALID_RESPONSE, "Unable to inflate string"), ex);
    }
}
Also used : Saml2Error(org.springframework.security.saml2.core.Saml2Error) Saml2AuthenticationException(org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationException) InflaterOutputStream(java.util.zip.InflaterOutputStream) Inflater(java.util.zip.Inflater) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Saml2AuthenticationException(org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationException)

Aggregations

Saml2Error (org.springframework.security.saml2.core.Saml2Error)9 Authentication (org.springframework.security.core.Authentication)5 RelyingPartyRegistration (org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration)5 Test (org.junit.jupiter.api.Test)4 Assertion (org.opensaml.saml.saml2.core.Assertion)4 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)4 Saml2ResponseValidatorResult (org.springframework.security.saml2.core.Saml2ResponseValidatorResult)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 Saml2ErrorCodes (org.springframework.security.saml2.core.Saml2ErrorCodes)3 ObjectOutputStream (java.io.ObjectOutputStream)2 Instant (java.time.Instant)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 QName (javax.xml.namespace.QName)2