use of org.jowidgets.cap.security.common.api.ISecureServiceId in project jo-client-platform by jo-source.
the class SecureServiceDecoratorProviderImpl method getDecorator.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <SERVICE_TYPE> IDecorator<SERVICE_TYPE> getDecorator(final IServiceId<SERVICE_TYPE> id) {
Assert.paramNotNull(id, "id");
if (id instanceof ISecureServiceId) {
final Object authorization = ((ISecureServiceId) id).getAuthorization();
final Class<? extends SERVICE_TYPE> serviceType = id.getServiceType();
return new IDecorator<SERVICE_TYPE>() {
@Override
public SERVICE_TYPE decorate(final SERVICE_TYPE original) {
final InvocationHandler invocationHandler = new SecurityInvocationHandler(original, authorization);
return (SERVICE_TYPE) Proxy.newProxyInstance(serviceType.getClassLoader(), new Class[] { serviceType }, invocationHandler);
}
};
} else if (DecorationMode.ALLOW_UNSECURE == decorationMode) {
return new IdentityTransformationDecorator<SERVICE_TYPE>();
} else {
throw new RuntimeException("The service with the id '" + id + "' has not the type '" + ISecureServiceId.class.getName() + "'");
}
}
Aggregations