Search in sources :

Example 16 with NonNull

use of lombok.NonNull in project cas by apereo.

the class SamlProfileSamlSoap11ResponseBuilder method buildResponse.

@Override
protected Envelope buildResponse(final Assertion assertion, final Object casAssertion, final RequestAbstractType authnRequest, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final HttpServletRequest request, final HttpServletResponse response, final String binding) throws SamlException {
    LOGGER.debug("Locating the assertion consumer service url for binding [{}]", binding);
    @NonNull final AssertionConsumerService acs = adaptor.getAssertionConsumerService(binding);
    LOGGER.debug("Located assertion consumer service url [{}]", acs);
    final Response ecpResponse = newEcpResponse(acs.getLocation());
    final Header header = newSoapObject(Header.class);
    header.getUnknownXMLObjects().add(ecpResponse);
    final Body body = newSoapObject(Body.class);
    final org.opensaml.saml.saml2.core.Response saml2Response = buildSaml2Response(casAssertion, authnRequest, service, adaptor, request, binding);
    body.getUnknownXMLObjects().add(saml2Response);
    final Envelope envelope = newSoapObject(Envelope.class);
    envelope.setHeader(header);
    envelope.setBody(body);
    SamlUtils.logSamlObject(this.configBean, envelope);
    return envelope;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.opensaml.saml.saml2.ecp.Response) Header(org.opensaml.soap.soap11.Header) NonNull(lombok.NonNull) AssertionConsumerService(org.opensaml.saml.saml2.metadata.AssertionConsumerService) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Example 17 with NonNull

use of lombok.NonNull in project cas by apereo.

the class SamlProfileSamlSubjectBuilder method buildSubject.

private Subject buildSubject(final HttpServletRequest request, final HttpServletResponse response, final RequestAbstractType authnRequest, final Object casAssertion, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final String binding) throws SamlException {
    final Assertion assertion = Assertion.class.cast(casAssertion);
    final ZonedDateTime validFromDate = ZonedDateTime.ofInstant(assertion.getValidFromDate().toInstant(), ZoneOffset.UTC);
    LOGGER.debug("Locating the assertion consumer service url for binding [{}]", binding);
    @NonNull final AssertionConsumerService acs = adaptor.getAssertionConsumerService(binding);
    final String location = StringUtils.isBlank(acs.getResponseLocation()) ? acs.getLocation() : acs.getResponseLocation();
    if (StringUtils.isBlank(location)) {
        LOGGER.warn("Subject recipient is not defined from either authentication request or metadata for [{}]", adaptor.getEntityId());
    }
    final NameID nameId = getNameIdForService(request, response, authnRequest, service, adaptor, binding, assertion);
    final Subject subject = newSubject(nameId, service.isSkipGeneratingSubjectConfirmationRecipient() ? null : location, service.isSkipGeneratingSubjectConfirmationNotOnOrAfter() ? null : validFromDate.plusSeconds(this.skewAllowance), service.isSkipGeneratingSubjectConfirmationInResponseTo() ? null : authnRequest.getID(), service.isSkipGeneratingSubjectConfirmationNotBefore() ? null : ZonedDateTime.now());
    LOGGER.debug("Created SAML subject [{}]", subject);
    return subject;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) NameID(org.opensaml.saml.saml2.core.NameID) NonNull(lombok.NonNull) Assertion(org.jasig.cas.client.validation.Assertion) AssertionConsumerService(org.opensaml.saml.saml2.metadata.AssertionConsumerService) Subject(org.opensaml.saml.saml2.core.Subject)

Example 18 with NonNull

use of lombok.NonNull in project cas by apereo.

the class GoogleAuthenticatorAuthenticationHandler method doAuthentication.

