Search in sources :

Example 6 with VerifiedUsernameAuthToken

use of com.enonic.xp.security.auth.VerifiedUsernameAuthToken in project xp by enonic.

the class SchedulableTaskImpl method taskContext.

private Context taskContext() {
    if (job.getUser() == null) {
        return ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.unAuthenticated()).build();
    }
    final AuthenticationInfo authInfo = OsgiSupport.withService(SecurityService.class, securityService -> {
        final VerifiedUsernameAuthToken token = new VerifiedUsernameAuthToken();
        token.setIdProvider(job.getUser().getIdProviderKey());
        token.setUsername(job.getUser().getId());
        return securityService.authenticate(token);
    });
    return ContextBuilder.from(ContextAccessor.current()).authInfo(authInfo).build();
}
Also used : VerifiedUsernameAuthToken(com.enonic.xp.security.auth.VerifiedUsernameAuthToken) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Example 7 with VerifiedUsernameAuthToken

use of com.enonic.xp.security.auth.VerifiedUsernameAuthToken in project app-auth0-idprovider by enonic.

the class Auth0LoginService method authenticate.

private void authenticate(final HttpServletRequest request, final PrincipalKey principalKey) {
    final VerifiedUsernameAuthToken verifiedUsernameAuthToken = new VerifiedUsernameAuthToken();
    verifiedUsernameAuthToken.setIdProvider(principalKey.getIdProviderKey());
    verifiedUsernameAuthToken.setUsername(principalKey.getId());
    verifiedUsernameAuthToken.setRememberMe(true);
    final AuthenticationInfo authenticationInfo = runAs(() -> securityService.authenticate(verifiedUsernameAuthToken), RoleKeys.AUTHENTICATED);
    if (authenticationInfo.isAuthenticated()) {
        final HttpSession httpSession = request.getSession(true);
        httpSession.setAttribute(authenticationInfo.getClass().getName(), authenticationInfo);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) VerifiedUsernameAuthToken(com.enonic.xp.security.auth.VerifiedUsernameAuthToken) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Aggregations

VerifiedUsernameAuthToken (com.enonic.xp.security.auth.VerifiedUsernameAuthToken)7 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)5 VerifiedEmailAuthToken (com.enonic.xp.security.auth.VerifiedEmailAuthToken)2 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)1 CreateUserParams (com.enonic.xp.security.CreateUserParams)1 IdProvider (com.enonic.xp.security.IdProvider)1 IdProviders (com.enonic.xp.security.IdProviders)1 User (com.enonic.xp.security.User)1 EmailPasswordAuthToken (com.enonic.xp.security.auth.EmailPasswordAuthToken)1 UsernamePasswordAuthToken (com.enonic.xp.security.auth.UsernamePasswordAuthToken)1 HttpSession (javax.servlet.http.HttpSession)1 Test (org.junit.jupiter.api.Test)1