Skip to content

Instantly share code, notes, and snippets.

@omindu
Last active May 4, 2016 06:50
Show Gist options
  • Save omindu/bf09dd7cb24c3ef19ce04f27be6351a2 to your computer and use it in GitHub Desktop.
Save omindu/bf09dd7cb24c3ef19ce04f27be6351a2 to your computer and use it in GitHub Desktop.
NameCallback usernameCallback = new NameCallback("username");
PasswordCallback passwordCallback = new PasswordCallback("password", false);
usernameCallback.setName("admin");
passwordCallback.setPassword(new char[]{'a', 'd', 'm', 'i', 'n'};
Callback[] callbacks = {usernameCallback, passwordCallback};
try {
//Authentication
AuthenticationContext authenticationContext = CarbonSecurityDataHolder.getInstance().getCarbonRealmService()
.getCredentialStore().authenticate(callbacks);
user = authenticationContext.getUser();
//Authorization
user.isAuthorized(new Permission(carbonPermission.getName(), carbonPermission.getActions()));
} catch (AuthenticationFailure authenticationFailure) {
throw new LoginException("Authentication failure.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment