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
Mar 08, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added PermissionEvaluator
parent
a66267cb
Changes
7
Hide 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 @@
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
auth
;
import
nl.uva.sne.drip.commons.v1.types.OwnedObject
;
import
nl.uva.sne.drip.commons.v1.types.Use
r
;
import
org.springframework.s
tereotype.Component
;
import
java.io.Serializable
;
import
org.springframework.security.access.PermissionEvaluato
r
;
import
org.springframework.s
ecurity.core.Authentication
;
/**
*
* @author S. Koulouzis
*/
@Component
(
"PermissionChecker"
)
public
class
PermissionChecker
{
public
class
PermissionEvaluatorImp
implements
PermissionEvaluator
{
public
boolean
canRead
(
OwnedObject
obj
,
User
user
)
{
@Override
public
boolean
hasPermission
(
Authentication
a
,
Object
o
,
Object
o1
)
{
if
(!
a
.
isAuthenticated
())
{
return
false
;
}
return
false
;
}
public
boolean
isOwner
(
OwnedObject
obj
,
User
user
)
{
String
ownerid
=
obj
.
getOwner
();
return
user
.
getId
().
equals
(
ownerid
);
@Override
public
boolean
hasPermission
(
Authentication
a
,
Serializable
srlzbl
,
String
string
,
Object
o
)
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
//To change body of generated methods, choose Tools | Templates.
}
}
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 @@
*/
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.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler
;
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
*/
@EnableWebMvc
@Configuration
@ComponentScan
({
"nl.uva.sne.drip.api"
})
public
class
ConverterConfig
extends
WebMvcConfigurerAdapter
{
@EnableGlobalMethodSecurity
(
prePostEnabled
=
true
)
public
class
MethodSecurityConfig
extends
GlobalMethodSecurityConfiguration
{
@Override
protected
MethodSecurityExpressionHandler
createExpressionHandler
()
{
DefaultMethodSecurityExpressionHandler
expressionHandler
=
new
DefaultMethodSecurityExpressionHandler
();
expressionHandler
.
setPermissionEvaluator
(
new
PermissionEvaluatorImp
());
return
expressionHandler
;
}
}
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;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
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.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
...
...
@@ -75,5 +76,4 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
PasswordEncoder
encoder
=
new
BCryptPasswordEncoder
();
return
encoder
;
}
}
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 {
ctx
.
register
(
MultipartConfig
.
class
);
ctx
.
register
(
MongoConfig
.
class
);
ctx
.
register
(
SecurityConfig
.
class
);
ctx
.
register
(
Converter
Config
.
class
);
ctx
.
register
(
MethodSecurity
Config
.
class
);
ctx
.
setServletContext
(
servletContext
);
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/CloudCredentialsService.java
View file @
7b97e40b
...
...
@@ -15,15 +15,10 @@
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
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.Permissions
;
import
nl.uva.sne.drip.commons.v1.types.User
;
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.PreAuthorize
;
import
org.springframework.security.access.prepost.PreFilter
;
...
...
@@ -39,21 +34,17 @@ public class CloudCredentialsService {
@Autowired
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
)
{
Permissions
permissions
=
new
Permissions
();
// String owner = user.getUsername();
// cloudCredentials.setOwner(owner);
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
);
}
@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
)
{
CloudCredentials
creds
=
dao
.
findOne
(
id
);
return
creds
;
...
...
@@ -63,8 +54,8 @@ public class CloudCredentialsService {
dao
.
delete
(
id
);
}
@PreAuthorize
(
" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))"
)
@PostFilter
(
"(filterObject.owner == authentication.name)"
)
//
@PreAuthorize(" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))")
//
@PostFilter("(filterObject.owner == authentication.name)")
public
List
<
CloudCredentials
>
findAll
()
{
return
dao
.
findAll
();
}
...
...
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;
import
javax.validation.constraints.NotNull
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.stereotype.Component
;
/**
*
...
...
@@ -29,23 +28,6 @@ public class OwnedObject {
@NotNull
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
*/
...
...
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
;
}
}
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