Search in sources :

Example 1 with DefaultMuleAuthentication

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

the class DataWeaveExpressionLanguageAdaptorTestCase method authenticationBinding.

@Test
public void authenticationBinding() throws Exception {
    CoreEvent event = spy(testEvent());
    Authentication authentication = new DefaultMuleAuthentication(new DefaultMuleCredentials("username", "password".toCharArray()));
    when(event.getAuthentication()).thenReturn(of(authentication));
    TypedValue result = expressionLanguage.evaluate(AUTHENTICATION, event, BindingContext.builder().build());
    assertThat(result.getValue(), is(instanceOf(Authentication.class)));
    assertThat(result.getValue(), is(authentication));
    assertThat(result.getDataType().getType(), is(equalTo(Authentication.class)));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DefaultMuleAuthentication(org.mule.runtime.api.security.DefaultMuleAuthentication) Authentication(org.mule.runtime.api.security.Authentication) DefaultMuleCredentials(org.mule.runtime.core.api.security.DefaultMuleCredentials) DefaultMuleAuthentication(org.mule.runtime.api.security.DefaultMuleAuthentication) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 2 with DefaultMuleAuthentication

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

the class UsernamePasswordAuthenticationFilter method getAuthenticationToken.

protected Authentication getAuthenticationToken(CoreEvent event) throws UnauthorisedException {
    ExpressionManager expressionManager = (ExpressionManager) registry.lookupByName(OBJECT_EXPRESSION_MANAGER).get();
    Object usernameEval = expressionManager.evaluate(username, event).getValue();
    Object passwordEval = expressionManager.evaluate(password, event).getValue();
    if (usernameEval == null) {
        throw new UnauthorisedException(authNoCredentials());
    }
    if (passwordEval == null) {
        throw new UnauthorisedException(authNoCredentials());
    }
    return new DefaultMuleAuthentication(new DefaultMuleCredentials(usernameEval.toString(), passwordEval.toString().toCharArray()));
}
Also used : ExpressionManager(org.mule.runtime.core.api.el.ExpressionManager) DefaultMuleCredentials(org.mule.runtime.core.api.security.DefaultMuleCredentials) UnauthorisedException(org.mule.runtime.api.security.UnauthorisedException) DefaultMuleAuthentication(org.mule.runtime.api.security.DefaultMuleAuthentication)

Example 3 with DefaultMuleAuthentication

use of org.mule.runtime.api.security.DefaultMuleAuthentication 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)

Example 4 with DefaultMuleAuthentication

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

the class MuleEventTestCase method createTestAuthentication.

private SecurityContext createTestAuthentication() {
    Authentication auth = new DefaultMuleAuthentication(new DefaultMuleCredentials("dan", new char[] { 'd', 'f' }));
    SecurityContext securityContext = new DefaultSecurityContextFactory().create(auth.setProperties(singletonMap("key1", "value1")));
    return securityContext;
}
Also used : DefaultSecurityContextFactory(org.mule.runtime.core.internal.security.DefaultSecurityContextFactory) DefaultMuleAuthentication(org.mule.runtime.api.security.DefaultMuleAuthentication) Authentication(org.mule.runtime.api.security.Authentication) SecurityContext(org.mule.runtime.api.security.SecurityContext) DefaultMuleCredentials(org.mule.runtime.core.api.security.DefaultMuleCredentials) DefaultMuleAuthentication(org.mule.runtime.api.security.DefaultMuleAuthentication)

Aggregations

DefaultMuleAuthentication (org.mule.runtime.api.security.DefaultMuleAuthentication)4 DefaultMuleCredentials (org.mule.runtime.core.api.security.DefaultMuleCredentials)4 Authentication (org.mule.runtime.api.security.Authentication)3 SecurityContext (org.mule.runtime.api.security.SecurityContext)2 UnauthorisedException (org.mule.runtime.api.security.UnauthorisedException)2 Test (org.junit.Test)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 TypedValue (org.mule.runtime.api.metadata.TypedValue)1 Credentials (org.mule.runtime.api.security.Credentials)1 SecurityException (org.mule.runtime.api.security.SecurityException)1 SecurityProviderNotFoundException (org.mule.runtime.api.security.SecurityProviderNotFoundException)1 UnknownAuthenticationTypeException (org.mule.runtime.api.security.UnknownAuthenticationTypeException)1 ExpressionManager (org.mule.runtime.core.api.el.ExpressionManager)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)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