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


Java AbstractAuthenticationToken类代码示例

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


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

示例1: 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

示例2: 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

示例3: attemptAuthentication

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
@Override
public Authentication attemptAuthentication(HttpServletRequest request,
		HttpServletResponse response) throws AuthenticationException,
		IOException, ServletException {

	String apiKeyValue = decodeParameterValue(request, API_KEY_PARAMETER_NAME);
	logger.debug("attemptAuthentication " + apiKeyValue);

	AbstractAuthenticationToken authRequest = createAuthenticationToken(
			apiKeyValue, new RestCredentials());

	// Allow subclasses to set the "details" property
	setDetails(request, authRequest);

	return this.getAuthenticationManager().authenticate(authRequest);
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:17,代码来源:RestAPIKeyAuthenticationFilter.java

示例4: getOAuth2Authentication

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
@Override
protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
    try {
        Authentication userAuth = null;
        User user = extensionGrantProvider.grant(convert(tokenRequest));
        if (user != null) {
            userAuth = new UsernamePasswordAuthenticationToken(user, "", AuthorityUtils.NO_AUTHORITIES);
            if (extensionGrant.isCreateUser()) {
                Map<String, String> parameters = new LinkedHashMap<String, String>(tokenRequest.getRequestParameters());
                parameters.put(RepositoryProviderUtils.SOURCE, extensionGrant.getIdentityProvider());
                ((AbstractAuthenticationToken) userAuth).setDetails(parameters);
                eventPublisher.publishAuthenticationSuccess(userAuth);
            }
        }

        OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest);
        return new OAuth2Authentication(storedOAuth2Request, userAuth);
    } catch (InvalidGrantException e) {
        throw new org.springframework.security.oauth2.common.exceptions.InvalidGrantException(e.getMessage(), e);
    }
}
 
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:22,代码来源:CustomTokenGranter.java

示例5: 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

示例6: refreshUserContextIfActive

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
@Override
@Transactional
public void refreshUserContextIfActive(String userName) {
    LOGGER.info("Refreshing context for user: {}", userName);

    MotechUser user = motechUsersDao.findByUserName(userName);
    Collection<HttpSession> sessions = sessionHandler.getAllSessions();

    for (HttpSession session : sessions) {
        SecurityContext context = (SecurityContext) session.getAttribute("SPRING_SECURITY_CONTEXT");

        if (context != null) {
            Authentication authentication = context.getAuthentication();
            AbstractAuthenticationToken token;
            User userInSession = (User) authentication.getPrincipal();
            if (userInSession.getUsername().equals(userName)) {
                token = getToken(authentication, user);
                context.setAuthentication(token);
            }
        }
    }
    LOGGER.info("Refreshed context for user: {}", userName);

}
 
开发者ID:motech,项目名称:motech,代码行数:25,代码来源:UserContextServiceImpl.java

示例7: attemptAuthentication

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
/**
 * Attempt to authenticate request - basically just pass over to another method to authenticate request headers
 */
@Override
public Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
	String token = null;
	if (null != request.getCookies()) {
		for (final Cookie cookie : request.getCookies()) {
			if (COOKIE_SECURITY_TOKEN.equals(cookie.getName())) {
				token = cookie.getValue();
			}
		}
	}

	if (token == null) {
		logger.info("No token found request:" + request.getRequestURI());
		throw new AuthenticationServiceException(MessageFormat.format("Error | {0}", "No Token"));
	}

	logger.info("token found:" + token + " request:" + request.getRequestURI());
	final AbstractAuthenticationToken userAuthenticationToken = authUserByToken(token);
	if (userAuthenticationToken == null) {
		throw new AuthenticationServiceException(MessageFormat.format("Error | {0}", "Bad Token"));
	}
	return userAuthenticationToken;
}
 
开发者ID:Sylvain-Bugat,项目名称:swagger-cxf-rest-skeleton,代码行数:27,代码来源:TokenAuthenticationFilter.java

