Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
7b97e40b
Commit
7b97e40b
authored
8 years ago
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added PermissionEvaluator
parent
a66267cb
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
105 deletions
+61
-105
PermissionEvaluatorImp.java
...java/nl/uva/sne/drip/api/auth/PermissionEvaluatorImp.java
+13
-9
MethodSecurityConfig.java
...n/java/nl/uva/sne/drip/api/conf/MethodSecurityConfig.java
+40
-0
SecurityConfig.java
...rc/main/java/nl/uva/sne/drip/api/conf/SecurityConfig.java
+1
-1
WebAppInitializer.java
...main/java/nl/uva/sne/drip/api/conf/WebAppInitializer.java
+1
-1
CloudCredentialsService.java
.../nl/uva/sne/drip/api/service/CloudCredentialsService.java
+6
-15
OwnedObject.java
...in/java/nl/uva/sne/drip/commons/v1/types/OwnedObject.java
+0
-18
Permissions.java
...in/java/nl/uva/sne/drip/commons/v1/types/Permissions.java
+0
-61
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/auth/Permission
Checker
.java
→
drip-api/src/main/java/nl/uva/sne/drip/api/auth/Permission
EvaluatorImp
.java
View file @
7b97e40b
...
@@ -15,23 +15,27 @@
...
@@ -15,23 +15,27 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
auth
;
package
nl
.
uva
.
sne
.
drip
.
api
.
auth
;
import
nl.uva.sne.drip.commons.v1.types.OwnedObject
;
import
java.io.Serializable
;
import
nl.uva.sne.drip.commons.v1.types.Use
r
;
import
org.springframework.security.access.PermissionEvaluato
r
;
import
org.springframework.s
tereotype.Component
;
import
org.springframework.s
ecurity.core.Authentication
;
/**
/**
*
*
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@Component
(
"PermissionChecker"
)
public
class
PermissionEvaluatorImp
implements
PermissionEvaluator
{
public
class
PermissionChecker
{
public
boolean
canRead
(
OwnedObject
obj
,
User
user
)
{
@Override
public
boolean
hasPermission
(
Authentication
a
,
Object
o
,
Object
o1
)
{
if
(!
a
.
isAuthenticated
())
{
return
false
;
}
return
false
;
return
false
;
}
}
public
boolean
isOwner
(
OwnedObject
obj
,
User
user
)
{
@Override
String
ownerid
=
obj
.
getOwner
();
public
boolean
hasPermission
(
Authentication
a
,
Serializable
srlzbl
,
String
string
,
Object
o
)
{
return
user
.
getId
().
equals
(
ownerid
);
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
//To change body of generated methods, choose Tools | Templates.
}
}
}
}
This diff is collapsed.
Click to expand it.
drip-api/src/main/java/nl/uva/sne/drip/api/conf/
Converter
Config.java
→
drip-api/src/main/java/nl/uva/sne/drip/api/conf/
MethodSecurity
Config.java
View file @
7b97e40b
...
@@ -15,18 +15,26 @@
...
@@ -15,18 +15,26 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
conf
;
package
nl
.
uva
.
sne
.
drip
.
api
.
conf
;
import
org.springframework.context.annotation.ComponentScan
;
import
nl.uva.sne.drip.api.auth.PermissionEvaluatorImp
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.security.access.expression.method.MethodSecurityExpressionHandler
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration
;
/**
/**
*
*
* @author alogo
* @author alogo
*/
*/
@EnableWebMvc
@Configuration
@Configuration
@
ComponentScan
({
"nl.uva.sne.drip.api"
}
)
@
EnableGlobalMethodSecurity
(
prePostEnabled
=
true
)
public
class
ConverterConfig
extends
WebMvcConfigurerAdapter
{
public
class
MethodSecurityConfig
extends
GlobalMethodSecurityConfiguration
{
@Override
protected
MethodSecurityExpressionHandler
createExpressionHandler
()
{
DefaultMethodSecurityExpressionHandler
expressionHandler
=
new
DefaultMethodSecurityExpressionHandler
();
expressionHandler
.
setPermissionEvaluator
(
new
PermissionEvaluatorImp
());
return
expressionHandler
;
}
}
}
This diff is collapsed.
Click to expand it.
drip-api/src/main/java/nl/uva/sne/drip/api/conf/SecurityConfig.java
View file @
7b97e40b
...
@@ -21,6 +21,7 @@ import nl.uva.sne.drip.api.service.UserService;
...
@@ -21,6 +21,7 @@ import nl.uva.sne.drip.api.service.UserService;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.access.expression.method.MethodSecurityExpressionHandler
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
...
@@ -75,5 +76,4 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -75,5 +76,4 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
PasswordEncoder
encoder
=
new
BCryptPasswordEncoder
();
PasswordEncoder
encoder
=
new
BCryptPasswordEncoder
();
return
encoder
;
return
encoder
;
}
}
}
}
This diff is collapsed.
Click to expand it.
drip-api/src/main/java/nl/uva/sne/drip/api/conf/WebAppInitializer.java
View file @
7b97e40b
...
@@ -28,7 +28,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
...
@@ -28,7 +28,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
ctx
.
register
(
MultipartConfig
.
class
);
ctx
.
register
(
MultipartConfig
.
class
);
ctx
.
register
(
MongoConfig
.
class
);
ctx
.
register
(
MongoConfig
.
class
);
ctx
.
register
(
SecurityConfig
.
class
);
ctx
.
register
(
SecurityConfig
.
class
);
ctx
.
register
(
Converter
Config
.
class
);
ctx
.
register
(
MethodSecurity
Config
.
class
);
ctx
.
setServletContext
(
servletContext
);
ctx
.
setServletContext
(
servletContext
);
...
...
This diff is collapsed.
Click to expand it.
drip-api/src/main/java/nl/uva/sne/drip/api/service/CloudCredentialsService.java
View file @
7b97e40b
...
@@ -15,15 +15,10 @@
...
@@ -15,15 +15,10 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
nl.uva.sne.drip.api.dao.CloudCredentialsDao
;
import
nl.uva.sne.drip.api.dao.CloudCredentialsDao
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.Permissions
;
import
nl.uva.sne.drip.commons.v1.types.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PostAuthorize
;
import
org.springframework.security.access.prepost.PostFilter
;
import
org.springframework.security.access.prepost.PostFilter
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreFilter
;
import
org.springframework.security.access.prepost.PreFilter
;
...
@@ -39,21 +34,17 @@ public class CloudCredentialsService {
...
@@ -39,21 +34,17 @@ public class CloudCredentialsService {
@Autowired
@Autowired
private
CloudCredentialsDao
dao
;
private
CloudCredentialsDao
dao
;
@PreFilter
(
"(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
//
@PreFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public
CloudCredentials
save
(
CloudCredentials
cloudCredentials
)
{
public
CloudCredentials
save
(
CloudCredentials
cloudCredentials
)
{
Permissions
permissions
=
new
Permissions
();
// String owner = user.getUsername();
// String owner = user.getUsername();
// cloudCredentials.setOwner(owner);
// cloudCredentials.setOwner(owner);
System
.
err
.
println
(
cloudCredentials
.
getOwner
());
System
.
err
.
println
(
cloudCredentials
.
getOwner
());
Set
<
String
>
read
=
new
HashSet
<>();
permissions
.
setRead
(
read
);
Set
<
String
>
write
=
new
HashSet
<>();
permissions
.
setWrite
(
write
);
cloudCredentials
.
setPermissions
(
permissions
);
return
dao
.
save
(
cloudCredentials
);
return
dao
.
save
(
cloudCredentials
);
}
}
@PreAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
// @PreAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
@PreAuthorize
(
"hasPermission(#returnObject, 'read')"
)
public
CloudCredentials
findOne
(
String
id
)
{
public
CloudCredentials
findOne
(
String
id
)
{
CloudCredentials
creds
=
dao
.
findOne
(
id
);
CloudCredentials
creds
=
dao
.
findOne
(
id
);
return
creds
;
return
creds
;
...
@@ -63,8 +54,8 @@ public class CloudCredentialsService {
...
@@ -63,8 +54,8 @@ public class CloudCredentialsService {
dao
.
delete
(
id
);
dao
.
delete
(
id
);
}
}
@PreAuthorize
(
" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))"
)
//
@PreAuthorize(" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))")
@PostFilter
(
"(filterObject.owner == authentication.name)"
)
//
@PostFilter("(filterObject.owner == authentication.name)")
public
List
<
CloudCredentials
>
findAll
()
{
public
List
<
CloudCredentials
>
findAll
()
{
return
dao
.
findAll
();
return
dao
.
findAll
();
}
}
...
...
This diff is collapsed.
Click to expand it.
drip-api/src/main/java/nl/uva/sne/drip/commons/v1/types/OwnedObject.java
View file @
7b97e40b
...
@@ -17,7 +17,6 @@ package nl.uva.sne.drip.commons.v1.types;
...
@@ -17,7 +17,6 @@ package nl.uva.sne.drip.commons.v1.types;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.NotNull
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.stereotype.Component
;
/**
/**
*
*
...
@@ -29,23 +28,6 @@ public class OwnedObject {
...
@@ -29,23 +28,6 @@ public class OwnedObject {
@NotNull
@NotNull
private
String
owner
;
private
String
owner
;
@NotNull
private
Permissions
permissions
;
/**
* @return the permissions
*/
public
Permissions
getPermissions
()
{
return
permissions
;
}
/**
* @param permissions the permissions to set
*/
public
void
setPermissions
(
Permissions
permissions
)
{
this
.
permissions
=
permissions
;
}
/**
/**
* @return the owner
* @return the owner
*/
*/
...
...
This diff is collapsed.
Click to expand it.
drip-api/src/main/java/nl/uva/sne/drip/commons/v1/types/Permissions.java
deleted
100644 → 0
View file @
a66267cb
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
;
import
java.util.Set
;
import
javax.validation.constraints.NotNull
;
import
org.springframework.data.mongodb.core.mapping.Document
;
/**
*
* @author S. Koulouzis
*/
@Document
public
class
Permissions
{
private
Set
<
String
>
read
;
private
Set
<
String
>
write
;
/**
* @return the read
*/
public
Set
<
String
>
getRead
()
{
return
read
;
}
/**
* @param read the read to set
*/
public
void
setRead
(
Set
<
String
>
read
)
{
this
.
read
=
read
;
}
/**
* @return the write
*/
public
Set
<
String
>
getWrite
()
{
return
write
;
}
/**
* @param write the write to set
*/
public
void
setWrite
(
Set
<
String
>
write
)
{
this
.
write
=
write
;
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment