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


Java PreAuthenticatedAuthenticationToken.getPrincipal方法代码示例

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


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

示例1: deleteTodoItem

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
/**
 * HTTP DELETE
 */
@RequestMapping(value = "/api/todolist/{id}", method = RequestMethod.DELETE)
public ResponseEntity<String> deleteTodoItem(@PathVariable("id") int id,
                                             PreAuthenticatedAuthenticationToken authToken) {
    final UserPrincipal current = (UserPrincipal) authToken.getPrincipal();

    if (current.isMemberOf(
            new UserGroup("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "group1"))) {
        final List<TodoItem> find = todoList.stream().filter(i -> i.getID() == id).collect(Collectors.toList());
        if (!find.isEmpty()) {
            todoList.remove(todoList.indexOf(find.get(0)));
            return new ResponseEntity<>("OK", HttpStatus.OK);
        }
        return new ResponseEntity<>("Entity not found", HttpStatus.OK);
    } else {
        return new ResponseEntity<>("Access is denied", HttpStatus.OK);
    }

}
 
开发者ID:Microsoft,项目名称:azure-spring-boot,代码行数:22,代码来源:TodolistController.java

示例2: loadUserDetails

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
	String principal = (String) token.getPrincipal();

	UserDetails result = null;
	if(!Strings.isNullOrEmpty(principal)) {
		logger.debug(principal);
		String[] slices = principal.split(":");
		String email = slices[0];
		String secret = slices[1];

		try {
			AccessToken p = accessTokenService.valid(email, secret);
			result = userService.findByEmail(p.getEmail());
		} catch(Exception ex) {
			throw new UsernameNotFoundException("");
		}
	}

	return result;
}
 
开发者ID:nonocast,项目名称:todolist,代码行数:22,代码来源:ApiAuthenticationUserDetailsService.java

示例3: isUserSync

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
public static boolean isUserSync(String userSyncMRN, String userSyncO, String userSyncOU, String userSyncC) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth instanceof PreAuthenticatedAuthenticationToken) {
        log.debug("Certificate authentication of user sync'er in process");
        // Certificate authentication
        PreAuthenticatedAuthenticationToken token = (PreAuthenticatedAuthenticationToken) auth;
        // Check that the Organization name of the accessed organization and the organization in the certificate is equal
        InetOrgPerson person = ((InetOrgPerson) token.getPrincipal());
        if (userSyncMRN.equalsIgnoreCase(person.getUid()) && userSyncO.equalsIgnoreCase(person.getO())
                // Hack alert! There is no country property in this type, so we misuse PostalAddress...
                && userSyncOU.equals(person.getOu()) && userSyncC.equals(person.getPostalAddress())) {
            log.debug("User sync'er accepted!");
            return true;
        }
        log.debug("This was not the user-sync'er! " + userSyncMRN + "~" + person.getUid() + ", " + userSyncO + "~"
                + person.getO() + ", " + userSyncOU + "~" + person.getOu() + ", " + userSyncC + "~" + person.getPostalAddress());
    }
    return false;
}
 
开发者ID:MaritimeConnectivityPlatform,项目名称:IdentityRegistry,代码行数:20,代码来源:AccessControlUtil.java

示例4: loadUserDetails

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
	String xAuthToken = (String) token.getPrincipal();
	UserDetails user = preAuthenticatedTokenCacheService.getFromCache(xAuthToken);

	if (user == null) {
           throw new UsernameNotFoundException("Pre authenticated token not found : " + xAuthToken);
       } else {
           if (log.isTraceEnabled()) {
               log.trace("Retrieved user from cache: " + user.getUsername());
           }

           // we want to update the expiration date on this key because the user is actively using it
           preAuthenticatedTokenCacheService.updateExpiration(xAuthToken);
       }

	return user;
}
 
开发者ID:bjornharvold,项目名称:bearchoke,代码行数:19,代码来源:PreAuthUserDetailsService.java

