merugu / springsecurity Goto Github PK
View Code? Open in Web Editor NEWSpring security + JWT + microservies
Spring security + JWT + microservies
How to make use ActiveDirectory server instead of ldif?
How can i read user groups (OR_AdminGroup, OR_EditorGroup, OR_UserGroup) and make it into roles (ADMIN, EDITOR, USERú which i can return in response?
Thanks.
Hello,
I'm unauthorized for accessing the path /user (I have created another controller named UserController), despite I have provided the bearer token in authorization header.
The error message in the console:
Responding with unauthorized error. Message - Full authentication is required to access this resource
The message in postman:
{
"timestamp": "2020-04-20T14:13:34.030+0000",
"status": 401,
"error": "Unauthorized",
"message": "Sorry, You're not authorized to access this resource.",
"path": "/user"
}
below the controller:
@RestController
@RequestMapping("/user")
public class UserController {
@GetMapping
public ResponseEntity<String> getUser(){
return new ResponseEntity<String>("Amine", HttpStatus.OK);
}
}
The security config:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(
securedEnabled = true,
jsr250Enabled = true,
prePostEnabled = true
)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${ldap.url}")
private String ldapUrl;
@Value("${ldap.domain}")
private String ldapDomain;
@Value("${ldap.userSearchBase}")
private String ldapSearchBase;
@Value("${ldap.userGroupSearch}")
private String ldapGroupSearch;
@Value("${ldap.searchFilter}")
private String ldapSearchFilter;
@Value("${ldap.managerDn}")
private String ldapManagerDn;
@Value("${ldap.managerPassword}")
private String ldapManagerPassword;
@Autowired
private JwtAuthenticationEntryPoint unauthorizedHandler;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.cors()
.disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.authorizeRequests()
.antMatchers("/api/auth/**").permitAll()
.anyRequest().authenticated()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);;
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider())
.ldapAuthentication()
.userSearchBase(ldapSearchBase)
.groupSearchBase(ldapGroupSearch)
.userSearchFilter(ldapSearchFilter)
.ldapAuthoritiesPopulator(ldapAuthoritiesPopulator())
.contextSource()
.url(ldapUrl)
.managerDn(ldapManagerDn)
.managerPassword(ldapManagerPassword);
}
private LdapAuthoritiesPopulator ldapAuthoritiesPopulator() {
return new LdapAuthoritiesPopulator() {
@Override
public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData,
String username) {
return Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
}
};
}
@Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(ldapDomain, ldapUrl);
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
I'm thankful for any help.
Hi
Can you include example curl requests for using this app in the readme?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.