示例8: createContext

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
private SecurityContext createContext(final User user) {
    SecurityContext securityContext = new SecurityContextImpl();
    securityContext.setAuthentication(new AbstractAuthenticationToken(user.getAuthorities()) {
        private static final long serialVersionUID = 1L;

        @Override
        public Object getCredentials() {
            return "N/A";
        }

        @Override
        public Object getPrincipal() {
            return user;
        }

        @Override
        public boolean isAuthenticated() {
            return true;
        }
    });
    return securityContext;
}
 
开发者ID:apache,项目名称:rave,代码行数:23,代码来源:DefaultUserService.java

示例9: getAuthenticatedUser_validUser

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
@Test
public void getAuthenticatedUser_validUser() {
    final User authUser = new UserImpl(USER_ID);
    AbstractAuthenticationToken auth = createNiceMock(AbstractAuthenticationToken.class);
    expect(auth.getPrincipal()).andReturn(authUser).anyTimes();
    replay(auth);

    SecurityContext context = new SecurityContextImpl();
    context.setAuthentication(auth);
    SecurityContextHolder.setContext(context);

    User result = service.getAuthenticatedUser();

    assertThat(result, is(sameInstance(authUser)));
    verify(auth);
}
 
开发者ID:apache,项目名称:rave,代码行数:17,代码来源:DefaultUserServiceTest.java

示例10: setup

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setup() throws SQLException {
    restOperations = EasyMock.createNiceMock(RestOperations.class);
    EasyMock.expect(restOperations.postForObject(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(Class.class)))
            .andReturn(VALID_METADATA);
    EasyMock.replay(restOperations);

    //Replace the real restOperations instance with a mock -- otherwise the call for gadget metadata would fail since
    //we don't have a shindig server available to hit.
    ReflectionTestUtils.setField(metadataRepository, "restOperations", restOperations);

    //Setup a mock authenticated user
    final User authUser = new UserImpl(VALID_USER_ID, VALID_USER_NAME);
    AbstractAuthenticationToken auth = EasyMock.createNiceMock(AbstractAuthenticationToken.class);
    EasyMock.expect(auth.getPrincipal()).andReturn(authUser).anyTimes();
    EasyMock.replay(auth);

    SecurityContext context = new SecurityContextImpl();
    context.setAuthentication(auth);
    SecurityContextHolder.setContext(context);
}
 
开发者ID:apache,项目名称:rave,代码行数:23,代码来源:RenderServiceIntegrationTest.java

示例11: 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

示例12: 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

示例13: onApplicationEvent

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof AbstractAuthenticationFailureEvent) {
        if (event.getSource() instanceof AbstractAuthenticationToken) {
            AbstractAuthenticationToken token = (AbstractAuthenticationToken) event.getSource();
            Object details = token.getDetails();
            if (details instanceof WebAuthenticationDetails) {
                LOG.info("Login failed from [" + ((WebAuthenticationDetails) details).getRemoteAddress() + "]");
            }
        }
    }

}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:14,代码来源:LoginFailureListener.java

示例14: setDetailsIfPossible

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
/**
 * Set auth details if it possible
 * @param authentication
 * @param details
 * @return  true if update details is success
 */
public static boolean setDetailsIfPossible(Authentication authentication, Object details) {
    if(authentication instanceof AbstractAuthenticationToken) {
        ((AbstractAuthenticationToken)authentication).setDetails(details);
        return true;
    }
    return false;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:14,代码来源:SecurityUtils.java

示例15: test

import org.springframework.security.authentication.AbstractAuthenticationToken; //导入依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @throws Throwable JAVADOC.
 */
@Test
public void test()
    throws Throwable {
    //create authentication
    User user = new User();

    user.setUsername("loggedin");

    //set security
    AbstractAuthenticationToken authToken = setSecurity(user, true);

    //mock systemUserService returns username
    String systemUsername = "ADMIN";

    when(systemUserService.getUsername()).thenReturn(systemUsername);

    SystemUserMethodInterceptor interceptor = new SystemUserMethodInterceptor(userAccessor,
            systemUserService);

    interceptor.invoke(methodInvocation);
    //mock authenticatioNService call
    verify(userAccessor).forceUserToContext(systemUsername);
    verify(methodInvocation).proceed();

    //test it switches back
    assertEquals(CurrentUserAccessor.currentAuthentication(), authToken);
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:33,代码来源:SystemUserMethodInterceptorTest.java


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