示例5: loadUserDetails

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
    Mapper mapper = mappers.stream()
                           .filter(p -> p.getTester().test(token))
                           .findFirst()
                           .orElse(null);

    if (mapper != null) {
        String username = (String) token.getPrincipal();
        return mapper.getDetailsService().loadUserByUsername(username);
    } else {
        return null;
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:15,代码来源:MultiPreauthProvider.java

示例6: assertAuthenticationUserIdEquals

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
/**
 * Asserts the given actual authentication's user ID is equal to the given expected user ID
 *
 * @param expectedUserId Expected user ID
 * @param actualAuthentication Actual authentication object
 */
private void assertAuthenticationUserIdEquals(String expectedUserId, Authentication actualAuthentication)
{
    assertNotNull(actualAuthentication);
    assertEquals(PreAuthenticatedAuthenticationToken.class, actualAuthentication.getClass());
    PreAuthenticatedAuthenticationToken preAuthenticatedAuthenticationToken = (PreAuthenticatedAuthenticationToken) actualAuthentication;
    Object principal = preAuthenticatedAuthenticationToken.getPrincipal();
    assertNotNull(principal);
    assertEquals(SecurityUserWrapper.class, principal.getClass());
    SecurityUserWrapper securityUserWrapper = (SecurityUserWrapper) principal;
    assertEquals(expectedUserId, securityUserWrapper.getUsername());
    assertNotNull(securityUserWrapper.getApplicationUser());
    assertEquals(expectedUserId, securityUserWrapper.getApplicationUser().getUserId());
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:20,代码来源:BaseJavaDelegateTest.java

示例7: loadUserDetails

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException
{
    ApplicationUser user = (ApplicationUser) token.getPrincipal();

    Set<GrantedAuthority> authorities = new HashSet<>();
    // Add all functional points per given collection of user roles.
    authorities.addAll(securityHelper.mapRolesToFunctions(user.getRoles()));
    // Add all function points that are not mapped to any roles in the system.
    authorities.addAll(securityHelper.getUnrestrictedFunctions());
    SecurityUserWrapper result = new SecurityUserWrapper(user.getUserId(), "N/A", true, true, true, true, authorities, user);

    LOGGER.debug("Loaded User: " + result);
    return result;
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:16,代码来源:HerdUserDetailsService.java

示例8: authenticate

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public Authentication authenticate(final Authentication authentication) {
    if (!supports(authentication.getClass())) {
        return null;
    }

    final PreAuthenticatedAuthenticationToken token = (PreAuthenticatedAuthenticationToken) authentication;
    final Object credentials = token.getCredentials();
    final Object principal = token.getPrincipal();
    final Object tokenDetails = token.getDetails();
    final Collection<GrantedAuthority> authorities = token.getAuthorities();

    if (principal == null) {
        throw new BadCredentialsException("The provided principal and credentials are not match");
    }

    final boolean successAuthentication = calculateAuthenticationSuccess(principal, credentials, tokenDetails);

    if (successAuthentication) {
        final PreAuthenticatedAuthenticationToken successToken = new PreAuthenticatedAuthenticationToken(principal,
                credentials, authorities);
        successToken.setDetails(tokenDetails);
        return successToken;
    }

    throw new BadCredentialsException("The provided principal and credentials are not match");
}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:28,代码来源:PreAuthTokenSourceTrustAuthenticationProvider.java

示例9: loadUserDetails

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
    String apiKey = (String)token.getPrincipal();
    BulbsContextUser user = userRepository.findByApiKey(apiKey);
    if(user == null) throw new UsernameNotFoundException("User not found: " + apiKey);
    return user;
}
 
开发者ID:datenstrudel,项目名称:bulbs-core,代码行数:8,代码来源:BulbsContextUserServiceImpl.java

示例10: loadUserDetails

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
    String username = (String) token.getPrincipal();

    return detailsService.loadUserByUsername(username);
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:7,代码来源:PreauthProvider.java

示例11: authenticate

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    PreAuthenticatedAuthenticationToken auth = (PreAuthenticatedAuthenticationToken) authentication;
    String username = (String) auth.getPrincipal();
    
    LOG.debug("authenticate: " + Objects.toString(auth, ""));

    User user = userDetailsService.loadUser(username);

    ExampleAuthentication result = new ExampleAuthentication(user, user.getAuthorities());
    result.setDetails(auth.getDetails());

    LOG.debug("authenticate: " + Objects.toString(result, ""));
    
    return result;
}
 
开发者ID:takesection,项目名称:spring-boot-security-custom,代码行数:17,代码来源:ExampleAuthenticationProvider.java

示例12: hasAccessToOrg

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
public static boolean hasAccessToOrg(String orgMrn) {
    if (orgMrn == null || orgMrn.trim().isEmpty()) {
        log.debug("The orgMrn was empty!");
        return false;
    }
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    // First check if the user is a SITE_ADMIN, in which case he gets access.
    for (GrantedAuthority authority : auth.getAuthorities()) {
        String role = authority.getAuthority();
        log.debug("User has role: " + role);
        if ("ROLE_SITE_ADMIN".equals(role)) {
            return true;
        }
    }
    log.debug("User not a SITE_ADMIN");
    // Check if the user is part of the organization
    if (auth instanceof KeycloakAuthenticationToken) {
        log.debug("OIDC authentication in process");
        // Keycloak authentication
        KeycloakAuthenticationToken kat = (KeycloakAuthenticationToken) auth;
        KeycloakSecurityContext ksc = (KeycloakSecurityContext) kat.getCredentials();
        Map<String, Object> otherClaims = ksc.getToken().getOtherClaims();
        if (otherClaims.containsKey(AccessControlUtil.ORG_PROPERTY_NAME) &&
                ((String) otherClaims.get(AccessControlUtil.ORG_PROPERTY_NAME)).equalsIgnoreCase(orgMrn)) {
            log.debug("Entity from org: " + otherClaims.get(AccessControlUtil.ORG_PROPERTY_NAME) + " is in " + orgMrn);
            return true;
        }
        log.debug("Entity from org: " + otherClaims.get(AccessControlUtil.ORG_PROPERTY_NAME) + " is not in " + orgMrn);
    } else if (auth instanceof PreAuthenticatedAuthenticationToken) {
        log.debug("Certificate authentication in process");
        // Certificate authentication
        PreAuthenticatedAuthenticationToken token = (PreAuthenticatedAuthenticationToken) auth;
        // Check that the Organization name of the accessed organization and the organization in the certificate is equal
        InetOrgPerson person = ((InetOrgPerson) token.getPrincipal());
        // The O(rganization) value in the certificate is an MRN
        String certOrgMrn = person.getO();
        if (orgMrn.equalsIgnoreCase(certOrgMrn)) {
            log.debug("Entity with O=" + certOrgMrn + " is in " + orgMrn);
            return true;
        }
        log.debug("Entity with O=" + certOrgMrn + " is not in " + orgMrn);
    } else {
        log.debug("Unknown authentication method: " + auth.getClass());
    }
    return false;
}
 
开发者ID:MaritimeConnectivityPlatform,项目名称:IdentityRegistry,代码行数:47,代码来源:AccessControlUtil.java

示例13: loadUserDetails

import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken authentication) throws UsernameNotFoundException {
    return (FederatedUser) authentication.getPrincipal();
}
 
开发者ID:OpenConext,项目名称:OpenConext-pdp,代码行数:5,代码来源:ShibbolethUserDetailService.java


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