use of com.enonic.xp.security.auth.VerifiedEmailAuthToken in project xp by enonic.
the class SecurityServiceImplTest method testAuthenticateByEmail.
@Test
public void testAuthenticateByEmail() throws Exception {
runAsAdmin(() -> {
final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").password("password").build();
final User user = securityService.createUser(createUser);
refresh();
final VerifiedEmailAuthToken authToken = new VerifiedEmailAuthToken();
authToken.setEmail("user1@enonic.com");
authToken.setIdProvider(SYSTEM);
final AuthenticationInfo authInfo = securityService.authenticate(authToken);
assertTrue(authInfo.isAuthenticated());
assertEquals(user.getKey(), authInfo.getUser().getKey());
});
}
use of com.enonic.xp.security.auth.VerifiedEmailAuthToken in project xp by enonic.
the class SecurityServiceImpl method authenticate.
@Override
public AuthenticationInfo authenticate(final AuthenticationToken token) {
if (!(token instanceof VerifiedUsernameAuthToken) && !(token instanceof VerifiedEmailAuthToken)) {
addRandomDelay();
}
if (isSuAuthenticationEnabled(token)) {
return authenticateSu((UsernamePasswordAuthToken) token);
}
if (token.getIdProvider() != null) {
return doAuthenticate(token);
} else {
final IdProviders idProviders = callAsAuthenticated(this::getIdProviders);
for (IdProvider idProvider : idProviders) {
token.setIdProvider(idProvider.getKey());
final AuthenticationInfo authInfo = doAuthenticate(token);
if (authInfo.isAuthenticated()) {
return authInfo;
}
}
return AuthenticationInfo.unAuthenticated();
}
}
use of com.enonic.xp.security.auth.VerifiedEmailAuthToken in project xp by enonic.
the class LoginHandler method authenticate.
private AuthenticationInfo authenticate(IdProviderKey idProvider) {
AuthenticationInfo authInfo = null;
if (isValidEmail(this.user)) {
if (this.skipAuth) {
final VerifiedEmailAuthToken verifiedEmailAuthToken = new VerifiedEmailAuthToken();
verifiedEmailAuthToken.setEmail(this.user);
verifiedEmailAuthToken.setIdProvider(idProvider);
authInfo = runAsAuthenticated(() -> this.securityService.get().authenticate(verifiedEmailAuthToken));
} else {
final EmailPasswordAuthToken emailAuthToken = new EmailPasswordAuthToken();
emailAuthToken.setEmail(this.user);
emailAuthToken.setPassword(this.password);
emailAuthToken.setIdProvider(idProvider);
authInfo = runAsAuthenticated(() -> this.securityService.get().authenticate(emailAuthToken));
}
}
if (authInfo == null || !authInfo.isAuthenticated()) {
if (this.skipAuth) {
final VerifiedUsernameAuthToken usernameAuthToken = new VerifiedUsernameAuthToken();
usernameAuthToken.setUsername(this.user);
usernameAuthToken.setIdProvider(idProvider);
authInfo = runAsAuthenticated(() -> this.securityService.get().authenticate(usernameAuthToken));
} else {
final UsernamePasswordAuthToken usernameAuthToken = new UsernamePasswordAuthToken();
usernameAuthToken.setUsername(this.user);
usernameAuthToken.setPassword(this.password);
usernameAuthToken.setIdProvider(idProvider);
authInfo = runAsAuthenticated(() -> this.securityService.get().authenticate(usernameAuthToken));
}
}
return authInfo;
}
Aggregations