use of com.enonic.xp.security.PrincipalType in project xp by enonic.
the class PrincipalKeyNodeTranslator method toKey.
public static PrincipalKey toKey(final Node node) {
final String principalId = node.name().toString();
final PropertyTree rootDataSet = node.data();
final String principalType = rootDataSet.getString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY);
final String idProviderKey = rootDataSet.getString(PrincipalPropertyNames.ID_PROVIDER_KEY);
final PrincipalType type = PrincipalType.valueOf(principalType);
switch(type) {
case USER:
return PrincipalKey.ofUser(IdProviderKey.from(idProviderKey), principalId);
case GROUP:
return PrincipalKey.ofGroup(IdProviderKey.from(idProviderKey), principalId);
case ROLE:
return PrincipalKey.ofRole(principalId);
}
throw new IllegalArgumentException("Invalid principal type in node: " + type);
}
use of com.enonic.xp.security.PrincipalType in project xp by enonic.
the class PrincipalNodeTranslator method doCreatePrincipalFromNode.
private static Principal doCreatePrincipalFromNode(final Node node) {
final PropertySet nodeAsSet = node.data().getRoot();
if (nodeAsSet.isNull(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY)) {
throw new IllegalArgumentException("Property " + PrincipalPropertyNames.PRINCIPAL_TYPE_KEY + " not found on node with id " + node.id());
}
final PrincipalType principalType = PrincipalType.valueOf(nodeAsSet.getString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY));
switch(principalType) {
case USER:
return createUserFromNode(node);
case GROUP:
return createGroupFromNode(node);
case ROLE:
return createRoleFromNode(node);
default:
throw new IllegalArgumentException("Not able to translate principal-type " + principalType);
}
}
use of com.enonic.xp.security.PrincipalType in project xp by enonic.
the class PrincipalQueryNodeQueryTranslator method translate.
public static NodeQuery translate(final PrincipalQuery principalQuery) {
final NodeQuery.Builder nodeQueryBuilder = NodeQuery.create().from(principalQuery.getFrom()).size(principalQuery.getSize());
final IdProviderKeys idProviders = principalQuery.getIdProviders();
if (idProviders.isNotEmpty()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(ID_PROVIDER_KEY).addValues(idProviders.stream().map(IdProviderKey::toString).collect(toList())).build());
}
final Set<PrincipalType> types = principalQuery.getPrincipalTypes();
if (!types.isEmpty()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(PRINCIPAL_TYPE_KEY).addValues(types.stream().map(Object::toString).collect(toList())).build());
}
final String searchText = principalQuery.getSearchText();
if (!nullToEmpty(searchText).isBlank()) {
nodeQueryBuilder.query(getQueryExpression(searchText));
}
final String email = principalQuery.getEmail();
if (!nullToEmpty(email).isBlank()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(EMAIL_KEY).addValues(email).build());
}
final String name = principalQuery.getName();
if (!nullToEmpty(name).isBlank()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(NAME_KEY).addValues(name).build());
}
final String displayName = principalQuery.getDisplayName();
if (!nullToEmpty(displayName).isBlank()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(DISPLAY_NAME_KEY).addValues(displayName).build());
}
return nodeQueryBuilder.build();
}
Aggregations