Search in sources :

Example 1 with SecurityContext

use of org.mule.runtime.api.security.SecurityContext in project mule by mulesoft.

the class MuleEventTestCase method securityContextCopy.

@Test
public void securityContextCopy() throws Exception {
    SecurityContext securityContext = mock(SecurityContext.class);
    CoreEvent event = CoreEvent.builder(testEvent()).securityContext(securityContext).build();
    CoreEvent eventCopy = CoreEvent.builder(event).message(Message.of("copy")).build();
    assertThat(securityContext, sameInstance(eventCopy.getSecurityContext()));
}
Also used : SecurityContext(org.mule.runtime.api.security.SecurityContext) Test(org.junit.Test)

Example 2 with SecurityContext

use of org.mule.runtime.api.security.SecurityContext in project mule by mulesoft.

the class DefaultEventBuilder method securityContext.

@Override
public DefaultEventBuilder securityContext(SecurityContext securityContext) {
    SecurityContext originalValue = this.securityContext;
    this.securityContext = securityContext;
    this.modified = originalValue != securityContext;
    return this;
}
Also used : SecurityContext(org.mule.runtime.api.security.SecurityContext)

Example 3 with SecurityContext

use of org.mule.runtime.api.security.SecurityContext in project mule by mulesoft.

the class UsernamePasswordAuthenticationFilter method authenticate.

/**
 * Authenticates the current message.
 *
 * @param event the current message recieved
 * @throws SecurityException if authentication fails
 */
@Override
public SecurityContext authenticate(CoreEvent event) throws SecurityException, SecurityProviderNotFoundException, UnknownAuthenticationTypeException {
    Authentication authentication = getAuthenticationToken(event);
    Authentication authResult;
    try {
        authResult = getSecurityManager().authenticate(authentication);
    } catch (UnauthorisedException e) {
        // Authentication failed
        if (logger.isDebugEnabled()) {
            logger.debug("Authentication request for user: " + username + " failed: " + e.toString());
        }
        throw new UnauthorisedException(authFailedForUser(authentication.getPrincipal().toString()), e);
    }
    // Authentication success
    if (logger.isDebugEnabled()) {
        logger.debug("Authentication success: " + authResult.toString());
    }
    SecurityContext context = getSecurityManager().createSecurityContext(authResult);
    context.setAuthentication(authResult);
    return context;
}
Also used : Authentication(org.mule.runtime.api.security.Authentication) DefaultMuleAuthentication(org.mule.runtime.api.security.DefaultMuleAuthentication) SecurityContext(org.mule.runtime.api.security.SecurityContext) UnauthorisedException(org.mule.runtime.api.security.UnauthorisedException)

Example 4 with SecurityContext

use of org.mule.runtime.api.security.SecurityContext in project mule by mulesoft.

the class PetstoreSecurityContextTestCase method filteredProvidersExpectedException.

@Test
public void filteredProvidersExpectedException() throws Exception {
    expectedException.expectCause(instanceOf(SecurityProviderNotFoundException.class));
    SecurityContext context = flowRunner("setSecureCageFilterProviders").withVariable("providers", asList("Invalid")).run().getSecurityContext();
    assertThat(context, is(notNullValue()));
    assertThat(context, is(securityContext));
}
Also used : SecurityProviderNotFoundException(org.mule.runtime.api.security.SecurityProviderNotFoundException) SecurityContext(org.mule.runtime.api.security.SecurityContext) Test(org.junit.Test)

Example 5 with SecurityContext

use of org.mule.runtime.api.security.SecurityContext in project mule by mulesoft.

the class MuleEncryptionEndpointSecurityFilter method authenticateInbound.

@Override
protected SecurityContext authenticateInbound(CoreEvent event) throws SecurityException, SecurityProviderNotFoundException, CryptoFailureException, EncryptionStrategyNotFoundException, UnknownAuthenticationTypeException {
    String userHeader = (String) credentialsAccessor.getCredentials(event);
    if (userHeader == null) {
        throw new CredentialsNotSetException(event, event.getSecurityContext(), this);
    }
    Credentials user = new DefaultMuleCredentials(userHeader, getSecurityManager());
    Authentication authentication;
    try {
        authentication = getSecurityManager().authenticate(new DefaultMuleAuthentication(user));
    } catch (Exception e) {
        // Authentication failed
        if (logger.isDebugEnabled()) {
            logger.debug("Authentication request for user: " + user.getUsername() + " failed: " + e.toString());
        }
        throw new UnauthorisedException(authFailedForUser(user.getUsername()), e);
    }
    // Authentication success
    if (logger.isDebugEnabled()) {
        logger.debug("Authentication success: " + authentication.toString());
    }
    SecurityContext context = getSecurityManager().createSecurityContext(authentication);
    context.setAuthentication(authentication);
    return context;
}
Also used : Authentication(org.mule.runtime.api.security.Authentication) DefaultMuleAuthentication(org.mule.runtime.api.security.DefaultMuleAuthentication) SecurityContext(org.mule.runtime.api.security.SecurityContext) DefaultMuleCredentials(org.mule.runtime.core.api.security.DefaultMuleCredentials) DefaultMuleAuthentication(org.mule.runtime.api.security.DefaultMuleAuthentication) UnauthorisedException(org.mule.runtime.api.security.UnauthorisedException) CredentialsNotSetException(org.mule.runtime.core.internal.security.CredentialsNotSetException) Credentials(org.mule.runtime.api.security.Credentials) DefaultMuleCredentials(org.mule.runtime.core.api.security.DefaultMuleCredentials) EncryptionStrategyNotFoundException(org.mule.runtime.core.api.security.EncryptionStrategyNotFoundException) UnauthorisedException(org.mule.runtime.api.security.UnauthorisedException) SecurityException(org.mule.runtime.api.security.SecurityException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) CryptoFailureException(org.mule.runtime.core.api.security.CryptoFailureException) SecurityProviderNotFoundException(org.mule.runtime.api.security.SecurityProviderNotFoundException) CredentialsNotSetException(org.mule.runtime.core.internal.security.CredentialsNotSetException) UnknownAuthenticationTypeException(org.mule.runtime.api.security.UnknownAuthenticationTypeException)

Aggregations

SecurityContext (org.mule.runtime.api.security.SecurityContext)8 Test (org.junit.Test)4 Authentication (org.mule.runtime.api.security.Authentication)3 DefaultMuleAuthentication (org.mule.runtime.api.security.DefaultMuleAuthentication)3 SecurityProviderNotFoundException (org.mule.runtime.api.security.SecurityProviderNotFoundException)2 UnauthorisedException (org.mule.runtime.api.security.UnauthorisedException)2 DefaultMuleCredentials (org.mule.runtime.core.api.security.DefaultMuleCredentials)2 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 Credentials (org.mule.runtime.api.security.Credentials)1 SecurityException (org.mule.runtime.api.security.SecurityException)1 UnknownAuthenticationTypeException (org.mule.runtime.api.security.UnknownAuthenticationTypeException)1 CryptoFailureException (org.mule.runtime.core.api.security.CryptoFailureException)1 EncryptionStrategyNotFoundException (org.mule.runtime.core.api.security.EncryptionStrategyNotFoundException)1 CredentialsNotSetException (org.mule.runtime.core.internal.security.CredentialsNotSetException)1 DefaultSecurityContextFactory (org.mule.runtime.core.internal.security.DefaultSecurityContextFactory)1