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
02eeeb97
Commit
02eeeb97
authored
Feb 14, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try to add AA
parent
5a5e0fe5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
162 additions
and
41 deletions
+162
-41
HelloWebSecurityConfiguration.java
.../uva/sne/drip/api/conf/HelloWebSecurityConfiguration.java
+35
-0
MongoConfig.java
...i/src/main/java/nl/uva/sne/drip/api/conf/MongoConfig.java
+2
-18
MultipartConfig.java
...c/main/java/nl/uva/sne/drip/api/conf/MultipartConfig.java
+1
-1
SecurityConfig.java
...rc/main/java/nl/uva/sne/drip/api/conf/SecurityConfig.java
+55
-12
WebAppInitializer.java
...main/java/nl/uva/sne/drip/api/conf/WebAppInitializer.java
+1
-1
UserDao.java
drip-api/src/main/java/nl/uva/sne/drip/api/dao/UserDao.java
+2
-0
UserService.java
...rc/main/java/nl/uva/sne/drip/api/service/UserService.java
+4
-6
User.java
...ons/src/main/java/nl/uva/sne/drip/commons/types/User.java
+4
-3
UserRole.java
...src/main/java/nl/uva/sne/drip/commons/types/UserRole.java
+58
-0
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/conf/HelloWebSecurityConfiguration.java
0 → 100644
View file @
02eeeb97
/*
* 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
.
api
.
conf
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
@Configuration
@EnableWebSecurity
public
class
HelloWebSecurityConfiguration
extends
WebSecurityConfigurerAdapter
{
@Autowired
public
void
configureGlobal
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
inMemoryAuthentication
()
.
withUser
(
"user"
).
password
(
"password"
).
roles
(
"USER"
);
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/conf/MongoConfig.java
View file @
02eeeb97
...
@@ -17,18 +17,12 @@ package nl.uva.sne.drip.api.conf;
...
@@ -17,18 +17,12 @@ package nl.uva.sne.drip.api.conf;
import
com.mongodb.Mongo
;
import
com.mongodb.Mongo
;
import
com.mongodb.MongoClient
;
import
com.mongodb.MongoClient
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.
Be
an
;
import
org.springframework.context.annotation.
ComponentSc
an
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.context.annotation.PropertySources
;
import
org.springframework.context.annotation.PropertySources
;
import
org.springframework.data.mongodb.MongoDbFactory
;
import
org.springframework.data.mongodb.config.AbstractMongoConfiguration
;
import
org.springframework.data.mongodb.config.AbstractMongoConfiguration
;
import
org.springframework.data.mongodb.core.convert.DbRefResolver
;
import
org.springframework.data.mongodb.core.convert.DefaultDbRefResolver
;
import
org.springframework.data.mongodb.core.convert.MappingMongoConverter
;
import
org.springframework.data.mongodb.core.mapping.MongoMappingContext
;
import
org.springframework.data.mongodb.repository.config.EnableMongoRepositories
;
import
org.springframework.data.mongodb.repository.config.EnableMongoRepositories
;
/**
/**
...
@@ -41,6 +35,7 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
...
@@ -41,6 +35,7 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
@PropertySource
(
value
=
"classpath:drip.properties"
,
ignoreResourceNotFound
=
true
),
@PropertySource
(
value
=
"classpath:drip.properties"
,
ignoreResourceNotFound
=
true
),
@PropertySource
(
value
=
"file:etc/drip.properties"
,
ignoreResourceNotFound
=
true
)
@PropertySource
(
value
=
"file:etc/drip.properties"
,
ignoreResourceNotFound
=
true
)
})
})
@ComponentScan
(
"nl.uva.sne.drip"
)
public
class
MongoConfig
extends
AbstractMongoConfiguration
{
public
class
MongoConfig
extends
AbstractMongoConfiguration
{
@Value
(
"${db.name}"
)
@Value
(
"${db.name}"
)
...
@@ -54,7 +49,6 @@ public class MongoConfig extends AbstractMongoConfiguration {
...
@@ -54,7 +49,6 @@ public class MongoConfig extends AbstractMongoConfiguration {
// private MongoDbFactory mongoFactory;
// private MongoDbFactory mongoFactory;
// @Autowired
// @Autowired
// private MongoMappingContext mongoMappingContext;
// private MongoMappingContext mongoMappingContext;
@Override
@Override
protected
String
getDatabaseName
()
{
protected
String
getDatabaseName
()
{
return
dbName
;
return
dbName
;
...
@@ -69,14 +63,4 @@ public class MongoConfig extends AbstractMongoConfiguration {
...
@@ -69,14 +63,4 @@ public class MongoConfig extends AbstractMongoConfiguration {
protected
String
getMappingBasePackage
()
{
protected
String
getMappingBasePackage
()
{
return
"nl.uva.sne.drip"
;
return
"nl.uva.sne.drip"
;
}
}
// @Bean
// public MappingMongoConverter mongoConverter() throws Exception {
// DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoFactory);
// MappingMongoConverter mongoConverter = new MappingMongoConverter(dbRefResolver, mongoMappingContext);
// mongoConverter.setMapKeyDotReplacement('\uff0E');
// mongoConverter.afterPropertiesSet();
// return mongoConverter;
// }
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/conf/Config.java
→
drip-api/src/main/java/nl/uva/sne/drip/api/conf/
Multipart
Config.java
View file @
02eeeb97
...
@@ -30,7 +30,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
...
@@ -30,7 +30,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
})
})
@EnableWebMvc
@EnableWebMvc
public
class
Config
{
public
class
Multipart
Config
{
@Bean
(
name
=
"multipartResolver"
)
@Bean
(
name
=
"multipartResolver"
)
public
CommonsMultipartResolver
createMultipartResolver
()
{
public
CommonsMultipartResolver
createMultipartResolver
()
{
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/conf/SecurityConfig.java
View file @
02eeeb97
...
@@ -15,34 +15,77 @@
...
@@ -15,34 +15,77 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
conf
;
package
nl
.
uva
.
sne
.
drip
.
api
.
conf
;
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.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
nl.uva.sne.drip.api.dao.UserDao
;
/**
/**
*
*
* @author S. Koulouzis
*/
*/
@Configuration
@EnableWebSecurity
@EnableWebSecurity
@ComponentScan
(
"nl.uva.sne.drip"
)
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Autowired
// @Autowired
public
void
configureGlobal
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
// private UserService userService;
// auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
auth
.
inMemoryAuthentication
()
// @Autowired
.
withUser
(
"user"
).
password
(
"password"
).
roles
(
"USER"
);
// private AuthenticationFailureHandlerImpl authFailureHandler;
//
// @Autowired
// private AuthenticationSuccessHandlerImpl authSuccessHandler;
@Override
protected
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
// auth
// .userDetailsService(userService).passwordEncoder(passwordEncoder());
auth
.
inMemoryAuthentication
().
withUser
(
"mkyong"
).
password
(
"123456"
).
roles
(
"USER"
);
auth
.
inMemoryAuthentication
().
withUser
(
"admin"
).
password
(
"123456"
).
roles
(
"ADMIN"
);
auth
.
inMemoryAuthentication
().
withUser
(
"dba"
).
password
(
"123456"
).
roles
(
"DBA"
);
}
}
@Bean
// @Override
public
PasswordEncoder
passwordEncoder
()
{
// protected void configure(HttpSecurity http) throws Exception {
PasswordEncoder
encoder
=
new
BCryptPasswordEncoder
();
// http
return
encoder
;
// .sessionManagement()
}
// .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
// .and()
// .exceptionHandling()
// .authenticationEntryPoint(authenticationEntryPoint())
// .accessDeniedHandler(accessDeniedHandler())
// .and();
// }
//
// @Bean(name = BeanIds.AUTHENTICATION_MANAGER)
// @Override
// public AuthenticationManager authenticationManagerBean() throws Exception {
// return super.authenticationManagerBean();
// }
////
// @Bean
// public PasswordEncoder passwordEncoder() {
// PasswordEncoder encoder = new BCryptPasswordEncoder();
// return encoder;
// }
////
// @Bean
// public AuthenticationEntryPoint authenticationEntryPoint() {
// AuthenticationEntryPoint authEp = new LoginUrlAuthenticationEntryPoint("/login.jsp");
// return authEp;
// }
//
// @Bean
// public AccessDeniedHandler accessDeniedHandler() {
// AccessDeniedHandler accessDenied = new org.springframework.security.web.access.AccessDeniedHandlerImpl();
// return accessDenied;
// }
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/conf/WebAppInitializer.java
View file @
02eeeb97
...
@@ -25,7 +25,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
...
@@ -25,7 +25,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
@Override
@Override
public
void
onStartup
(
ServletContext
servletContext
)
throws
ServletException
{
public
void
onStartup
(
ServletContext
servletContext
)
throws
ServletException
{
AnnotationConfigWebApplicationContext
ctx
=
new
AnnotationConfigWebApplicationContext
();
AnnotationConfigWebApplicationContext
ctx
=
new
AnnotationConfigWebApplicationContext
();
ctx
.
register
(
Config
.
class
);
ctx
.
register
(
Multipart
Config
.
class
);
ctx
.
register
(
MongoConfig
.
class
);
ctx
.
register
(
MongoConfig
.
class
);
// ctx.register(SecurityConfig.class);
// ctx.register(SecurityConfig.class);
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/dao/UserDao.java
View file @
02eeeb97
...
@@ -24,4 +24,6 @@ import org.springframework.data.mongodb.repository.MongoRepository;
...
@@ -24,4 +24,6 @@ import org.springframework.data.mongodb.repository.MongoRepository;
*/
*/
public
interface
UserDao
extends
MongoRepository
<
User
,
String
>
{
public
interface
UserDao
extends
MongoRepository
<
User
,
String
>
{
public
User
findByUsername
(
String
username
);
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/
rest
/UserService.java
→
drip-api/src/main/java/nl/uva/sne/drip/api/
service
/UserService.java
View file @
02eeeb97
...
@@ -13,14 +13,14 @@
...
@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
rest
;
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
import
nl.uva.sne.drip.api.dao.UserDao
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
nl.uva.sne.drip.api.dao.UserDao
;
/**
/**
*
*
...
@@ -30,13 +30,11 @@ import nl.uva.sne.drip.api.dao.UserDao;
...
@@ -30,13 +30,11 @@ import nl.uva.sne.drip.api.dao.UserDao;
public
class
UserService
implements
UserDetailsService
{
public
class
UserService
implements
UserDetailsService
{
@Autowired
@Autowired
private
UserDao
userRepository
;
UserDao
dao
;
@Override
@Override
public
UserDetails
loadUserByUsername
(
String
string
)
throws
UsernameNotFoundException
{
public
UserDetails
loadUserByUsername
(
String
string
)
throws
UsernameNotFoundException
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
//To change body of generated methods, choose Tools | Templates.
return
null
;
}
}
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/User.java
View file @
02eeeb97
...
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
...
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
...
@@ -41,7 +42,7 @@ public class User implements UserDetails {
...
@@ -41,7 +42,7 @@ public class User implements UserDetails {
@JsonIgnore
@JsonIgnore
private
String
password
;
private
String
password
;
private
List
<
String
>
roles
;
private
Set
<
UserRole
>
roles
;
private
boolean
expired
;
private
boolean
expired
;
private
boolean
nonLocked
;
private
boolean
nonLocked
;
private
boolean
credentialsNonExpired
;
private
boolean
credentialsNonExpired
;
...
@@ -59,11 +60,11 @@ public class User implements UserDetails {
...
@@ -59,11 +60,11 @@ public class User implements UserDetails {
return
false
;
return
false
;
}
}
public
List
<
String
>
getRoles
()
{
public
Set
<
UserRole
>
getRoles
()
{
return
roles
;
return
roles
;
}
}
public
void
setRoles
(
List
<
String
>
roles
)
{
public
void
setRoles
(
Set
<
UserRole
>
roles
)
{
this
.
roles
=
roles
;
this
.
roles
=
roles
;
}
}
...
...
drip-
api/src/main/java/nl/uva/sne/drip/api/conf/MessageSecurityWebApplicationInitializer
.java
→
drip-
commons/src/main/java/nl/uva/sne/drip/commons/types/UserRole
.java
View file @
02eeeb97
...
@@ -13,8 +13,46 @@
...
@@ -13,8 +13,46 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
conf
;
package
nl
.
uva
.
sne
.
drip
.
commons
.
types
;
import
org.springframework.data.mongodb.core.mapping.Document
;
/**
*
* @author S. Koulouzis
*/
@Document
public
class
UserRole
{
private
Integer
userRoleId
;
private
String
role
;
/**
* @return the userRoleId
*/
public
Integer
getUserRoleId
()
{
return
userRoleId
;
}
/**
* @param userRoleId the userRoleId to set
*/
public
void
setUserRoleId
(
Integer
userRoleId
)
{
this
.
userRoleId
=
userRoleId
;
}
/**
* @return the role
*/
public
String
getRole
()
{
return
role
;
}
/**
* @param role the role to set
*/
public
void
setRole
(
String
role
)
{
this
.
role
=
role
;
}
public
class
MessageSecurityWebApplicationInitializer
{
//extends AbstractSecurityWebApplicationInitializer {
}
}
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