本文整理汇总了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;
}
示例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);
}
示例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");
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
示例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));
}