keycloak
公開メンバ関数 | 限定公開メンバ関数 | 静的関数 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory クラス
org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory の継承関係図
Inheritance graph
org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory 連携図
Collaboration graph

公開メンバ関数

GenericPrincipal createPrincipal (Realm realm, final Principal identity, final Set< String > roleSet)
 

限定公開メンバ関数

GenericPrincipal createPrincipal (Principal userPrincipal, List< String > roles)
 
Principal getPrincipal (Subject subject)
 
Group createGroup (String name, Set< Principal > principals)
 
Group [] getRoleSets (Collection< String > roleSet)
 

静的関数

static Constructor findJBossGenericPrincipalConstructor ()
 

静的非公開変数類

static Constructor jbossWebPrincipalConstructor = findJBossGenericPrincipalConstructor()
 

詳解

著者
Bill Burke
バージョン
Revision
1

関数詳解

◆ createGroup()

Group org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory.createGroup ( String  name,
Set< Principal >  principals 
)
inlineprotected
140  {
141  Group roles = null;
142  Iterator<Principal> iter = principals.iterator();
143  while (iter.hasNext()) {
144  Object next = iter.next();
145  if (!(next instanceof Group))
146  continue;
147  Group grp = (Group) next;
148  if (grp.getName().equals(name)) {
149  roles = grp;
150  break;
151  }
152  }
153  // If we did not find a group create one
154  if (roles == null) {
155  roles = new SimpleGroup(name);
156  principals.add(roles);
157  }
158  return roles;
159  }

◆ createPrincipal() [1/2]

GenericPrincipal org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory.createPrincipal ( Principal  userPrincipal,
List< String >  roles 
)
inlineprotected
52  {
53  return null;
54  }

◆ createPrincipal() [2/2]

GenericPrincipal org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory.createPrincipal ( Realm  realm,
final Principal  identity,
final Set< String >  roleSet 
)
inline
57  {
58  KeycloakAccount account = new KeycloakAccount() {
59  @Override
60  public Principal getPrincipal() {
61  return identity;
62  }
63 
64  @Override
65  public Set<String> getRoles() {
66  return roleSet;
67  }
68  };
69  Subject subject = new Subject();
70  Set<Principal> principals = subject.getPrincipals();
71  principals.add(identity);
72  Group[] roleSets = getRoleSets(roleSet);
73  for (int g = 0; g < roleSets.length; g++) {
74  Group group = roleSets[g];
75  String name = group.getName();
76  Group subjectGroup = createGroup(name, principals);
77  if (subjectGroup instanceof NestableGroup) {
78  /* A NestableGroup only allows Groups to be added to it so we
79  need to add a SimpleGroup to subjectRoles to contain the roles
80  */
81  SimpleGroup tmp = new SimpleGroup("Roles");
82  subjectGroup.addMember(tmp);
83  subjectGroup = tmp;
84  }
85  // Copy the group members to the Subject group
86  Enumeration<? extends Principal> members = group.members();
87  while (members.hasMoreElements()) {
88  Principal role = (Principal) members.nextElement();
89  subjectGroup.addMember(role);
90  }
91  }
92  // add the CallerPrincipal group if none has been added in getRoleSets
93  Group callerGroup = new SimpleGroup(SecurityConstants.CALLER_PRINCIPAL_GROUP);
94  callerGroup.addMember(identity);
95  principals.add(callerGroup);
96  SecurityContext sc = SecurityContextAssociation.getSecurityContext();
97  Principal userPrincipal = getPrincipal(subject);
98  sc.getUtil().createSubjectInfo(userPrincipal, account, subject);
99  List<String> rolesAsStringList = new ArrayList<String>();
100  rolesAsStringList.addAll(roleSet);
101 
102  try {
103  return (GenericPrincipal) jbossWebPrincipalConstructor.newInstance(realm, userPrincipal.getName(), null, rolesAsStringList, userPrincipal, null, account, null, subject);
104  } catch (Throwable t) {
105  throw new RuntimeException("Failed to create JBossGenericPrincipal", t);
106  }
107  }
Group createGroup(String name, Set< Principal > principals)
Definition: JBossWebPrincipalFactory.java:140
static Constructor jbossWebPrincipalConstructor
Definition: JBossWebPrincipalFactory.java:49
Group [] getRoleSets(Collection< String > roleSet)
Definition: JBossWebPrincipalFactory.java:161
Principal getPrincipal(Subject subject)
Definition: JBossWebPrincipalFactory.java:116

◆ findJBossGenericPrincipalConstructor()

static Constructor org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory.findJBossGenericPrincipalConstructor ( )
inlinestaticpackage
170  {
171  for (Constructor<?> c : JBossGenericPrincipal.class.getConstructors()) {
172  if (c.getParameterTypes().length == 9 &&
173  c.getParameterTypes()[0].equals(Realm.class) &&
174  c.getParameterTypes()[1].equals(String.class) &&
175  c.getParameterTypes()[3].equals(List.class) &&
176  c.getParameterTypes()[4].equals(Principal.class) &&
177  c.getParameterTypes()[6].equals(Object.class) &&
178  c.getParameterTypes()[8].equals(Subject.class)) {
179  return c;
180  }
181  }
182  return null;
183  }

◆ getPrincipal()

Principal org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory.getPrincipal ( Subject  subject)
inlineprotected

Get the Principal given the authenticated Subject. Currently the first subject that is not of type

Group

is considered or the single subject inside the CallerPrincipal group.

引数
subject
戻り値
the authenticated subject
116  {
117  Principal principal = null;
118  Principal callerPrincipal = null;
119  if (subject != null) {
120  Set<Principal> principals = subject.getPrincipals();
121  if (principals != null && !principals.isEmpty()) {
122  for (Principal p : principals) {
123  if (!(p instanceof Group) && principal == null) {
124  principal = p;
125  }
126  if (p instanceof Group) {
127  Group g = Group.class.cast(p);
128  if (g.getName().equals(SecurityConstants.CALLER_PRINCIPAL_GROUP) && callerPrincipal == null) {
129  Enumeration<? extends Principal> e = g.members();
130  if (e.hasMoreElements())
131  callerPrincipal = e.nextElement();
132  }
133  }
134  }
135  }
136  }
137  return callerPrincipal == null ? principal : callerPrincipal;
138  }

◆ getRoleSets()

Group [] org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory.getRoleSets ( Collection< String >  roleSet)
inlineprotected
161  {
162  SimpleGroup roles = new SimpleGroup("Roles");
163  Group[] roleSets = {roles};
164  for (String role : roleSet) {
165  roles.addMember(new SimplePrincipal(role));
166  }
167  return roleSets;
168  }

メンバ詳解

◆ jbossWebPrincipalConstructor

Constructor org.keycloak.adapters.jbossweb.JBossWebPrincipalFactory.jbossWebPrincipalConstructor = findJBossGenericPrincipalConstructor()
staticprivate

このクラス詳解は次のファイルから抽出されました: