當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。