Search in sources :

Example 1 with SecurityProviderNotFoundException

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

the class DefaultAuthenticationHandler method setAuthentication.

/**
 * {@inheritDoc}
 */
@Override
public void setAuthentication(List<String> securityProviders, Authentication authentication) throws SecurityProviderNotFoundException, SecurityException, UnknownAuthenticationTypeException {
    if (!securityProviders.isEmpty()) {
        // This filter may only allow authentication on a subset of registered
        // security providers
        SecurityManager localManager = new DefaultMuleSecurityManager();
        for (String sp : securityProviders) {
            SecurityProvider provider = manager.getProvider(sp);
            if (provider != null) {
                localManager.addProvider(provider);
            } else {
                throw new SecurityProviderNotFoundException(sp);
            }
        }
        this.manager = localManager;
    }
    setAuthentication(authentication);
}
Also used : DefaultMuleSecurityManager(org.mule.runtime.core.internal.security.DefaultMuleSecurityManager) DefaultMuleSecurityManager(org.mule.runtime.core.internal.security.DefaultMuleSecurityManager) SecurityManager(org.mule.runtime.core.api.security.SecurityManager) SecurityProviderNotFoundException(org.mule.runtime.api.security.SecurityProviderNotFoundException) SecurityProvider(org.mule.runtime.core.api.security.SecurityProvider)

Example 2 with SecurityProviderNotFoundException

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

the class DefaultMuleSecurityManager method authenticate.

/**
 * {@inheritDoc}
 */
@Override
public Authentication authenticate(Authentication authentication) throws SecurityException, SecurityProviderNotFoundException {
    Iterator<SecurityProvider> iter = providers.values().iterator();
    Class<? extends Authentication> toTest = authentication.getClass();
    while (iter.hasNext()) {
        SecurityProvider provider = iter.next();
        if (provider.supports(toTest)) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Authentication attempt using " + provider.getClass().getName());
            }
            Authentication result = null;
            try {
                result = provider.authenticate(authentication);
            } catch (Exception e) {
                if (!iter.hasNext()) {
                    throw new UnauthorisedException(authorizationAttemptFailed(), e);
                }
            }
            if (result != null) {
                return result;
            }
        }
    }
    throw new SecurityProviderNotFoundException(toTest.getName());
}
Also used : SecurityProviderNotFoundException(org.mule.runtime.api.security.SecurityProviderNotFoundException) Authentication(org.mule.runtime.api.security.Authentication) SecurityProvider(org.mule.runtime.core.api.security.SecurityProvider) UnauthorisedException(org.mule.runtime.api.security.UnauthorisedException) UnauthorisedException(org.mule.runtime.api.security.UnauthorisedException) SecurityException(org.mule.runtime.api.security.SecurityException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) SecurityProviderNotFoundException(org.mule.runtime.api.security.SecurityProviderNotFoundException) UnknownAuthenticationTypeException(org.mule.runtime.api.security.UnknownAuthenticationTypeException)

Example 3 with SecurityProviderNotFoundException

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

SecurityProviderNotFoundException (org.mule.runtime.api.security.SecurityProviderNotFoundException)3 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)2 Authentication (org.mule.runtime.api.security.Authentication)2 SecurityException (org.mule.runtime.api.security.SecurityException)2 UnauthorisedException (org.mule.runtime.api.security.UnauthorisedException)2 UnknownAuthenticationTypeException (org.mule.runtime.api.security.UnknownAuthenticationTypeException)2 SecurityProvider (org.mule.runtime.core.api.security.SecurityProvider)2 Credentials (org.mule.runtime.api.security.Credentials)1 DefaultMuleAuthentication (org.mule.runtime.api.security.DefaultMuleAuthentication)1 SecurityContext (org.mule.runtime.api.security.SecurityContext)1 CryptoFailureException (org.mule.runtime.core.api.security.CryptoFailureException)1 DefaultMuleCredentials (org.mule.runtime.core.api.security.DefaultMuleCredentials)1 EncryptionStrategyNotFoundException (org.mule.runtime.core.api.security.EncryptionStrategyNotFoundException)1 SecurityManager (org.mule.runtime.core.api.security.SecurityManager)1 CredentialsNotSetException (org.mule.runtime.core.internal.security.CredentialsNotSetException)1 DefaultMuleSecurityManager (org.mule.runtime.core.internal.security.DefaultMuleSecurityManager)1