当前位置: 首页>>代码示例>>Java>>正文


Java AbstractAuthenticationToken.setDetails方法代码示例

本文整理汇总了Java中org.springframework.security.authentication.AbstractAuthenticationToken.setDetails方法的典型用法代码示例。如果您正苦于以下问题:Java AbstractAuthenticationToken.setDetails方法的具体用法?Java AbstractAuthenticationToken.setDetails怎么用?Java AbstractAuthenticationToken.setDetails使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.authentication.AbstractAuthenticationToken的用法示例。


在下文中一共展示了AbstractAuthenticationToken.setDetails方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSuccessAuthentication

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected Authentication createSuccessAuthentication(UserDetails details,
        Authentication authentication) {
    if (details == null || authentication == null) {
        return null;
    }
    AbstractAuthenticationToken auth = null;
    if (authentication instanceof UsernamePasswordAuthenticationToken) {
        auth = new UsernamePasswordAuthenticationToken(details,
                authentication.getCredentials(), details.getAuthorities());
    } else if (authentication instanceof ConfluenceAuthenticationToken) {
        auth = new ConfluenceAuthenticationToken(details,
                (String) authentication.getCredentials(), details.getAuthorities());
    }
    if (auth != null) {
        auth.setDetails(authentication.getDetails());
    }
    return auth;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:23,代码来源:ConfluenceAuthenticationProvider.java

示例2: setUp

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入方法依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @throws Exception JAVADOC.
 */
@Before
public void setUp()
    throws Exception {
    MockitoAnnotations.initMocks(this);
    interceptor = new CurrentUserChannelInterceptor(systemUserService, userAccessor);

    if (null == SecurityContextHolder.getContext()) {
        SecurityContextHolder.setContext(new SecurityContextImpl());
    }

    SecurityContext context = SecurityContextHolder.getContext();

    user = new User();
    user.setName("user");

    AbstractAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(user, null);

    authToken.setDetails("pipipi");
    context.setAuthentication(authToken);
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:26,代码来源:CurrentUserChannelInterceptorTest.java

示例3: authenticate

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    // get username and password
    String username = (authentication.getPrincipal() == null) ? "" : authentication.getName();
    String password = (authentication.getCredentials() == null) ? "" : authentication.getCredentials().toString();

    // check credentials
    if (userService.checkCredentials(username, password)) {
        // init return value
        AbstractAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, null, new ArrayList<>());

        // set user object
        authenticationToken.setDetails(userService.getUserByUsername(username));

        // return user details
        return authenticationToken;
    }

    // indicate invalid credentials
    throw new InternalAuthenticationServiceException("Unable to authenticate");
}
 
开发者ID:tblasche,项目名称:springboot-jersey-example,代码行数:22,代码来源:CustomAuthenticationProvider.java

示例4: postUser

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入方法依赖的package包/类
@RequestMapping(value = "/rest/auth", method = RequestMethod.POST, produces = {"application/json"})
@ResponseBody
public AuthenticationResultDto postUser(@RequestParam("user") String user, HttpServletRequest request) {
    AuthenticationResultDto dto = new AuthenticationResultDto();
    dto.setSessionId(request.getSession().getId());
    try {
        // Must be called from request filtered by Spring Security, otherwise SecurityContextHolder is not updated
        AbstractAuthenticationToken token = new UsernamePasswordAuthenticationToken(user, "");
        token.setDetails(new WebAuthenticationDetails(request));
        Authentication authentication = authenticationManager.authenticate(token);
        SecurityContextHolder.getContext().setAuthentication(authentication);
        dto.setSuccess(Boolean.TRUE);
        request.getSession().setAttribute("authenticated", Boolean.TRUE);
    } catch (Exception e) {
        SecurityContextHolder.getContext().setAuthentication(null);
        dto.setSuccess(Boolean.FALSE);
        request.getSession().setAttribute("authenticated", Boolean.FALSE);
    }
    return dto;
}
 
开发者ID:tveronezi,项目名称:springchat,代码行数:21,代码来源:AuthenticationRest.java

示例5: convertToAuthentication

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入方法依赖的package包/类
protected Authentication convertToAuthentication(Subject subject) {
    AbstractAuthenticationToken authToken = null;
    Set<UsernamePasswordPrincipal> principalSet  = subject.getPrincipals(UsernamePasswordPrincipal.class);
    if (principalSet.size() > 0) {
        UsernamePasswordPrincipal upp = principalSet.iterator().next();
        authToken = new UsernamePasswordAuthenticationToken(upp.getName(), upp.getPassword());
    }
    if (authToken != null) {
        Set<DomainPrincipal> auxset = subject.getPrincipals(DomainPrincipal.class);
        if (auxset.size() > 0) {
            String domain = auxset.iterator().next().getName();
            authToken.setDetails(domain);
        }
    }
    return authToken;
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:17,代码来源:UsernamePasswordAuthenticationAdapter.java

示例6: doFilter

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入方法依赖的package包/类
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
		ServletException {

	final boolean debug = logger.isDebugEnabled();
	final HttpServletRequest request = (HttpServletRequest) req;
	final HttpServletResponse response = (HttpServletResponse) res;

	try {
		
		Authentication authentication = tokenExtractor.extract(request);

		if (authentication == null) {
			if (debug) {
				logger.debug("No token in request, will continue chain.");
			}
		}
		else {
			request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_VALUE, authentication.getPrincipal());
			if (authentication instanceof AbstractAuthenticationToken) {
				AbstractAuthenticationToken needsDetails = (AbstractAuthenticationToken) authentication;
				needsDetails.setDetails(authenticationDetailsSource.buildDetails(request));					
			}
			Authentication authResult = authenticationManager.authenticate(authentication);

			if (debug) {
				logger.debug("Authentication success: " + authResult);
			}

			SecurityContextHolder.getContext().setAuthentication(authResult);

		}
	}
	catch (OAuth2Exception failed) {
		SecurityContextHolder.clearContext();

		if (debug) {
			logger.debug("Authentication request failed: " + failed);
		}

		authenticationEntryPoint.commence(request, response,
				new InsufficientAuthenticationException(failed.getMessage(), failed));

		return;
	}

	chain.doFilter(request, response);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:48,代码来源:OAuth2AuthenticationProcessingFilter.java

示例7: setDetails

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入方法依赖的package包/类
/**
 * Provided so that subclasses may configure what is put into the
 * authentication request's details property.
 *
 * @param request
 *            that an authentication request is being created for
 * @param authRequest
 *            the authentication request object that should have its details
 *            set
 */
protected void setDetails(HttpServletRequest request,
		AbstractAuthenticationToken authRequest) {
	authRequest.setDetails(authenticationDetailsSource
			.buildDetails(request));
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:16,代码来源:RestAPIKeyAuthenticationFilter.java

示例8: setDetails

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入方法依赖的package包/类
/**
 * Provided so that subclasses may configure what is put into the authentication request's details
 * property.
 *
 * @param request that an authentication request is being created for
 * @param authRequest the authentication request object that should have its details set
 */
protected void setDetails(HttpServletRequest request, AbstractAuthenticationToken authRequest) {
    authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:11,代码来源:UrAuthenticationProcessingFilter.java


注:本文中的org.springframework.security.authentication.AbstractAuthenticationToken.setDetails方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。