-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(GMS): migrate GMS to Spring boot
* GMS: Migrate GMS Spring WebApp -> Spring Boot (embedded jetty 12) * Spring WebMvc endpoints are the default, Rest.li endpoints are secondary * Removed jetty 11 * Refactor kafka consumers startup * GMS with all embedded consumers startup <40s * Neo4j upgraded * Dgraph upgraded
- Loading branch information
1 parent
262dd76
commit 2a30b07
Showing
73 changed files
with
784 additions
and
905 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,33 @@ | ||
package security; | ||
|
||
import com.google.common.base.Preconditions; | ||
import java.util.Collections; | ||
import javax.annotation.Nonnull; | ||
import javax.naming.AuthenticationException; | ||
import javax.security.auth.callback.Callback; | ||
import javax.security.auth.callback.CallbackHandler; | ||
import javax.security.auth.callback.NameCallback; | ||
import javax.security.auth.callback.PasswordCallback; | ||
import javax.security.auth.login.LoginContext; | ||
import javax.security.auth.login.LoginException; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.eclipse.jetty.jaas.JAASLoginService; | ||
import org.eclipse.jetty.jaas.PropertyUserStoreManager; | ||
import play.Logger; | ||
import org.eclipse.jetty.security.UserPrincipal; | ||
import org.eclipse.jetty.util.security.Credential; | ||
|
||
public class AuthenticationManager { | ||
|
||
private AuthenticationManager(boolean verbose) {} | ||
private AuthenticationManager() {} // Prevent instantiation | ||
|
||
public static void authenticateJaasUser(@Nonnull String userName, @Nonnull String password) | ||
throws Exception { | ||
Preconditions.checkArgument(!StringUtils.isAnyEmpty(userName), "Username cannot be empty"); | ||
JAASLoginService jaasLoginService = new JAASLoginService("WHZ-Authentication"); | ||
PropertyUserStoreManager propertyUserStoreManager = new PropertyUserStoreManager(); | ||
propertyUserStoreManager.start(); | ||
jaasLoginService.setBeans(Collections.singletonList(propertyUserStoreManager)); | ||
JAASLoginService.INSTANCE.set(jaasLoginService); | ||
try { | ||
LoginContext lc = | ||
new LoginContext("WHZ-Authentication", new WHZCallbackHandler(userName, password)); | ||
lc.login(); | ||
} catch (LoginException le) { | ||
AuthenticationException authenticationException = | ||
new AuthenticationException(le.getMessage()); | ||
authenticationException.setRootCause(le); | ||
throw authenticationException; | ||
} | ||
} | ||
|
||
private static class WHZCallbackHandler implements CallbackHandler { | ||
private String password; | ||
private String username; | ||
|
||
private WHZCallbackHandler(@Nonnull String username, @Nonnull String password) { | ||
this.username = username; | ||
this.password = password; | ||
} | ||
try { | ||
// Create and configure credentials for authentication | ||
UserPrincipal userPrincipal = new UserPrincipal(userName, Credential.getCredential(password)); | ||
|
||
@Override | ||
public void handle(@Nonnull Callback[] callbacks) { | ||
NameCallback nc = null; | ||
PasswordCallback pc = null; | ||
for (Callback callback : callbacks) { | ||
Logger.debug( | ||
"The submitted callback is of type: " + callback.getClass() + " : " + callback); | ||
if (callback instanceof NameCallback) { | ||
nc = (NameCallback) callback; | ||
nc.setName(this.username); | ||
} else if (callback instanceof PasswordCallback) { | ||
pc = (PasswordCallback) callback; | ||
pc.setPassword(this.password.toCharArray()); | ||
} | ||
// Verify credentials | ||
if (!userPrincipal.authenticate(password)) { | ||
throw new AuthenticationException("Invalid credentials for user: " + userName); | ||
} | ||
|
||
} catch (Exception e) { | ||
AuthenticationException authenticationException = | ||
new AuthenticationException("Authentication failed"); | ||
authenticationException.setRootCause(e); | ||
throw authenticationException; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.