java - Complex authentication in Spring Boot -


i'm trying authentication done spring boot app external provider need code 3rd party software equipment . app issues commands on external software , user credential needed connect , operate.

the authentication needs performed using username , password provided in form against active directory database (checks if user exists in company), , internal database tells app if user allowed use app , whether he's admin or not (for customizing menu bar later on). afterwards, user authenticated external software means of binary executable present on server (using processbuilder). it's bit complex that's way has because of external contraints.

furthermore, once user authenticated in 3rd party software, must pick role out of list contains roles available user. after this, connection set , have redirect user main page can use app.

the login page shows form username , password fields, , button trigger auth process , present user list of roles, , after picking 1 , clicking button role selected , user redirected home page.

the problem don't have clues implement in spring boot.

my logincontroller contains:

@inject public logincontroller(final loginservice loginservice) {     this.loginservice = loginservice; }  @requestmapping("/login.html") public modelandview getloginview() {     logger.debug("received request login view");     modelmap model = new modelmap();     model.addattribute("authenticationtypes",loginservice.getauthenticationtypes());     model.addattribute(loginservice);     return new modelandview("login", model); } 

i had working code in loginserviceimpl module using in older jsf application reuse don't know how.

like similar answer here, need create own customauthenticationprovider, must implements authenticationprovider.

for example:

@component public class customauthenticationprovider implements authenticationprovider {  @autowired private thirdpartyclient thirdpartyclient;  public void setatpclient(thirdpartyclient atpclient) {     this.thirdpartyclient = atpclient; }  @override public authentication authenticate(authentication authentication) throws authenticationexception {     string username = authentication.getname();     string password = authentication.getcredentials().tostring();       request3rd requestto = new atpauthenticaterequestdto();     requestto.setpassword(password);     requestto.setusername(username);     response3rd authenticate = this.thirdpartyclient.authenticate(requestto);      if (authenticate != null) {         list<grantedauthority> grantedauths = new arraylist<>();         grantedauths.add(new simplegrantedauthority("role_user"));         authentication auth = new usernamepasswordauthenticationtoken(authenticate.getusername(), password, grantedauths);         return auth;     } else {         return null;     } }  @override public boolean supports(class<?> authentication) {     return authentication.equals(usernamepasswordauthenticationtoken.class); }  } 

then in securityconfig class, extends websecurityconfigureradapter override in configure method:

@override public void configure(authenticationmanagerbuilder auth) throws exception {     auth.authenticationprovider(this.authenticationprovider); } 

where can autowire customauthenticationprovider created before:

@autowired private customauthenticationprovider authenticationprovider; 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -