Grails security filter all action but except one - security

I'm gonna create a security filter for my project. I check if !session.user then redirect to action error.
Here is my current code:
all(controller: 'accounting|installation|installer|sales|service|serviceOrder|document', action: '*') {
before = {
if (!session.user) {
redirect(controller: 'installation', action: 'errors')
return false
}
}
after = { Map model ->
}
afterView = { Exception e ->
}
}
However the point is that session.user being created in controller 'installation' and action 'index'. So how can I filter without index action?
Any suggestions will be appreciated. Thanks.

You can use invert:true
e.g
def filters = {
allExceptIndex(controller:"installation",action:"index",invert:true) {
before = {
}
after = { Map model ->
}
afterView = { Exception e ->
}
}
}
For further reference see Blog

Try this
all(controller: 'accounting|installation|installer|sales|service|serviceOrder|document', action: '*') {
before = {
if (!(controllerName == 'installation' && actionName == 'index')) {
if (!session.user) {
redirect(controller: 'installation', action: 'errors')
return false
}
}
}
after = { Map model ->
}
afterView = { Exception e ->
}
}

Hope I have understood your question ,Since you want to exclude action index then ,try this ..
all(controller: 'accounting|installation|installer|sales|service|serviceOrder|document', action: '*',actionExclude:'index'){....
Regards

Related

Guidewire : Refresh List view when the button is clicked

The Listview(partial page) is not getting refreshed when I click the button. It keeps on adding the rows whenever the buttons are clicked.
Below are the functions for adding the drivers.
function getDriversFromPolicy_CA7() : CA7CommAutoDriver[] {
var drivers = this.Policy.LatestPeriod.CA7Line.Drivers // **this** Contingency Entity
var excludeDrivers = this.ExcludeDrivers_CA7.toList() // Contingency entity has a ExcludeDrivers_CA7 array
if(excludeDrivers.Empty) {
drivers?.each(\driver -> this.addToExcludeDrivers_CA7(driver) )
} else {
drivers.each(\driver -> {
if (excludeDrivers.where(\elt -> elt.LicenseNumber == driver.LicenseNumber).toList().Count == 0) {
this.addToExcludeDrivers_CA7(driver)
}
})
}
return this.ExcludeDrivers_CA7
}
function getDriversFromTransaction_CA7() : CA7CommAutoDriver[] {
var drivers = this.PolicyPeriod.CA7Line.Drivers.toList()
var excludeDrivers = this.ExcludeDrivers_CA7.toList()
if(this.ExcludeDrivers_CA7.IsEmpty) {
drivers?.each(\driver -> this.addToExcludeDrivers_CA7(driver) )
} else {
// this.ExcludeDrivers_CA7.toList().retainAll(drivers.toList())
drivers.each(\driver -> {
if (excludeDrivers.where(\elt -> elt.LicenseNumber == driver.LicenseNumber).toList().Count == 0) {
this.addToExcludeDrivers_CA7(driver)
}
})
}
return this.ExcludeDrivers_CA7
}
function removeDrivers_CA7(driver : CA7CommAutoDriver) {
this.removeFromExcludeDrivers_CA7(driver)
}
pcf screenshot for reference
UI screenshot for reference

concurrent query and insert have any side effect in android with objectbox?

In my android project, I use objectbox as database, if I insert with lock and query without lock, is there any side effect ? such as crash and so on.
fun query(uniqueId: String = ""): MutableList<T> {
if (box.store.isClosed) return mutableListOf()
val query = box.query()
withQueryBuilder(query, uniqueId)
//开始
return query.build().find()
}
private fun putInner(entity: T): Long {
synchronized(box.store) {
if (box.store.isClosed) return -1
if (entity.unique.isBlank()) {
entity.unique = entity.providerUnique()
}
entity.timestamp = System.currentTimeMillis()
return try {
box.put(entity).let { id -> entity.id = id }
entity.id
} catch (ex: Exception) {
-1
}
}
}

How to compare a previous list and updated a field in multi thread

I have a local cache where I store the runner's lap info, I need to show if the runner's current lap was better or worse than the current lap, while displaying the current lap information.
data class RunInfo(
val runnerId: String,
val lapTime: Double,
var betterThanLastLap: BETTERTHANLASTLAP
)
enum class BETTERTHANLASTLAP {
NA, YES, NO
}
object RunDB {
private var listOfRunners: MutableList<RunInfo> =
java.util.Collections.synchronizedList(mutableListOf())
private var previousList: MutableList<RunInfo> = mutableListOf()
fun save(runList: MutableList<RunInfo>) {
previousList = listOfRunners.toMutableList()
listOfRunners.clear()
listOfRunners.addAll(runList)
listOfRunners.forEach { runner ->
previousList.forEach { previousLap ->
if (runner.runnerId == previousLap.runnerId) {
runner.betterThanLastLap =
when {
previousLap.lapTime == 0.0 -> BETTERTHANLASTLAP.NA
runner.lapTime >= previousLap.lapTime -> BETTERTHANLASTLAP.YES
else -> BETTERTHANLASTLAP.NO
}
}
}
}
}
}
This seems to do the job, but often I get concurrent modification exception. Is there a better way of solving this problem?
I don't recommend combining mutable lists with read-write var properties. Making it mutable in two different ways creates ambiguity and is error prone. Since you're just clearing and replacing the list contents, I would make it a read-only list and a read-write property.
You need to synchronize the whole function so it can only be executed once at a time.
object RunDB {
private var listOfRunners: List<RunInfo> = listOf()
private var previousList: List<RunInfo> = listOf()
fun save(runList: List<RunInfo>) {
sychronized(this) {
previousList = listOfRunners.toList()
listOfRunners = runList.toList()
listOfRunners.forEach { runner ->
previousList.forEach { previousLap ->
if (runner.runnerId == previousLap.runnerId) {
runner.betterThanLastLap =
when {
previousLap.lapTime == 0.0 -> BETTERTHANLASTLAP.NA
runner.lapTime >= previousLap.lapTime -> BETTERTHANLASTLAP.YES
else -> BETTERTHANLASTLAP.NO
}
}
}
}
}
}
}
It also feels error prone to have a mutable data class in these lists that you're copying and shuffling around. I recommend making it immutable:
data class RunInfo(
val runnerId: String,
val lapTime: Double,
val betterThanLastLap: BETTERTHANLASTLAP
)
object RunDB {
private var listOfRunners: List<RunInfo> = listOf()
private var previousList: List<RunInfo> = listOf()
fun save(runList: List<RunInfo>) {
sychronized(this) {
previousList = listOfRunners.toList()
listOfRunners = runList.map { runner ->
val previousLap = previousList.find { runner.runnerId == previousLap.runnerId }
runner.copy(betterThanLastLap = when {
previousLap == null || previousLap.lapTime == 0.0 -> BETTERTHANLASTLAP.NA
runner.lapTime >= previousLap.lapTime -> BETTERTHANLASTLAP.YES
else -> BETTERTHANLASTLAP.NO
})
}
}
}
}

How to access the data from database into groovy using filters

Here I try to get the data from uploadcdr table but I cannot understand how the filters work. Please explain me.
def private getFilteredUploadCDR(filters, GrailsParameterMap params) {
params.max = params?.max?.toInteger() ?: pagination.max
params.offset = params?.offset?.toInteger() ?: pagination.offset
params.sort = params?.sort ?: pagination.sort
params.order = params?.order ?: pagination.order
return UploadCDRFileDTO.createCriteria().list(
max: params.max,
offset: params.offset
) {
and {
filters.each { filter ->
log.debug("fileter field ${filter.field}")
if (filter.value) {
addToCriteria(filter.getRestrictions());
}
}
}
// apply sorting
SortableCriteria.sort(params, delegate)
}
}

Get item’s metadata with Entity Framework?

I'm working with Sharepoint 2010.
I need to know the date of creation/edition and the author/editor of items in my sharepoint's Lists, but I didn't find a solution to map these columns with Entity Framework.
I tried this kind of code :
[Microsoft.SharePoint.Linq.ColumnAttribute(Name = "tp_author", Storage = "_author", ReadOnly = true, FieldType = "User")]
public SPUser Author
{
get
{
return this._author;
}
set
{
if (!value.Equals(this._author))
{
this.OnPropertyChanging("Author", this._author);
this._author = value;
this.OnPropertyChanged("Author");
}
}
}
But with that code, Sharepoint give me this error:
Invalid transfer type Microsoft.SharePoint.SPUser
I also tried with other types for _author, but it doesn't change anything.
Is there a way to make this mapping?
SPMetal generates the following code for a user field
[Microsoft.SharePoint.Linq.ColumnAttribute(Name="AssignedTo", Storage="_assignedToId", FieldType="User", IsLookupId=true)]
public System.Nullable<int> AssignedToId {
get {
return this._assignedToId;
}
set {
if ((value != this._assignedToId)) {
this.OnPropertyChanging("AssignedToId", this._assignedToId);
this._assignedToId = value;
this.OnPropertyChanged("AssignedToId");
}
}
}
[Microsoft.SharePoint.Linq.ColumnAttribute(Name="AssignedTo", Storage="_assignedTo", ReadOnly=true, FieldType="User", IsLookupValue=true)]
public string AssignedTo {
get {
return this._assignedTo;
}
set {
if ((value != this._assignedTo)) {
this.OnPropertyChanging("AssignedTo", this._assignedTo);
this._assignedTo = value;
this.OnPropertyChanged("AssignedTo");
}
}
}

Resources