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

How to determine the number of Hardware Threads
Java live video capturing/streaming [closed]
jQuery autocompleter JSON AJAX response is lost
how to set temporary directory relative path in simple jsp file upload? FIleNotFound Exception [duplicate]
java data-structure to simulate a data tree
Why my application has less heap memory than others?
Java - Clipboard copied content disappear after program exits
problem with maven webapp-cache.xml
Differentiate events for multiple attached gwt widgets
Java string to date conversion
Function Return writing style in Java
Can't delete folder created by junit TemporaryFolderRule
EJB, Remoting between two application-servers (glassfish)
Whats the advantage of load() vs get() in Hibernate?
Java JTextArea font
in java, is it possble to name an array from a string?

Categories

HOME
sendgrid
osgi
wso2
zeromq
reflection
single-sign-on
pycharm
include
tesseract
sd-card
routes
yahoo-oauth
spring-jdbc
infragistics
ckeditor
installshield
enterprise-library-5
convolution
constraint-programming
portia
node-notifier
webrequest
gitpitch
dacpac
gnupg
messages
decomposition
ef-migrations
oracle-coherence
jtextfield
autoconf
riot.js
css-animations
traffic
entitlements
web-api-testing
maxmind
maquette
webkitspeechrecognition
gsmcomm
nouislider
iframe-resizer
uisplitview
google-sites-2016
calibre
normal-distribution
bytecode-manipulation
appfabric
disassembling
qwerty
android-fingerprint-api
cookiecutter-django
mesos-chronos
janrain
estimote
sencha-touch-2.3
wso2carbon
veracode
integrity
csound
directory-structure
python-cryptography
memory-alignment
arrow-keys
sqldf
webdriverjs
topbeat
abcpdf9
vmware-tools
yaws
freedesktop.org
tcpserver
marching-cubes
security-testing
varargs
sysinternals
sailfish-os
unity3d-gui
directoryservices
castle
bundles
didselectrowatindexpath
intentservice
mysqltuner
.aspxauth
inbox
blending
ora-00911
html4
limejs
ocunit
cisco-jtapi
pysimplesoap
errai
jquery-ui-layout
cufon
work-stealing
boost-filesystem
mercurial-server
cxxtest
suppress
avatar
spec#
lzh

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