Search in sources :

Example 1 with IndexedUserDetails

use of org.onebusaway.users.model.IndexedUserDetails 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 IndexedUserDetails

use of org.onebusaway.users.model.IndexedUserDetails in project onebusaway-application-modules by camsys.

the class AutoUserCurrentUserStrategyImpl method getCurrentUserDetails.

@Override
public IndexedUserDetails getCurrentUserDetails(boolean createUserIfAppropriate) {
    IndexedUserDetails details = super.getCurrentUserDetails(createUserIfAppropriate);
    if (details == null && createUserIfAppropriate) {
        Authentication authentication = createAuthentication();
        details = getUserDetailsForAuthentication(authentication);
        SecurityContextHolder.getContext().setAuthentication(authentication);
        RequestAndResponseContext context = RequestAndResponseContext.getContext();
        if (context != null)
            _rememberMeServices.onLoginSuccess(context.getRequest(), context.getResponse(), authentication);
    }
    return details;
}
Also used : IndexedUserDetails(org.onebusaway.users.model.IndexedUserDetails) Authentication(org.springframework.security.core.Authentication)

Example 3 with IndexedUserDetails

use of org.onebusaway.users.model.IndexedUserDetails in project onebusaway-application-modules by camsys.

the class CurrentUserServiceImpl method clearPhoneNumberRegistration.

@Override
public void clearPhoneNumberRegistration() {
    IndexedUserDetails details = _currentUserStrategy.getCurrentUserDetails(false);
    if (details == null)
        return;
    _userService.clearPhoneNumberRegistration(details.getUserIndexKey());
}
Also used : IndexedUserDetails(org.onebusaway.users.model.IndexedUserDetails)

Example 4 with IndexedUserDetails

use of org.onebusaway.users.model.IndexedUserDetails in project onebusaway-application-modules by camsys.

the class PhoneNumberLoginInterceptor method isCurrentUserLoggedInWithKey.

private boolean isCurrentUserLoggedInWithKey(UserIndexKey key) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null)
        return false;
    Object principal = authentication.getPrincipal();
    if (!(principal instanceof IndexedUserDetails))
        return false;
    IndexedUserDetails details = (IndexedUserDetails) principal;
    UserIndexKey indexKey = details.getUserIndexKey();
    return indexKey.equals(key);
}
Also used : UserIndexKey(org.onebusaway.users.model.UserIndexKey) IndexedUserDetails(org.onebusaway.users.model.IndexedUserDetails) Authentication(org.springframework.security.core.Authentication)

Example 5 with IndexedUserDetails

use of org.onebusaway.users.model.IndexedUserDetails 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)

Aggregations

IndexedUserDetails (org.onebusaway.users.model.IndexedUserDetails)8 DefaultUserAuthenticationToken (org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken)3 UserIndexKey (org.onebusaway.users.model.UserIndexKey)3 Authentication (org.springframework.security.core.Authentication)2 ActionContext (com.opensymphony.xwork2.ActionContext)1 UUID (java.util.UUID)1 AuthenticationResult (org.onebusaway.everylastlogin.server.AuthenticationResult)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1