Search in sources :

Example 1 with SecurityProvider

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

the class DefaultMuleSecurityManager method createSecurityContext.

/**
 * {@inheritDoc}
 */
@Override
public SecurityContext createSecurityContext(Authentication authentication) throws UnknownAuthenticationTypeException {
    Iterator<SecurityProvider> iter = providers.values().iterator();
    Class<? extends Authentication> toTest = authentication.getClass();
    while (iter.hasNext()) {
        SecurityProvider provider = iter.next();
        if (provider.supports(toTest)) {
            return provider.createSecurityContext(authentication);
        }
    }
    throw new UnknownAuthenticationTypeException(authentication);
}
Also used : SecurityProvider(org.mule.runtime.core.api.security.SecurityProvider) UnknownAuthenticationTypeException(org.mule.runtime.api.security.UnknownAuthenticationTypeException)

Example 2 with SecurityProvider

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

the class PetstoreSecurityContextTestCase method setup.

@Before
public void setup() throws Exception {
    when(provider.getName()).thenReturn(MOCK_PROVIDER);
    when(provider.authenticate(any(Authentication.class))).thenReturn(authenticationResult);
    when(provider.createSecurityContext(authenticationResult)).thenReturn(securityContext);
    when(provider.supports(any())).thenReturn(true);
    SecurityProvider nullProvider = mock(SecurityProvider.class);
    when(nullProvider.getName()).thenReturn(NULL_PROVIDER);
    when(nullProvider.authenticate(any())).thenReturn(null);
    when(nullProvider.createSecurityContext(any())).thenReturn(null);
    when(nullProvider.supports(any())).thenReturn(false);
    muleContext.getSecurityManager().addProvider(provider);
    muleContext.getSecurityManager().addProvider(nullProvider);
}
Also used : Authentication(org.mule.runtime.api.security.Authentication) SecurityProvider(org.mule.runtime.core.api.security.SecurityProvider) Before(org.junit.Before)

Example 3 with SecurityProvider

use of org.mule.runtime.core.api.security.SecurityProvider 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 4 with SecurityProvider

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

Aggregations

SecurityProvider (org.mule.runtime.core.api.security.SecurityProvider)4 Authentication (org.mule.runtime.api.security.Authentication)2 SecurityProviderNotFoundException (org.mule.runtime.api.security.SecurityProviderNotFoundException)2 UnknownAuthenticationTypeException (org.mule.runtime.api.security.UnknownAuthenticationTypeException)2 Before (org.junit.Before)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 SecurityException (org.mule.runtime.api.security.SecurityException)1 UnauthorisedException (org.mule.runtime.api.security.UnauthorisedException)1 SecurityManager (org.mule.runtime.core.api.security.SecurityManager)1 DefaultMuleSecurityManager (org.mule.runtime.core.internal.security.DefaultMuleSecurityManager)1