Search in sources :

Example 1 with DefaultUserAuthenticationToken

use of org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken in project onebusaway-application-modules by camsys.

the class AutoUserCurrentUserStrategyImpl method createAuthentication.

protected Authentication createAuthentication() {
    UUID uuid = UUID.randomUUID();
    UUID credentials = UUID.randomUUID();
    UserIndexKey principal = new UserIndexKey(UserIndexTypes.WEB, uuid.toString());
    IndexedUserDetails details = _userDetailsService.getOrCreateUserForIndexKey(principal, credentials.toString(), true);
    return new DefaultUserAuthenticationToken(details);
}
Also used : UserIndexKey(org.onebusaway.users.model.UserIndexKey) IndexedUserDetails(org.onebusaway.users.model.IndexedUserDetails) DefaultUserAuthenticationToken(org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken) UUID(java.util.UUID)

Example 2 with DefaultUserAuthenticationToken

use of org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken in project onebusaway-application-modules by camsys.

the class PhoneNumberLoginInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext context = invocation.getInvocationContext();
    Map<String, Object> params = context.getParameters();
    String phoneNumber = getPhoneNumber(params);
    phoneNumber = PhoneNumberLibrary.normalizePhoneNumber(phoneNumber);
    if (phoneNumber != null && phoneNumber.length() > 0) {
        UserIndexKey key = new UserIndexKey(UserIndexTypes.PHONE_NUMBER, phoneNumber);
        if (params.containsKey(RESET_USER))
            _indexedUserDetailsService.resetUserForIndexKey(key);
        // Ensure that we have authentication, even if it's anonymous
        if (!isCurrentUserLoggedInWithKey(key)) {
            IndexedUserDetails userDetails = _indexedUserDetailsService.getOrCreateUserForIndexKey(key, "", false);
            DefaultUserAuthenticationToken token = new DefaultUserAuthenticationToken(userDetails);
            SecurityContextHolder.getContext().setAuthentication(token);
        }
    }
    return invocation.invoke();
}
Also used : UserIndexKey(org.onebusaway.users.model.UserIndexKey) IndexedUserDetails(org.onebusaway.users.model.IndexedUserDetails) DefaultUserAuthenticationToken(org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 3 with DefaultUserAuthenticationToken

use of org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken in project onebusaway-application-modules by camsys.

the class CurrentUserStrategyImpl method setCurrentUser.

@Override
public void setCurrentUser(UserIndex userIndex) {
    IndexedUserDetails userDetails = new IndexedUserDetailsImpl(_authoritiesService, userIndex);
    DefaultUserAuthenticationToken token = new DefaultUserAuthenticationToken(userDetails);
    SecurityContextHolder.getContext().setAuthentication(token);
}
Also used : IndexedUserDetails(org.onebusaway.users.model.IndexedUserDetails) DefaultUserAuthenticationToken(org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken)

Aggregations

DefaultUserAuthenticationToken (org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken)3 IndexedUserDetails (org.onebusaway.users.model.IndexedUserDetails)3 UserIndexKey (org.onebusaway.users.model.UserIndexKey)2 ActionContext (com.opensymphony.xwork2.ActionContext)1 UUID (java.util.UUID)1