How to use onSetAttribute method of org.cerberus.service.groovy.impl.RestrictiveGroovyInterceptor class

Best Cerberus-source code snippet using org.cerberus.service.groovy.impl.RestrictiveGroovyInterceptor.onSetAttribute

Source:RestrictiveGroovyInterceptor.java Github

copy

Full Screen

...364 checkPropertyAccess(receiver, attribute, false);365 return super.onGetAttribute(invoker, receiver, attribute);366 }367 @Override368 public Object onSetAttribute(Invoker invoker, Object receiver, String attribute, Object value)369 throws Throwable {370 if (disallowedWriteProperties.contains(attribute)) {371 throw new GroovyRestrictionException("setting the property " + attribute372 + " is not allowed in Groovy transformations!");373 }374 if (receiver instanceof Closure && disallowedClosureWriteProperties.contains(attribute)) {375 throw new GroovyRestrictionException("setting the closure property " + attribute376 + " is not allowed in Groovy transformations!");377 }378 checkPropertyAccess(receiver, attribute, true);379 return super.onSetAttribute(invoker, receiver, attribute, value);380 }381 @Override382 public Object onGetArray(Invoker invoker, Object receiver, Object index) throws Throwable {383 // generally allow array access for now384 return super.onGetArray(invoker, receiver, index);385 }386 @Override387 public Object onSetArray(Invoker invoker, Object receiver, Object index, Object value)388 throws Throwable {389 // generally allow array access for now390 return super.onSetArray(invoker, receiver, index, value);391 }392 private static boolean hasProperty(Object object, String property) {393 if (InvokerHelper.getMetaClass(object).hasProperty(object, property) != null) {...

Full Screen

Full Screen

onSetAttribute

Using AI Code Generation

copy

Full Screen

1package org.cerberus.service.groovy.impl;2import groovy.lang.Binding;3import groovy.lang.GroovyShell;4import groovy.lang.Script;5import org.apache.logging.log4j.LogManager;6import org.apache.logging.log4j.Logger;7import org.cerberus.service.groovy.IGroovyService;8import org.springframework.beans.factory.annotation.Autowired;9import org.springframework.beans.factory.annotation.Qualifier;10import org.springframework.stereotype.Service;11public class GroovyService implements IGroovyService {12 private static final Logger LOG = LogManager.getLogger(GroovyService.class);13 @Qualifier("RestrictiveGroovyInterceptor")14 private RestrictiveGroovyInterceptor restrictiveGroovyInterceptor;15 public Object executeGroovyScript(String script, Binding binding) {16 Object result = null;17 try {18 GroovyShell shell = new GroovyShell(binding);19 Script groovyScript = shell.parse(script);20 groovyScript.setMetaClass(restrictiveGroovyInterceptor);21 result = groovyScript.run();22 } catch (Exception ex) {23 LOG.error(ex.toString(), ex);24 }25 return result;26 }27}28package org.cerberus.service.groovy.impl;29import groovy.lang.GroovyObject;30import groovy.lang.MetaClass;31import groovy.lang.MetaMethod;32import java.util.ArrayList;33import java.util.List;34import java.util.Map;35import org.apache.logging.log4j.LogManager;36import org.apache.logging.log4j.Logger;37public class RestrictiveGroovyInterceptor extends MetaClass {38 private static final Logger LOG = LogManager.getLogger(RestrictiveGroovyInterceptor.class);39 private final List<String> allowedMethods = new ArrayList<>();40 public RestrictiveGroovyInterceptor() {41 allowedMethods.add("get");42 allowedMethods.add("put");43 allowedMethods.add("size");44 allowedMethods.add("clear");45 allowedMethods.add("isEmpty");46 allowedMethods.add("containsKey");47 allowedMethods.add("containsValue");48 allowedMethods.add("keySet");49 allowedMethods.add("values");50 allowedMethods.add("entrySet");51 allowedMethods.add("getAt");52 allowedMethods.add("putAt");53 allowedMethods.add("getMetaClass");54 allowedMethods.add("setMetaClass");

Full Screen

Full Screen

onSetAttribute

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.groovy.impl.RestrictiveGroovyInterceptor2import org.cerberus.util.StringUtil3RestrictiveGroovyInterceptor onSetAttributeInterceptor = new RestriveGroovyInterceptor()4def isAuthorized = onSetAttributeInterceptor.isAuthorized(attribute, value)5if (isAuthorized) {6 session.setAttribute(attribute, value)7} else {8 String message = StringUtil.format("You are not authorized to set attribute {0} with value {1}", attribute, value)9 LOG.warn(message)10 throw new Exception(message)11}12import org.cerberus.service.groovy.impl.RestrictiveGroovyInterceptor13import org.cerberus.util.StringUtil14RestrictiveGroovyInterceptor onSetAttributeInterceptor = new RestriveGroovyInterceptor()15def isAuthorized = onSetAttributeInterceptor.isAuthorized(attribute, value)16if (isAuthorized) {17 session.getAttribute(attribute)18} else {19 String message = StringUtil.format("You are not authorized to get attribute {0}", attribute)20 LOG.warn(message)21 throw new Exception(message)22}23import org.cerberus.service.groovy.impl.RestrictiveGroovyInterceptor24import org.cerberus.util.StringUtil25RestrictiveGroovyInterceptor onSetAttributeInterceptor = new RestriveGroovyInterceptor()26def isAuthorized = onSetAttributeInterceptor.isAuthorized(attribute, value)27if (isAuthorized) {28 session.removeAttribute(attribute)29} else {30 String message = StringUtil.format("You are not authorized to remove attribute {0}", attribute)31 LOG.warn(message)32 throw new Exception(message)33}34import org.cerberus.service.groovy.impl.RestrictiveGroovyInterceptor35import org.cerberus.util.StringUtil36RestrictiveGroovyInterceptor onSetAttributeInterceptor = new RestriveGroovyInterceptor()37def isAuthorized = onSetAttributeInterceptor.isAuthorized(attribute, value)38if (isAuthorized) {39 session.setAttribute(attribute, value)40} else {41 String message = StringUtil.format("You are not authorized to set attribute {0} with value {1}", attribute,

Full Screen

Full Screen

onSetAttribute

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.MessageEvent2import org.cerberus.crud.entity.TestCaseExecution3import org.cerberus.crud.entity.TestCaseExecutionData4def getTest() {5}6def getTestCase() {7}8def getCountry() {9}10def getEnvironment() {11}12def getBrowser() {13}14def getTag() {15}16def getApplication() {17}18def getBuild() {19}20def getRevision() {21}22def getRobot() {23}24def getRobotExecutor() {25}26def getRobotHost() {27}28def getRobotPort() {29}30def getRobotPlatform() {31}32def getRobotBrowser() {33}34def getRobotBrowserVersion() {35}36def getRobotDevice() {37}38def getRobotVersion() {39}40def getStart() {41}42def getEnd() {43}44def getControlStatus() {45}46def getControlMessage() {47}48def getControlProperty() {49}50def getTestCaseExecution() {51}52def getTestCaseExecutionDataList() {53}54def getTestCaseExecutionDataListByCriteria(String test, String testCase, String country, String environment, String tag, String property, String type, String database) {55 return testCaseExecutionDataList.findAll { it.test == test && it.testCase == testCase && it.country == country && it.environment == environment && it.tag == tag && it.property == property && it.type == type && it.database == database }56}57def getTestCaseExecutionDataListByCriteria(String test, String testCase, String country, String environment, String tag, String property, String type) {58 return testCaseExecutionDataList.findAll { it.test == test && it.testCase == testCase &&

Full Screen

Full Screen

onSetAttribute

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.MessageEvent2import org.cerberus.engine.entity.MessageGeneral3import org.cerberus.engine.execution.IExecutionService4import org.cerberus.engine.groovy.impl.RestrictiveGroovyInterceptor5import org.cerberus.engine.groovy.impl.Script6import org.cerberus.engine.groovy.impl.ScriptFactory7import org.cerberus.engine.groovy.impl.ScriptResult8import org.cerberus.engine.groovy.impl.ScriptSource9import org.cerberus.engine.groovy.impl.ScriptSourceFactory10import org.cerberus.engine.groovy.impl.ScriptSourceFactoryImpl11import org.cerberus.engine.groovy.impl.ScriptSourceImpl12import org.cerberus.engine.groovy.impl.ScriptSourceKey13import org.cerberus.engine.groovy.impl.ScriptSourceKeyFactory14import org.cerberus.engine.groovy.impl.ScriptSourceKeyFactoryImpl15import org.cerberus.engine.groovy.impl.ScriptSourceKeyImpl16import org.cerberus.engine.groovy.impl.ScriptSourceLocation17import org.cerberus.engine.groovy.impl.ScriptSourceLocationFactory18import org.cerberus.engine.groovy.impl.ScriptSourceLocationFactoryImpl19import org.cerberus.engine.groovy.impl.ScriptSourceLocationImpl20import org.cerberus.engine.groovy.impl.ScriptSourceOwner21import org.cerberus.engine.groovy.impl.ScriptSourceOwnerFactory22import org.cerberus.engine.groovy.impl.ScriptSourceOwnerFactoryImpl23import org.cerberus.engine.groovy.impl.ScriptSourceOwnerImpl24import org.cerberus.engine.groovy.impl.ScriptSourceRepository25import org.cerberus.engine.groovy.impl.ScriptSourceRepositoryImpl26import org.cerberus.engine.groovy.impl.ScriptSourceRepositoryKey27import org.cerberus.engine.groovy.impl.ScriptSourceRepositoryKeyFactory28import org.cerberus.engine.groovy.impl.ScriptSourceRepositoryKeyFactoryImpl29import org.cerberus.engine.groovy.impl.ScriptSourceRepositoryKeyImpl30import org.cerberus.engine.groovy.impl.ScriptSourceRepositoryType31import org.cerberus.engine.groovy.impl.ScriptSourceRepositoryType

Full Screen

Full Screen

onSetAttribute

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecution2import org.cerberus.crud.entity.TestCaseExecutionData3import org.cerberus.crud.entity.TestCaseExecutionInQueue4import org.cerberus.crud.entity.TCase5import org.cerberus.crud.entity.TCaseCountryProperties6import org.cerberus.crud.entity.TCaseStep7import org.cerberus.crud.entity.TCaseStepAction8import org.cerberus.crud.entity.TCaseStepActionControl9import org.cerberus.crud.entity.TCaseStepActionControlExecution10import org.cerberus.crud.entity.TCaseStepExecution11import org.cerberus.crud.entity.TCaseStepExecutionFile12import org.cerberus.crud.entity.TCaseStepExecutionInQueue13import org.cerberus.crud.entity.TCaseStepExecutionQueueToTCaseStepExecution14import org.cerberus.crud.entity.TCaseStepFile15import org.cerberus.crud.entity.TCaseStepTestCaseExecution16import org.cerberus.crud.entity.TCaseStepTestCaseExecutionQueue17import org.cerberus.crud.entity.TCaseStepTestCaseExecutionQueueToTCaseStepTestCaseExecution18import org.cerberus.crud.entity.TCaseStepTestCaseExecutionToTCaseStep19import org.cerberus.crud.entity.TCaseTestCaseCountry20import org.cerberus.crud.entity.TCaseTestCaseCountryProperties21import org.cerberus.crud.entity.TCaseTestCaseCountryPropertiesExecution22import org.cerberus.crud.entity.TCaseTestCaseCountryPropertiesExecutionQueue23import org.cerberus.crud.entity.TCaseTestCaseCountryPropertiesExecutionQueueToTCaseTestCaseCountryPropertiesExecution24import org.cerberus.crud.entity.TCaseTestCaseCountryPropertiesExecutionToTCaseTestCaseCountryProperties25import org.cerberus.crud.entity.TCaseTestCaseCountryPropertiesToTCase26import org.cerberus.crud.entity.TCaseTestCaseCountryToTCase27import org.cerberus.crud.entity.TCaseTestCaseCountryToTCaseCountry28import org.cerberus.crud.entity.TCaseToTProject29import org.cerberus.crud.entity.TCaseToTProjectTestCaseExecution30import org.cerberus.crud.entity

Full Screen

Full Screen

onSetAttribute

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.groovy.impl.RestrictiveGroovyInterceptor2RestrictiveGroovyInterceptor.onSetAttribute = { String name, Object value ->3 if (name == "restricted" && value == "true") {4 return ["java.lang.System.exit", "java.lang.Runtime.getRuntime().exec", "java.lang.Runtime.getRuntime().halt"]5 }6}7import org.cerberus.service.groovy.impl.RestrictiveGroovyInterceptor8RestrictiveGroovyInterceptor.onSetAttribute = { String name, Object value ->9 if (name == "restricted" && value == "true") {10 return ["java.lang.System.exit", "java.lang.Runtime.getRuntime().exec", "java.lang.Runtime.getRuntime().halt"]11 }12}13java.lang.Runtime.getRuntime().exec14java.lang.Runtime.getRuntime().halt15java.lang.Runtime.getRuntime().load16java.lang.Runtime.getRuntime().loadLibrary17java.lang.Runtime.getRuntime().addShutdownHook18java.lang.Runtime.getRuntime().removeShutdownHook19java.lang.Runtime.getRuntime().traceInstructions20java.lang.Runtime.getRuntime().traceMethodCalls21java.lang.Runtime.getRuntime().loadLibrary

Full Screen

Full Screen

onSetAttribute

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecutionData2import org.cerberus.crud.entity.TestCaseExecutionData3import org.cerberus.crud.service.ITestCaseExecutionDataService4import org.springframework.beans.factory.annotation.Autowired5def testCaseExecutionDataList = new ArrayList<TestCaseExecutionData>()6def init() {7 testCaseExecutionDataService = appContext.getBean(ITestCaseExecutionDataService.class)8}9def onSetAttribute(testCaseExecutionData) {10 def testCaseExecutionDataInList = testCaseExecutionDataList.find { it.getProperty().equalsIgnoreCase(testCaseExecutionData.getProperty()) }11 if (testCaseExecutionDataInList != null) {12 testCaseExecutionDataInList.setValue(testCaseExecutionData.getValue())13 } else {14 testCaseExecutionDataList.add(testCaseExecutionData)15 }16}17def onSetAttribute(String property, String value) {18 onSetAttribute(new TestCaseExecutionData(property, value))19}20def onGetAttribute(String property) {21 def testCaseExecutionDataInList = testCaseExecutionDataList.find { it.getProperty().equalsIgnoreCase(property) }22 if (testCaseExecutionDataInList != null) {23 return testCaseExecutionDataInList.getValue()24 }25}26def onGetAttributeList() {27}28def onClearAttribute(String property) {29 def testCaseExecutionDataInList = testCaseExecutionDataList.find { it.getProperty().equalsIgnoreCase(property) }30 if (testCaseExecutionDataInList != null) {31 testCaseExecutionDataList.remove(testCaseExecutionDataInList)32 }33}34def onClearAttributeList() {35 testCaseExecutionDataList.clear()36}37def onPersistAttributeList() {38 testCaseExecutionDataList.each {39 testCaseExecutionDataService.create(it)40 }41}42def onPersistAttribute(String property) {43 def testCaseExecutionDataInList = testCaseExecutionDataList.find { it.getProperty().equalsIgnoreCase(property) }44 if (testCaseExecutionDataInList != null) {45 testCaseExecutionDataService.create(testCaseExecutionDataInList)46 }47}48def onPersistAttributeList(List<String> propertyList) {49 testCaseExecutionDataList.each {50 if (propertyList.contains(it.getProperty())) {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful