Search in sources :

Example 1 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project knowledgebase-service by open-hand.

the class WorkSpaceServiceImpl method setUserSettingInfo.

private void setUserSettingInfo(Long organizationId, Long projectId, WorkSpaceInfoVO workSpaceInfoVO) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    if (customUserDetails == null) {
        return;
    }
    Long userId = customUserDetails.getUserId();
    List<UserSettingDTO> userSettingDTOList = userSettingMapper.selectByOption(organizationId, projectId, SETTING_TYPE_EDIT_MODE, userId);
    if (!userSettingDTOList.isEmpty() && userSettingDTOList.size() == 1) {
        workSpaceInfoVO.setUserSettingVO(modelMapper.map(userSettingDTOList.get(0), UserSettingVO.class));
    }
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails)

Example 2 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project knowledgebase-service by open-hand.

the class PageServiceImpl method deleteDraftContent.

@Override
public void deleteDraftContent(Long organizationId, Long projectId, Long pageId) {
    pageRepository.checkById(organizationId, projectId, pageId);
    CustomUserDetails userDetails = DetailsHelper.getUserDetails();
    if (userDetails != null) {
        Long userId = userDetails.getUserId();
        PageContentDTO pageContent = new PageContentDTO();
        pageContent.setPageId(pageId);
        pageContent.setVersionId(0L);
        pageContent.setCreatedBy(userId);
        pageContentMapper.delete(pageContent);
    }
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) PageContentDTO(io.choerodon.kb.infra.dto.PageContentDTO)

Example 3 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project choerodon-starters by open-hand.

the class AbstractAsgardConsumer method beforeInvoke.

protected void beforeInvoke(CustomUserDetails customUserDetails) {
    if (customUserDetails == null) {
        customUserDetails = new CustomUserDetails("default", "unknown", Collections.emptyList());
        customUserDetails.setUserId(0L);
        customUserDetails.setOrganizationId(0L);
        customUserDetails.setLanguage("zh_CN");
        customUserDetails.setTimeZone("CCT");
    }
    Authentication user = new UsernamePasswordAuthenticationToken("default", "N/A", Collections.emptyList());
    OAuth2Request request = new OAuth2Request(new HashMap<>(0), "", Collections.emptyList(), true, Collections.emptySet(), Collections.emptySet(), null, null, null);
    OAuth2Authentication authentication = new OAuth2Authentication(request, user);
    OAuth2AuthenticationDetails oAuth2AuthenticationDetails = new OAuth2AuthenticationDetails(new MockHttpServletRequest());
    oAuth2AuthenticationDetails.setDecodedDetails(customUserDetails);
    authentication.setDetails(oAuth2AuthenticationDetails);
    SecurityContextHolder.getContext().setAuthentication(authentication);
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) MockHttpServletRequest(io.choerodon.asgard.saga.consumer.MockHttpServletRequest) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) OAuth2AuthenticationDetails(org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails)

Example 4 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project choerodon-file by open-hand.

the class DevopsExcetionHandler method locale.

/**
 * 返回用户的语言类型
 *
 * @return Locale
 */
private Locale locale() {
    CustomUserDetails details = DetailsHelper.getUserDetails();
    Locale locale = Locale.SIMPLIFIED_CHINESE;
    if (details != null && "en_US".equals(details.getLanguage())) {
        locale = Locale.US;
    }
    return locale;
}
Also used : Locale(java.util.Locale) CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails)

Example 5 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project workflow-service by open-hand.

the class UserRegistryAspect method userRegistry.

/**
 * @param joinPoint
 * @throws Throwable
 */
@Before("userRegistry()")
public void userRegistry(JoinPoint joinPoint) {
    CustomUserDetails details = DetailsHelper.getUserDetails();
    String activitiGroup = "Group_activiti" + details.getOrganizationId();
    String[] user = { details.getUserId().toString(), "password", "ROLE_ACTIVITI_USER", activitiGroup };
    List<String> authoritiesStrings = Arrays.asList(Arrays.copyOfRange(user, 2, user.length));
    if (!((InMemoryUserDetailsManager) userDetailsService).userExists(details.getUserId().toString())) {
        ((InMemoryUserDetailsManager) userDetailsService).createUser(new User(user[0], passwordEncoder.encode(user[1]), authoritiesStrings.stream().map(s -> new SimpleGrantedAuthority(s)).collect(Collectors.toList())));
    }
    activitiUserLoginUtil.logInAs(details.getUserId().toString());
}
Also used : Arrays(java.util.Arrays) ActivitiUserLoginUtil(io.choerodon.workflow.infra.util.ActivitiUserLoginUtil) Logger(org.slf4j.Logger) DetailsHelper(io.choerodon.core.oauth.DetailsHelper) LoggerFactory(org.slf4j.LoggerFactory) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) Pointcut(org.aspectj.lang.annotation.Pointcut) Collectors(java.util.stream.Collectors) CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) List(java.util.List) Before(org.aspectj.lang.annotation.Before) Component(org.springframework.stereotype.Component) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) InMemoryUserDetailsManager(org.springframework.security.provisioning.InMemoryUserDetailsManager) Aspect(org.aspectj.lang.annotation.Aspect) JoinPoint(org.aspectj.lang.JoinPoint) CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) InMemoryUserDetailsManager(org.springframework.security.provisioning.InMemoryUserDetailsManager) Before(org.aspectj.lang.annotation.Before)

Aggregations

CustomUserDetails (io.choerodon.core.oauth.CustomUserDetails)52 CommonException (io.choerodon.core.exception.CommonException)17 DetailsHelper (io.choerodon.core.oauth.DetailsHelper)7 Collectors (java.util.stream.Collectors)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 PageRequest (io.choerodon.mybatis.pagehelper.domain.PageRequest)6 java.util (java.util)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 MockHttpServletRequest (io.choerodon.asgard.saga.consumer.MockHttpServletRequest)4 Value (org.springframework.beans.factory.annotation.Value)4 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)4 Authentication (org.springframework.security.core.Authentication)4 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)4 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)4 Service (org.springframework.stereotype.Service)4 CollectionUtils (org.springframework.util.CollectionUtils)4 IssueDetailDTO (io.choerodon.agile.infra.dto.business.IssueDetailDTO)3 Page (io.choerodon.core.domain.Page)3