AllTokensIterator.java
3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserManagementService
* javax.jcr.ItemNotFoundException
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Workspace
* javax.jcr.nodetype.NodeType
* javax.jcr.query.Query
* javax.jcr.query.QueryManager
* javax.jcr.query.QueryResult
*/
package com.day.crx.security.token.impl.helper;
import com.adobe.granite.security.user.UserManagementService;
import com.day.crx.security.token.impl.helper.Token;
import com.day.crx.security.token.impl.helper.TokenHelper;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
import javax.jcr.nodetype.NodeType;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class AllTokensIterator
implements Iterator<Token> {
private static final String REP_USER = "rep:User";
private NodeIterator tokenNodes;
private Node currentToken;
private UserManagementService userManagementService;
public AllTokensIterator(Session session, UserManagementService userManagementService) throws RepositoryException {
this.userManagementService = userManagementService;
Query q = session.getWorkspace().getQueryManager().createQuery(this.getTokenQuery(), "xpath");
this.tokenNodes = q.execute().getNodes();
this.seek();
}
@Override
public boolean hasNext() {
return this.currentToken != null;
}
@Override
public Token next() {
if (!this.hasNext()) {
throw new NoSuchElementException();
}
Token result = new Token(this.currentToken);
this.seek();
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
public String getCurrentUserName() throws RepositoryException {
return this.currentToken != null ? this.getUserName() : null;
}
public String getCurrentUserIdentifier() throws RepositoryException {
if (this.currentToken != null) {
Node parent = this.currentToken;
do {
try {
parent = parent.getParent();
continue;
}
catch (ItemNotFoundException e) {
return null;
}
} while (!"rep:User".equals(parent.getPrimaryNodeType().toString()));
return parent.getIdentifier();
}
return null;
}
private void seek() {
this.currentToken = this.tokenNodes.hasNext() ? this.tokenNodes.nextNode() : null;
}
private String getUserName() throws RepositoryException {
Node userNode = this.currentToken.getParent().getParent();
return TokenHelper.getUserName(userNode);
}
private String getTokenQuery() {
StringBuilder sb = new StringBuilder();
sb.append("/jcr:root");
if (this.userManagementService != null) {
sb.append(this.userManagementService.getUserRootPath());
}
sb.append("//element(*,rep:Token)");
return sb.toString();
}
}