use of com.enonic.xp.security.IdProviderKey in project xp by enonic.
the class AuthenticationInfoTest method testCopy.
@Test
public void testCopy() {
final User user = User.create().login("userlogin").displayName("my user").key(PrincipalKey.ofUser(IdProviderKey.from("myidprovider"), "userid")).email("user@email").modifiedTime(Instant.now(clock)).build();
final IdProviderKey idProvider = IdProviderKey.from("myStore");
final PrincipalKey group1 = PrincipalKey.ofGroup(idProvider, "group1");
final PrincipalKey group2 = PrincipalKey.from("group:myStore:group2");
final PrincipalKey role1 = PrincipalKey.from("role:administrators");
final AuthenticationInfo info = AuthenticationInfo.create().user(user).principals(group1).principals(PrincipalKeys.from(group2, role1)).build();
final AuthenticationInfo copy = AuthenticationInfo.copyOf(info).build();
assertEquals(info, copy);
assertEquals(info.hashCode(), copy.hashCode());
}
use of com.enonic.xp.security.IdProviderKey in project xp by enonic.
the class AuthenticationInfoTest method testSerializationWithUserProfile.
@Test
void testSerializationWithUserProfile() throws Exception {
final PropertySet data = new PropertySet();
data.setString("subString", "subStringValue");
data.setLong("subLong", 123L);
final PropertyTree userProfile = new PropertyTree();
userProfile.setSet("myApp", data);
userProfile.setString("string", "stringValue");
final User user = User.create().login("userlogin").displayName("my user").key(PrincipalKey.ofUser(IdProviderKey.from("myidprovider"), "userid")).email("user@email").modifiedTime(Instant.now(clock)).profile(userProfile).build();
final IdProviderKey idProvider = IdProviderKey.from("myStore");
final PrincipalKey group1 = PrincipalKey.ofGroup(idProvider, "group1");
final PrincipalKey group2 = PrincipalKey.from("group:myStore:group2");
final PrincipalKey role1 = PrincipalKey.from("role:administrators");
final AuthenticationInfo info = AuthenticationInfo.create().user(user).principals(group1).principals(PrincipalKeys.from(group2, role1)).build();
final byte[] serializedObject = serialize(info);
final AuthenticationInfo deserializedObject = (AuthenticationInfo) deserialize(serializedObject);
assertEquals(deserializedObject, info);
}
use of com.enonic.xp.security.IdProviderKey in project xp by enonic.
the class IdProviderNodeTranslator method createIdProviderFromNode.
private static IdProvider createIdProviderFromNode(final Node node) {
if (node.name().toString().equalsIgnoreCase(PrincipalKey.ROLES_NODE_NAME)) {
return null;
}
final PropertySet nodeAsSet = node.data().getRoot();
final IdProviderKey idProviderKey = IdProviderNodeTranslator.toKey(node);
final IdProvider.Builder idProvider = IdProvider.create().displayName(nodeAsSet.getString(IdProviderPropertyNames.DISPLAY_NAME_KEY)).key(idProviderKey).description(nodeAsSet.getString(IdProviderPropertyNames.DESCRIPTION_KEY));
if (nodeAsSet.hasProperty(IdProviderPropertyNames.APPLICATION)) {
final String applicationKey = nodeAsSet.getString(IdProviderPropertyNames.ID_PROVIDER_APPLICATION_KEY);
final PropertySet config = nodeAsSet.getSet(IdProviderPropertyNames.ID_PROVIDER_CONFIG_FORM_KEY);
final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(ApplicationKey.from(applicationKey)).config(config.toTree()).build();
idProvider.idProviderConfig(idProviderConfig);
} else if (IdProviderKey.system().equals(idProviderKey)) {
// TODO Remove after next dump upgrade
final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(SYSTEM_ID_PROVIDER_KEY).build();
idProvider.idProviderConfig(idProviderConfig);
}
return idProvider.build();
}
use of com.enonic.xp.security.IdProviderKey in project xp by enonic.
the class VirtualHostHandlerTest method setUp.
@BeforeEach
public void setUp() {
Mockito.when(virtualHostService.isEnabled()).thenReturn(true);
virtualHost = Mockito.mock(VirtualHost.class);
Mockito.when(virtualHost.getName()).thenReturn("a");
Mockito.when(virtualHost.getSource()).thenReturn("/a");
Mockito.when(virtualHost.getTarget()).thenReturn("/other/a");
Mockito.when(virtualHost.getHost()).thenReturn("localhost");
final IdProviderKey defaultIdProviderKey = IdProviderKey.from("default");
Mockito.when(virtualHost.getDefaultIdProviderKey()).thenReturn(defaultIdProviderKey);
Mockito.when(virtualHost.getIdProviderKeys()).thenReturn(IdProviderKeys.from(defaultIdProviderKey));
}
use of com.enonic.xp.security.IdProviderKey in project xp by enonic.
the class BasicAuthFilterTest method setup.
@BeforeEach
public void setup() {
this.request = Mockito.mock(HttpServletRequest.class);
this.response = Mockito.mock(HttpServletResponse.class);
this.chain = Mockito.mock(FilterChain.class);
this.securityService = Mockito.mock(SecurityService.class);
this.filter = new BasicAuthFilter();
this.filter.setSecurityService(this.securityService);
final IdProviderKey idProviderKey = IdProviderKey.from("store");
final IdProvider idProvider = IdProvider.create().key(idProviderKey).build();
final IdProviders idProviders = IdProviders.from(idProvider);
when(this.securityService.getIdProviders()).thenReturn(idProviders);
}
Aggregations