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

Android ImageView shows as the correct size for an image, but doesn't display the image
Using JGit to create a tool that clones repositories out of properties
In Spring data elasticsearch is there any clear syntax to query which mapping value is HashMap
Need to drag imageview to its boundaries
How to do Post for https using Apache client
Android Studio get location from Google Maps api
GXT Drag and drop from tree label to a widget
what is driver.findelementby(By.id(“”)) in webelement element=driver.findelementby(By.id(“”))
How to reload entity mapping file in dynamic-map mode of Hibernate without restarting the application?
ArrayList is empty after session sets the attribute
My program has no output when I attempt to find the lowest value of 3 objects [duplicate]
assign decimal value to a string in java [duplicate]
sb cannot be resolved to a variable
Why will my JAR file not run after obfuscating it with ProGuard? Main class is getting obfuscated / library
Merge two arrays and remove duplicates in Java
JavaFX samples crash or doesn't launch on linux with AMD GPU

Categories

HOME
winforms
gremlin
smarty
appx
fft
vmware
q
maven-3
twitter-bootstrap-4
ip
baqend
blueprintjs
windows-server
acquia
fancybox
cross-validation
virtualization
medical
collectd
jplayer
decomposition
percona
try-catch
jsprit
netflix
ghc
foselasticabundle
openedx
crystal-reports-2008
alpine
autocad-plugin
arabic
extjs5
realex-payments-api
crystal-reports-2010
pepper
brunch
rst2pdf
kendo-datasource
bpel
nat
nameservers
iframe-resizer
titanium-mobile
google-qpx-express-api
http-get
grails-3.1
catch-all
mozilla
unspecified
webix-treetable
ruby-on-rails-3.1
eigenvalue
isbn
bootstrap-dialog
s
websphere-mq-fte
smartcontracts
dds
colorama
csound
python-cryptography
orthogonal
smart-table
ableton-live
firmata
azure-sdk
thrust
multiple-regression
persist
nessus
php-parse-error
cloudbees
srand
wso2cloud
libressl
iis-arr
coveralls
responsive-images
createprocessasuser
processmodel
sortedlist
modalpopup
c3
qpainter
winddk
has-many-through
fluentautomation
valueconverter
rtmfp
transcoding
ember-charts
mbr
uv-mapping
gnu-smalltalk
.aspxauth
runtime.exec
type-equivalence
tinn-r
frameset
twrequest
jspinclude
transactionscope
gnu-prolog
external-accessory
genshi
rfc1123
appendto
sql-server-profiler
asp.net-mvc-areas
virtual-functions
temporal-database
zend-decorators
gacutil
commodore

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