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);
}
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);
}
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);
}
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());
}
Aggregations