Search in sources :

Example 1 with XmAuthenticationContext

use of com.icthh.xm.commons.security.XmAuthenticationContext in project xm-ms-entity by xm-online.

the class XmAuthContextHolderDefaultTestConfiguration method xmAuthenticationContextHolder.

@Bean
@Primary
public XmAuthenticationContextHolder xmAuthenticationContextHolder() {
    XmAuthenticationContext context = mock(XmAuthenticationContext.class);
    when(context.hasAuthentication()).thenReturn(true);
    when(context.getLogin()).thenReturn(Optional.of("testLogin"));
    when(context.getUserKey()).thenReturn(Optional.of("ACCOUNT.TEST"));
    XmAuthenticationContextHolder holder = mock(XmAuthenticationContextHolder.class);
    when(holder.getContext()).thenReturn(context);
    return holder;
}
Also used : XmAuthenticationContext(com.icthh.xm.commons.security.XmAuthenticationContext) XmAuthenticationContextHolder(com.icthh.xm.commons.security.XmAuthenticationContextHolder) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 2 with XmAuthenticationContext

use of com.icthh.xm.commons.security.XmAuthenticationContext in project xm-ms-entity by xm-online.

the class ProfileResourceIntTest method xmAuthenticationContextHolder.

@Bean
@Primary
public XmAuthenticationContextHolder xmAuthenticationContextHolder() {
    XmAuthenticationContext context = mock(XmAuthenticationContext.class);
    when(context.hasAuthentication()).thenReturn(true);
    when(context.isFullyAuthenticated()).thenReturn(true);
    when(context.getUserKey()).thenReturn(Optional.of(DEFAULT_USER_KEY));
    when(context.getRequiredUserKey()).thenReturn(DEFAULT_USER_KEY);
    XmAuthenticationContextHolder holder = mock(XmAuthenticationContextHolder.class);
    when(holder.getContext()).thenReturn(context);
    return holder;
}
Also used : XmAuthenticationContext(com.icthh.xm.commons.security.XmAuthenticationContext) XmAuthenticationContextHolder(com.icthh.xm.commons.security.XmAuthenticationContextHolder) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 3 with XmAuthenticationContext

use of com.icthh.xm.commons.security.XmAuthenticationContext in project xm-ms-entity by xm-online.

the class CommentResourceIntTest method xmAuthenticationContextHolder.

@Bean
@Primary
public XmAuthenticationContextHolder xmAuthenticationContextHolder() {
    XmAuthenticationContext context = mock(XmAuthenticationContext.class);
    when(context.hasAuthentication()).thenReturn(true);
    when(context.getLogin()).thenReturn(Optional.of("testLogin"));
    when(context.getUserKey()).thenReturn(Optional.of(DEFAULT_USER_KEY));
    XmAuthenticationContextHolder holder = mock(XmAuthenticationContextHolder.class);
    when(holder.getContext()).thenReturn(context);
    return holder;
}
Also used : XmAuthenticationContext(com.icthh.xm.commons.security.XmAuthenticationContext) XmAuthenticationContextHolder(com.icthh.xm.commons.security.XmAuthenticationContextHolder) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 4 with XmAuthenticationContext

use of com.icthh.xm.commons.security.XmAuthenticationContext in project xm-ms-entity by xm-online.

the class ProfileService method getSelfProfile.

@LogicExtensionPoint("GetSelfProfile")
@Transactional(readOnly = true)
public Profile getSelfProfile() {
    XmAuthenticationContext context = authContextHolder.getContext();
    if (!context.isFullyAuthenticated()) {
        throw new EntityNotFoundException("Can't get profile for not fully authenticated user");
    }
    String userKey = context.getRequiredUserKey();
    log.debug("Get profile for user key {}", userKey);
    Profile profile = getProfile(userKey);
    if (profile == null) {
        throw new IllegalArgumentException("Profile not found for user key " + userKey);
    }
    return profile;
}
Also used : XmAuthenticationContext(com.icthh.xm.commons.security.XmAuthenticationContext) EntityNotFoundException(com.icthh.xm.commons.exceptions.EntityNotFoundException) Profile(com.icthh.xm.ms.entity.domain.Profile) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

XmAuthenticationContext (com.icthh.xm.commons.security.XmAuthenticationContext)4 XmAuthenticationContextHolder (com.icthh.xm.commons.security.XmAuthenticationContextHolder)3 Bean (org.springframework.context.annotation.Bean)3 Primary (org.springframework.context.annotation.Primary)3 EntityNotFoundException (com.icthh.xm.commons.exceptions.EntityNotFoundException)1 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 Profile (com.icthh.xm.ms.entity.domain.Profile)1 Transactional (org.springframework.transaction.annotation.Transactional)1