java


Authorization of access to resources with spring security and Angularjs


I made permission to access resources in spring security as shown in this code: "The user authentication is then from the DB"
#Configuration
#EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
#Autowired
protected void globalConfig(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception {
//auth.inMemoryAuthentication().withUser("user").password("123").roles("USER");
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("select username as principal, password as credentials, etat as actived from utilisateurs where username=?")
.authoritiesByUsernameQuery("select u.username as principal, ur.nom_role as role from utilisateurs u inner join roles ur on(u.roles_id=ur.id_role) where u.username=?")
.rolePrefix("ROLE_");
}
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.sessionManagement().maximumSessions(100).maxSessionsPreventsLogin(false).expiredUrl("/Login");
http
.authorizeRequests()
.antMatchers("/AppJS/**","/images/**","/pdf/**","/Template/**","/Views/**","/MainApp.js").permitAll()
.antMatchers("/Users/**").access("hasRole('ADMIN')")
.antMatchers("/Dashbord/**").access("hasRole('ADMIN')")
.antMatchers("/Login*").anonymous()
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/Login").permitAll()
.defaultSuccessUrl("/home")
.failureUrl("/Login?error=true")
.and().exceptionHandling().accessDeniedPage("/Access_Denied")
.and()
.logout()
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutUrl("/logout")
.permitAll()
.logoutSuccessUrl("/Login");
}
}
Subsequently, I specified the views for each URL:
#Configuration
public class MvcConfig extends WebMvcConfigurerAdapter{
#Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/Login").setViewName("Login");
registry.addViewController("/Dashbord").setViewName("home");
registry.addViewController("/logout").setViewName("Login");
registry.addViewController("/Users").setViewName("Views/ListUsers");
}
}
I used the angularJS routeProvider to keep track of URLs:
var app = angular.module('Mainapp', ['ngRoute','file-model','ui.bootstrap','ngMessages']);
app.config(function($routeProvider) {
$routeProvider
.when('/Users', {
controller:'UsersController',
templateUrl: 'Views/ListUsers'
})
.when('/Dashbord', {
controller: 'ResultController',
templateUrl: 'Views/home.html'
});
});
My problem is how to make the link of the access authorization that I
defined in spring security with the URLs of angularjs ($
routeProvider)
Thank you,
and Have a good day,
You could try enable html5mode, to get this
AngularJS: http://localhost:8080/Users
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/Users', {
controller:'UsersController',
templateUrl: 'Views/ListUsers'
})
.when('/Dashbord', {
controller: 'ResultController',
templateUrl: 'Views/home.html'
});
$locationProvider.html5Mode(true)
});
I am not sure this will meets your requirement but yes i have already did before with the use of ngPermission. Before that you need list of the roles to set in your route.
.state('view1', {
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl',
resolve: {
authorization: ["ngPermissionService", function (ngPermissionService) {
//you need to call webserivce at this level for get all user's permissions and return it.
return ngPermissionService.role(["admin"])
}]
}
});
For more details click here

Related Links

Adding values from HashSet to 2D Matrix
java , each Json documents strored in a List of String for elastic search
Can't execute python script through java while using websocket
How is the exact flow of this program with respect to the allocation of Memory?
Having trouble solving cubic equations in Java
Shorten multiple ANDs + ORs in one if-statement (+ XOR, regex)
How to use pojo to find out class level Log4J appender
Migrating from Migrate to Spring MVC 4 + Hibernate5
How to work with Blob when trying to insert image into Sqlite database?
Why can't i see the inserted data from user input?
get an item only after scroll function finish
How to count comaprisons and swaps in Quicksort in Java?
How to get only List of IDs of JSON Objects?
Why is my app terminating?
Constructing an XML with JAXB and multiple same sub-elements
java - Automatically add a JMenuItem inside a JMenu

Categories

HOME
xamarin
gitlab
asp.net-core
reflection
isabelle
smarty
layout
rsyslog
filtering
analysis
infragistics
survey
disassembler
synchronization
gnupg
midi
code-review
beyondcompare
jquery-ajaxq
sox
opennlp
vlsi
url-scheme
bootstrap-material-design
nhapi
fifo
wtx
http-get
ghost4j
html5-fullscreen
bytecode-manipulation
dosbox
adobe-premiere
objectlistview
grid.mvc
gpx
osx-mavericks
dds
logparser
powercli
integrity
drupal-6
feeds
nbconvert
jspdf-autotable
account-kit
smart-table
specrun
android-fonts
probability-density
transmitfile
lttng
sigabrt
freedesktop.org
natvis
lemon
kcachegrind
processmodel
census
e10s
javax.mail
facebook-graph-api-v2.4
dia
rake-task
codeigniter-routing
internet-connection
zend-route
flask-cors
responsive-slides
uitouch
poller
industrial
gnu-smalltalk
c18
apc
easy-install
flash-builder4.5
jplaton
batterylevel
jquery-mobile-dialog
lcs
punbb
pydot
xmlspy
invite
file-comparison
krl
inotifycollectionchanged
infrastructure
rescale
meego
ctp4
multiple-languages
3gp

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App