@Override
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    final GoogleAuthenticatorTokenCredential tokenCredential = (GoogleAuthenticatorTokenCredential) credential;
    if (!StringUtils.isNumeric(tokenCredential.getToken())) {
        throw new PreventedException("Invalid non-numeric OTP format specified.", new IllegalArgumentException("Invalid token " + tokenCredential.getToken()));
    }
    final int otp = Integer.parseInt(tokenCredential.getToken());
    LOGGER.debug("Received OTP [{}]", otp);
    @NonNull final Authentication authentication = WebUtils.getInProgressAuthentication();
    final String uid = authentication.getPrincipal().getId();
    LOGGER.debug("Received principal id [{}]", uid);
    final OneTimeTokenAccount acct = this.credentialRepository.get(uid);
    if (acct == null || StringUtils.isBlank(acct.getSecretKey())) {
        throw new AccountNotFoundException(uid + " cannot be found in the registry");
    }
    if (this.tokenRepository.exists(uid, otp)) {
        throw new AccountExpiredException(uid + " cannot reuse OTP " + otp + " as it may be expired/invalid");
    }
    boolean isCodeValid = this.googleAuthenticatorInstance.authorize(acct.getSecretKey(), otp);
    if (!isCodeValid && acct.getScratchCodes().contains(otp)) {
        LOGGER.warn("Using scratch code [{}] to authenticate user [{}]. Scratch code will be removed", otp, uid);
        acct.getScratchCodes().removeIf(token -> token == otp);
        this.credentialRepository.update(acct);
        isCodeValid = true;
    }
    if (isCodeValid) {
        this.tokenRepository.store(new GoogleAuthenticatorToken(otp, uid));
        return createHandlerResult(tokenCredential, this.principalFactory.createPrincipal(uid));
    }
    throw new FailedLoginException("Failed to authenticate code " + otp);
}
Also used : OneTimeTokenAccount(org.apereo.cas.otp.repository.credentials.OneTimeTokenAccount) FailedLoginException(javax.security.auth.login.FailedLoginException) Authentication(org.apereo.cas.authentication.Authentication) AccountExpiredException(javax.security.auth.login.AccountExpiredException) NonNull(lombok.NonNull) GoogleAuthenticatorToken(org.apereo.cas.adaptors.gauth.token.GoogleAuthenticatorToken) PreventedException(org.apereo.cas.authentication.PreventedException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException)

Example 19 with NonNull

use of lombok.NonNull in project cas by apereo.

the class SSOSamlProfileCallbackHandlerController method determineProfileBinding.

/**
 * Determine profile binding.
 *
 * @param authenticationContext the authentication context
 * @param assertion             the assertion
 * @return the string
 */
protected String determineProfileBinding(final Pair<AuthnRequest, MessageContext> authenticationContext, final Assertion assertion) {
    final AuthnRequest authnRequest = authenticationContext.getKey();
    final Pair<SamlRegisteredService, SamlRegisteredServiceServiceProviderMetadataFacade> pair = getRegisteredServiceAndFacade(authnRequest);
    final SamlRegisteredServiceServiceProviderMetadataFacade facade = pair.getValue();
    final String binding = StringUtils.defaultIfBlank(authnRequest.getProtocolBinding(), SAMLConstants.SAML2_POST_BINDING_URI);
    LOGGER.debug("Determined authentication request binding is [{}], issued by [{}]", binding, authnRequest.getIssuer().getValue());
    LOGGER.debug("Checking metadata for [{}] to see if binding [{}] is supported", facade.getEntityId(), binding);
    @NonNull final AssertionConsumerService svc = facade.getAssertionConsumerService(binding);
    LOGGER.debug("Binding [{}] is supported by [{}]", svc.getBinding(), facade.getEntityId());
    return binding;
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) NonNull(lombok.NonNull) AssertionConsumerService(org.opensaml.saml.saml2.metadata.AssertionConsumerService)

Aggregations

NonNull (lombok.NonNull)19 Lists (com.google.common.collect.Lists)8 QualifiedName (com.netflix.metacat.common.QualifiedName)8 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)8 HiveConnectorInfoConverter (com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter)8 List (java.util.List)8 Nonnull (javax.annotation.Nonnull)8 Inject (javax.inject.Inject)8 Named (javax.inject.Named)8 Pageable (com.netflix.metacat.common.dto.Pageable)7 Sort (com.netflix.metacat.common.dto.Sort)7 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)7 Map (java.util.Map)7 Nullable (javax.annotation.Nullable)7 Strings (com.google.common.base.Strings)6 Maps (com.google.common.collect.Maps)6 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)6 Throwables (com.google.common.base.Throwables)5 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)5 PartitionListRequest (com.netflix.metacat.common.server.connectors.model.PartitionListRequest)5