Last active
May 4, 2016 06:50
-
-
Save omindu/bf09dd7cb24c3ef19ce04f27be6351a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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