本文整理汇总了Java中org.pac4j.core.profile.CommonProfile.setId方法的典型用法代码示例。如果您正苦于以下问题:Java CommonProfile.setId方法的具体用法?Java CommonProfile.setId怎么用?Java CommonProfile.setId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pac4j.core.profile.CommonProfile
的用法示例。
在下文中一共展示了CommonProfile.setId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Override
public void validate(final UsernamePasswordCredentials credentials, final WebContext context) throws HttpAction {
if (credentials == null) {
throwsException("No credential");
}
String username = credentials.getUsername();
String password = credentials.getPassword();
if (CommonHelper.isBlank(username)) {
throwsException("Username cannot be blank");
}
if (CommonHelper.isBlank(password)) {
throwsException("Password cannot be blank");
}
if (CommonHelper.areNotEquals(username, password)) {
throwsException("Username : '" + username + "' does not match password");
}
final CommonProfile profile = new CommonProfile();
profile.setId(username);
profile.addAttribute(Pac4jConstants.USERNAME, username);
credentials.setUserProfile(profile);
}
示例2: testDoubleDirectClient
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Test
public void testDoubleDirectClient() throws Exception {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final CommonProfile profile2 = new CommonProfile();
profile2.setId(VALUE);
final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
clients = NAME + "," + VALUE;
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) context.getRequestAttribute(Pac4jConstants.USER_PROFILES);
assertEquals(1, profiles.size());
assertTrue(profiles.containsValue(profile));
}
示例3: testDoubleDirectClientSupportingMultiProfile
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Test
public void testDoubleDirectClientSupportingMultiProfile() throws Exception {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final CommonProfile profile2 = new CommonProfile();
profile2.setId(VALUE);
final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
clients = NAME + "," + VALUE;
multiProfile = true;
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) context.getRequestAttribute(Pac4jConstants.USER_PROFILES);
assertEquals(2, profiles.size());
assertTrue(profiles.containsValue(profile));
assertTrue(profiles.containsValue(profile2));
}
示例4: testDoubleDirectClientChooseDirectClient
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Test
public void testDoubleDirectClientChooseDirectClient() throws Exception {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final CommonProfile profile2 = new CommonProfile();
profile2.setId(VALUE);
final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
clients = NAME + "," + VALUE;
context.addRequestParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, VALUE);
multiProfile = true;
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) context.getRequestAttribute(Pac4jConstants.USER_PROFILES);
assertEquals(1, profiles.size());
assertTrue(profiles.containsValue(profile2));
}
示例5: testReturnNewProfile
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Test
public void testReturnNewProfile() throws HttpAction {
final CommonProfile profile = new CommonProfile();
profile.setId(ID);
profile.addAttribute(KEY, VALUE);
profile.setRemembered(false);
profile.addRole(NAME);
profile.addPermission(VALUE);
profile.setClientName(CLIENT_NAME);
final Credentials credentials = new TokenCredentials(TOKEN, CLIENT_NAME);
credentials.setUserProfile(profile);
final AuthenticatorProfileCreator creator = new AuthenticatorProfileCreator();
creator.setProfileFactory(MyCommonProfile::new);
final CommonProfile profile2 = creator.create(credentials, null);
assertTrue(profile2 instanceof MyCommonProfile);
assertEquals(profile.getId(), profile2.getId());
assertEquals(profile.getAttributes(), profile2.getAttributes());
assertEquals(profile.getRoles(), profile2.getRoles());
assertEquals(profile.getPermissions(), profile2.getPermissions());
assertEquals(profile.isRemembered(), profile2.isRemembered());
assertEquals(profile.getClientName(), profile2.getClientName());
}
示例6: validate
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Override
public void validate(final TokenCredentials credentials, final WebContext context) throws HttpAction {
if (credentials == null) {
throw new CredentialsException("No credential");
}
if (!(credentials instanceof DigestCredentials)) {
throw new CredentialsException ("Unsupported credentials type " + credentials.getClass());
}
DigestCredentials digestCredentials = (DigestCredentials) credentials;
String username = digestCredentials.getUsername();
if (CommonHelper.isBlank(username)) {
throw new CredentialsException("Username cannot be blank");
}
String token = credentials.getToken();
if (CommonHelper.isBlank(token)) {
throw new CredentialsException("Token cannot be blank");
}
CommonProfile profile = new CommonProfile();
profile.setId(username);
credentials.setUserProfile(profile);
}
示例7: verifyLoadUserByUsername
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Test
public void verifyLoadUserByUsername() throws Exception {
for (final LdapEntry entry : getEntries()) {
if (entry.getAttribute("objectclass").getStringValues().contains(CAS_SERVICE_DETAILS_OBJ_CLASS)) {
final String username = getUsername(entry);
final CommonProfile profile = new CommonProfile();
profile.setId(username);
ldapAuthorizationGenerator.generate(profile);
assertTrue(hasAuthority(profile, "ROLE_ADMINISTRATORS"));
assertTrue(hasAuthority(profile, "ROLE_USERS"));
}
}
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:LdapAuthorizationGeneratorTests.java
示例8: testAlreadyAuthenticatedAndAuthorized
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Test
public void testAlreadyAuthenticatedAndAuthorized() throws Exception {
final CommonProfile profile = new CommonProfile();
profile.setId(ID);
final LinkedHashMap<String, CommonProfile> profiles = new LinkedHashMap<>();
profiles.put(NAME, profile);
context.setSessionAttribute(Pac4jConstants.USER_PROFILES, profiles);
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), new CommonProfile());
authorizers = NAME;
config.setClients(new Clients(CALLBACK_URL, indirectClient));
config.addAuthorizer(NAME, (context, prof) -> ID.equals(((CommonProfile) prof.get(0)).getId()));
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
}
示例9: testDirectClientThrowsRequiresHttpAction
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Test
public void testDirectClientThrowsRequiresHttpAction() throws Exception {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final DirectClient directClient = new MockDirectClient(NAME, () -> { throw HttpAction.status("bad request", 400, context); }, profile);
config.setClients(new Clients(CALLBACK_URL, directClient));
clients = NAME;
call();
assertEquals(400, context.getResponseStatus());
assertEquals(0, nbCall);
}
示例10: testDoubleDirectClientChooseBadDirectClient
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Test
public void testDoubleDirectClientChooseBadDirectClient() {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final CommonProfile profile2 = new CommonProfile();
profile2.setId(VALUE);
final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
clients = NAME;
context.addRequestParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, VALUE);
multiProfile = true;
TestsHelper.expectException(() -> call(), TechnicalException.class, "Client not allowed: " + VALUE);
}
示例11: test
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
private Set<String> test(final String value) {
final Properties properties = new Properties();
properties.put(USERNAME, PASSWORD + value);
final SpringSecurityPropertiesAuthorizationGenerator generator = new SpringSecurityPropertiesAuthorizationGenerator(properties);
final CommonProfile profile = new CommonProfile();
profile.setId(USERNAME);
generator.generate(profile);
return profile.getRoles();
}
示例12: validate
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Override
public void validate(final TokenCredentials credentials, final WebContext context) throws HttpAction {
if (credentials == null) {
throw new CredentialsException("credentials must not be null");
}
if (CommonHelper.isBlank(credentials.getToken())) {
throw new CredentialsException("token must not be blank");
}
final String token = credentials.getToken();
final CommonProfile profile = new CommonProfile();
profile.setId(token);
credentials.setUserProfile(profile);
}
示例13: authenticate
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Override
public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
try {
final String username = authentication.getPrincipal().toString();
final Object credentials = authentication.getCredentials();
final String password = credentials == null ? null : credentials.toString();
LOGGER.debug("Preparing LDAP authentication request for user [{}]", username);
final AuthenticationRequest request = new AuthenticationRequest(username, new org.ldaptive.Credential(password), ReturnAttributes.ALL.value());
final Authenticator authenticator = Beans.newLdaptiveAuthenticator(adminPagesSecurityProperties.getLdap());
LOGGER.debug("Executing LDAP authentication request for user [{}]", username);
final AuthenticationResponse response = authenticator.authenticate(request);
LOGGER.debug("LDAP response: [{}]", response);
if (response.getResult()) {
final LdapEntry entry = response.getLdapEntry();
final CommonProfile profile = new CommonProfile();
profile.setId(username);
entry.getAttributes().forEach(a -> profile.addAttribute(a.getName(), a.getStringValues()));
LOGGER.debug("Collected user profile [{}]", profile);
this.authorizationGenerator.generate(WebUtils.getPac4jJ2EContext(), profile);
LOGGER.debug("Assembled user profile with roles after generating authorization claims [{}]", profile);
final Collection<GrantedAuthority> authorities = new ArrayList<>();
authorities.addAll(profile.getRoles().stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()));
LOGGER.debug("List of authorities remapped from profile roles are [{}]", authorities);
final RequireAnyRoleAuthorizer authorizer = new RequireAnyRoleAuthorizer(adminPagesSecurityProperties.getAdminRoles());
LOGGER.debug("Executing authorization for expected admin roles [{}]", authorizer.getElements());
final J2EContext context = WebUtils.getPac4jJ2EContext();
if (authorizer.isAllAuthorized(context, Arrays.asList(profile))) {
return new UsernamePasswordAuthenticationToken(username, password, authorities);
}
LOGGER.warn("User [{}] is not authorized to access the requested resource allowed to roles [{}]",
username, authorizer.getElements());
} else {
LOGGER.warn("LDAP authentication response produced no results for [{}]", username);
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
throw new InsufficientAuthenticationException("Unexpected LDAP error", e);
}
throw new BadCredentialsException("Could not authenticate provided credentials");
}
示例14: getUserProfile
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
private CommonProfile getUserProfile() {
final CommonProfile profile = new CommonProfile();
profile.setId(ID);
profile.addAttribute(NAME, VALUE);
return profile;
}
示例15: validate
import org.pac4j.core.profile.CommonProfile; //导入方法依赖的package包/类
@Override
public void validate(final UsernamePasswordCredentials credentials, final WebContext context) {
final CommonProfile profile = new CommonProfile();
profile.setId(credentials.getUsername());
credentials.setUserProfile(profile);
}