gluu
公開メンバ関数 | 静的公開メンバ関数 | 静的関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.gluu.oxtrust.util.ServiceUtil クラス
org.gluu.oxtrust.util.ServiceUtil の継承関係図
Inheritance graph
org.gluu.oxtrust.util.ServiceUtil 連携図
Collaboration graph

公開メンバ関数

void deleteGroupFromPerson (GluuGroup group, String dn) throws Exception
 
String iterableToString (Iterable<?> list)
 
void deleteUserFromGroup (GluuCustomPerson person, String dn) throws Exception
 
void personMembersAdder (GluuGroup gluuGroup, String dn) throws Exception
 
void groupMembersAdder (GluuCustomPerson gluuPerson, String dn) throws Exception
 
String getPersonParentInum ()
 
String getPersonParentIname ()
 
byte [] copyUploadedFile (UploadedFile uploadedFile) throws IOException
 
String saveUploadedFile (UploadedFile uploadedFile, String baseDir, String extension) throws IOException
 

静的公開メンバ関数

static String saveRandomFile (byte[] array, String baseDir, String extension) throws IOException
 
static GluuCustomPerson syncEmailForward (GluuCustomPerson gluuCustomPerson, boolean isScim2) throws Exception
 
static GluuCustomPerson syncEmailReverse (GluuCustomPerson gluuCustomPerson, boolean isScim2) throws Exception
 
static ObjectMapper getObjectMapper ()
 
static byte [] readFully (InputStream is) throws IOException
 

静的関数

 [static initializer]
 

非公開メンバ関数

boolean isMemberOfExist (List< String > groups, String dn)
 
boolean isMemberExist (List< String > groupMembers, String dn)
 

非公開変数類

IPersonService personService
 
IGroupService groupService
 
AppConfiguration appConfiguration
 

静的非公開変数類

static Logger logger = LoggerFactory.getLogger(ServiceUtil.class)
 
static final long serialVersionUID = -2842459224631032594L
 
static final SecureRandom random = new SecureRandom()
 
static final ObjectMapper mapper = new ObjectMapper()
 

詳解

User: Dejan Maric

関数詳解

◆ [static initializer]()

org.gluu.oxtrust.util.ServiceUtil.[static initializer] ( )
inlinestaticpackage

◆ copyUploadedFile()

byte [] org.gluu.oxtrust.util.ServiceUtil.copyUploadedFile ( UploadedFile  uploadedFile) throws IOException
inline

Copy uploaded file to byte array.

引数
uploadedFile
戻り値
byte array
例外
IOException
274  {
275 
276  InputStream in = uploadedFile.getInputStream();
277  ByteArrayOutputStream out = new ByteArrayOutputStream();
278  try {
279  int b;
280  while ((b = in.read()) != -1) {
281  out.write(b);
282  }
283  } finally {
284  out.close();
285  in.close();
286  }
287  return out.toByteArray();
288  }

◆ deleteGroupFromPerson()

void org.gluu.oxtrust.util.ServiceUtil.deleteGroupFromPerson ( GluuGroup  group,
String  dn 
) throws Exception
inline

Delete a Group from a Person

戻り値
void
例外
Exception
75  {
76  List<String> persons = group.getMembers();
77  for (String onePerson : persons) {
78 
79  GluuCustomPerson gluuPerson = personService.getPersonByDn(onePerson);
80  List<String> memberOflist = gluuPerson.getMemberOf();
81 
82  List<String> tempMemberOf = new ArrayList<String>();
83  for (String aMemberOf : memberOflist) {
84  tempMemberOf.add(aMemberOf);
85  }
86 
87  for (String oneMemberOf : tempMemberOf) {
88  if (oneMemberOf.equalsIgnoreCase(dn)) {
89  tempMemberOf.remove(oneMemberOf);
90  break;
91  }
92  }
93 
94  List<String> cleanMemberOf = new ArrayList<String>();
95 
96  for (String aMemberOf : tempMemberOf) {
97  cleanMemberOf.add(aMemberOf);
98  }
99 
100  gluuPerson.setMemberOf(cleanMemberOf);
101  personService.updatePerson(gluuPerson);
102 
103  }
104 
105  }
abstract void updatePerson(GluuCustomPerson person)
abstract GluuCustomPerson getPersonByDn(String dn)
IPersonService personService
Definition: ServiceUtil.java:52
List< String > getMemberOf()
Definition: GluuCustomPerson.java:168

◆ deleteUserFromGroup()

void org.gluu.oxtrust.util.ServiceUtil.deleteUserFromGroup ( GluuCustomPerson  person,
String  dn 
) throws Exception
inline

Delete a person from a group

戻り値
void
例外
Exception
129  {
130  List<String> groups = person.getMemberOf();
131  for (String oneGroup : groups) {
132 
133  GluuGroup aGroup = groupService.getGroupByDn(oneGroup);
134  List<String> groupMembers = aGroup.getMembers();
135 
136  List<String> tempGroupMembers = new ArrayList<String>();
137  if (groupMembers != null && !groupMembers.isEmpty()) {
138  for (String aMember : groupMembers) {
139  tempGroupMembers.add(aMember);
140  }
141  }
142 
143  for (String oneMember : tempGroupMembers) {
144 
145  if (oneMember.equalsIgnoreCase(dn)) {
146 
147  tempGroupMembers.remove(oneMember);
148 
149  break;
150  }
151  }
152 
153  List<String> cleanGroupMembers = new ArrayList<String>();
154  for (String aMember : tempGroupMembers) {
155  cleanGroupMembers.add(aMember);
156  }
157 
158  aGroup.setMembers(cleanGroupMembers);
159 
160  if (aGroup.getMembers() != null && aGroup.getMembers().isEmpty()) {
161  aGroup.setMembers(null); // Reset to no members
162  }
163 
164  groupService.updateGroup(aGroup);
165  }
166  }
abstract GluuGroup getGroupByDn(String Dn)
IGroupService groupService
Definition: ServiceUtil.java:55
List< String > getMembers()
Definition: GluuGroup.java:118
abstract void updateGroup(GluuGroup group)

◆ getObjectMapper()

static ObjectMapper org.gluu.oxtrust.util.ServiceUtil.getObjectMapper ( )
inlinestatic
447  {
448  return mapper;
449  }
static final ObjectMapper mapper
Definition: ServiceUtil.java:62

◆ getPersonParentIname()

String org.gluu.oxtrust.util.ServiceUtil.getPersonParentIname ( )
inline
262  {
263  return appConfiguration.getOrgIname() + OxTrustConstants.inameDelimiter
264  + OxTrustConstants.INAME_PERSON_OBJECTTYPE;
265  }
AppConfiguration appConfiguration
Definition: ServiceUtil.java:58

◆ getPersonParentInum()

String org.gluu.oxtrust.util.ServiceUtil.getPersonParentInum ( )
inline
257  {
258  return appConfiguration.getOrgInum() + OxTrustConstants.inumDelimiter
259  + OxTrustConstants.INUM_PERSON_OBJECTTYPE;
260  }
AppConfiguration appConfiguration
Definition: ServiceUtil.java:58

◆ groupMembersAdder()

void org.gluu.oxtrust.util.ServiceUtil.groupMembersAdder ( GluuCustomPerson  gluuPerson,
String  dn 
) throws Exception
inline

Adds a person to a group

戻り値
void
例外
Exception
218  {
219  List<String> groups = gluuPerson.getMemberOf();
220 
221  for (String group : groups) {
222 
223  GluuGroup oneGroup = groupService.getGroupByDn(group);
224 
225  List<String> groupMembers = oneGroup.getMembers();
226 
227  if ((groupMembers != null && !groupMembers.isEmpty()) && !isMemberExist(groupMembers, dn)) {
228 
229  List<String> cleanGroupMembers = new ArrayList<String>();
230  cleanGroupMembers.add(dn);
231 
232  for (String personDN : groupMembers) {
233  cleanGroupMembers.add(personDN);
234  }
235 
236  oneGroup.setMembers(cleanGroupMembers);
237  groupService.updateGroup(oneGroup);
238  }
239  }
240  }
abstract GluuGroup getGroupByDn(String Dn)
IGroupService groupService
Definition: ServiceUtil.java:55
List< String > getMembers()
Definition: GluuGroup.java:118
abstract void updateGroup(GluuGroup group)
boolean isMemberExist(List< String > groupMembers, String dn)
Definition: ServiceUtil.java:247

◆ isMemberExist()

boolean org.gluu.oxtrust.util.ServiceUtil.isMemberExist ( List< String >  groupMembers,
String  dn 
)
inlineprivate

checks if the member already exist in a group

戻り値
boolean
247  {
248 
249  for (String member : groupMembers) {
250  if (member.equalsIgnoreCase(dn)) {
251  return true;
252  }
253  }
254  return false;
255  }

◆ isMemberOfExist()

boolean org.gluu.oxtrust.util.ServiceUtil.isMemberOfExist ( List< String >  groups,
String  dn 
)
inlineprivate

checks if the memeberOf attribute already contains a given group

戻り値
boolean
202  {
203  for (String group : groups) {
204  if (group.equalsIgnoreCase(dn)) {
205  return true;
206  }
207 
208  }
209  return false;
210  }

◆ iterableToString()

String org.gluu.oxtrust.util.ServiceUtil.iterableToString ( Iterable<?>  list)
inline
107  {
108  if (list == null) {
109  return "";
110  }
111 
112  StringBuilder sb = new StringBuilder();
113  for (Object item : list) {
114  sb.append(item);
115  sb.append(",");
116  }
117  if (sb.length() > 0) {
118  sb.deleteCharAt(sb.length() - 1);
119  }
120  return sb.toString();
121  }

◆ personMembersAdder()

void org.gluu.oxtrust.util.ServiceUtil.personMembersAdder ( GluuGroup  gluuGroup,
String  dn 
) throws Exception
inline

Adds a group to a person's memberOf

戻り値
void
例外
Exception
174  {
175  List<String> members = gluuGroup.getMembers();
176 
177  for (String member : members) {
178  GluuCustomPerson gluuPerson = personService.getPersonByDn(member);
179 
180  List<String> groups = gluuPerson.getMemberOf();
181  if (!isMemberOfExist(groups, dn)) {
182 
183  List<String> cleanGroups = new ArrayList<String>();
184  cleanGroups.add(dn);
185  for (String aGroup : groups) {
186  cleanGroups.add(aGroup);
187  }
188 
189  gluuPerson.setMemberOf(cleanGroups);
190  personService.updatePerson(gluuPerson);
191  }
192 
193  }
194 
195  }
boolean isMemberOfExist(List< String > groups, String dn)
Definition: ServiceUtil.java:202
abstract void updatePerson(GluuCustomPerson person)
abstract GluuCustomPerson getPersonByDn(String dn)
IPersonService personService
Definition: ServiceUtil.java:52
List< String > getMemberOf()
Definition: GluuCustomPerson.java:168

◆ readFully()

static byte [] org.gluu.oxtrust.util.ServiceUtil.readFully ( InputStream  is) throws IOException
inlinestatic

Read all bytes from the supplied input stream. Closes the input stream.

引数
isInput stream
戻り値
All bytes
例外
IOExceptionIf an I/O problem occurs
458  {
459  ByteArrayOutputStream baos = null;
460 
461  try {
462  baos = new ByteArrayOutputStream();
463 
464  byte[] buffer = new byte[2048];
465  int read = 0;
466 
467  while ((read = is.read(buffer)) != -1) {
468  baos.write(buffer, 0, read);
469  }
470 
471  return baos.toByteArray();
472  } finally {
473  IOUtils.closeQuietly(baos);
474  IOUtils.closeQuietly(is);
475  }
476  }

◆ saveRandomFile()

static String org.gluu.oxtrust.util.ServiceUtil.saveRandomFile ( byte []  array,
String  baseDir,
String  extension 
) throws IOException
inlinestatic

Save file with random name with provided base directory and extension.

引数
arraybinary content of file.
baseDirWrite to directory.
extensionFilename extension.
戻り値
Return full path
例外
IOException
298  {
299  final String filepath = baseDir + File.separator + Math.abs(random.nextLong()) + "." + extension;
300 
301  final File dir = new File(baseDir);
302  if (!dir.exists())
303  dir.mkdirs();
304  else if (!dir.isDirectory())
305  throw new IllegalArgumentException("parameter baseDir should be directory. The value: " + baseDir);
306 
307  InputStream in = new ByteArrayInputStream(array);
308  FileOutputStream out = new FileOutputStream(filepath);
309  try {
310  int b;
311  while ((b = in.read()) != -1) {
312  out.write(b);
313  }
314  } finally {
315  in.close();
316  out.close();
317  }
318  return filepath;
319  }
static final SecureRandom random
Definition: ServiceUtil.java:60

◆ saveUploadedFile()

String org.gluu.oxtrust.util.ServiceUtil.saveUploadedFile ( UploadedFile  uploadedFile,
String  baseDir,
String  extension 
) throws IOException
inline

Save uploaded file with random name.

引数
uploadedFile
baseDirWrite to directory.
extensionFilename extension.
戻り値
Return full path
例外
IOException
329  {
330  byte[] fileContent = copyUploadedFile(uploadedFile);
331 
332  return saveRandomFile(fileContent, baseDir, extension);
333  }
static String saveRandomFile(byte[] array, String baseDir, String extension)
Definition: ServiceUtil.java:298
byte [] copyUploadedFile(UploadedFile uploadedFile)
Definition: ServiceUtil.java:274

◆ syncEmailForward()

static GluuCustomPerson org.gluu.oxtrust.util.ServiceUtil.syncEmailForward ( GluuCustomPerson  gluuCustomPerson,
boolean  isScim2 
) throws Exception
inlinestatic

One-way sync from "oxTrustEmail" to "mail". Ultimately this is persisted so "mail" will be updated by values from "oxTrustEmail".

引数
gluuCustomPerson
戻り値
例外
Exception
343  {
344 
345  logger.info(" IN Utils.syncEmailForward()...");
346 
347  GluuCustomAttribute oxTrustEmail = gluuCustomPerson.getGluuCustomAttribute("oxTrustEmail");
348 
349  if (oxTrustEmail != null && oxTrustEmail.getValues()!=null && oxTrustEmail.getValues().length > 0) {
350 
351  String[] oxTrustEmails = oxTrustEmail.getValues(); // JSON array in element 0
352  String[] newMails = new String[oxTrustEmails.length];
353 
354  ObjectMapper mapper = getObjectMapper();
355 
356  if (isScim2) {
357 
358  for (int i = 0; i < oxTrustEmails.length; i++) {
359  newMails[i] = mapper.readValue(oxTrustEmails[i], Email.class).getValue();
360  }
361 
362  }
363  gluuCustomPerson.setAttribute("mail", newMails);
364  }
365 
366  logger.info(" LEAVING Utils.syncEmailForward()...");
367 
368  return gluuCustomPerson;
369  }
static Logger logger
Definition: ServiceUtil.java:47
static ObjectMapper getObjectMapper()
Definition: ServiceUtil.java:447
static final ObjectMapper mapper
Definition: ServiceUtil.java:62

◆ syncEmailReverse()

static GluuCustomPerson org.gluu.oxtrust.util.ServiceUtil.syncEmailReverse ( GluuCustomPerson  gluuCustomPerson,
boolean  isScim2 
) throws Exception
inlinestatic

One-way sync from "mail" to "oxTrustEmail". This method takes current values of "oxTrustEmail" attribute, deletes those that do not match any of those in "mail", and adds new ones that are missing.

引数
gluuCustomPerson
isScim2
戻り値
例外
Exception
379  {
380 
381  /*
382  Implementation of this method could not be simplified to creating a new empty list for oxTrustEmail and then do
383  the respective additions based on current mail values since information such as display, primary, etc. would be lost.
384  Instead, it uses set operations to know which existing entries must be removed or retained, and then apply additions
385  of new data.
386  */
387  logger.info(" IN Utils.syncEmailReverse()...");
388 
389  GluuCustomAttribute mail = gluuCustomPerson.getGluuCustomAttribute("mail");
390  GluuCustomAttribute oxTrustEmail = gluuCustomPerson.getGluuCustomAttribute("oxTrustEmail");
391 
392  if (mail == null) {
393  gluuCustomPerson.setAttribute("oxTrustEmail", new String[0]);
394  }
395  else{
396  ObjectMapper mapper = getObjectMapper();
397 
398  Set<String> mailSet=new HashSet<String>();
399  if (mail.getValues()!=null)
400  mailSet.addAll(Arrays.asList(mail.getValues()));
401 
402  Set<String> mailSetCopy=new HashSet<String>(mailSet);
403  Set<String> oxTrustEmailSet =new HashSet<String>();
404  List<Email> oxTrustEmails=new ArrayList<Email>();
405 
406  if (oxTrustEmail!=null && oxTrustEmail.getValues()!=null){
407  for (String oxTrustEmailJson : oxTrustEmail.getValues())
408  oxTrustEmails.add(mapper.readValue(oxTrustEmailJson, Email.class));
409 
410  for (Email email : oxTrustEmails)
411  oxTrustEmailSet.add(email.getValue());
412  }
413  mailSetCopy.removeAll(oxTrustEmailSet); //Keep those in "mail" and not in oxTrustEmail
414  oxTrustEmailSet.removeAll(mailSet); //Keep those in oxTrustEmail and not in "mail"
415 
416  List<Integer> delIndexes=new ArrayList<Integer>();
417  //Build a list of indexes that should be removed in oxTrustEmails
418  for (int i=0;i<oxTrustEmails.size();i++) {
419  if (oxTrustEmailSet.contains(oxTrustEmails.get(i).getValue()))
420  delIndexes.add(0, i);
421  }
422  //Delete unmatched oxTrustEmail entries from highest index to lowest
423  for (Integer idx : delIndexes)
424  oxTrustEmails.remove(idx.intValue()); //must not pass an Integer directly
425 
426  List<String> newValues=new ArrayList<String>();
427  for (Email email : oxTrustEmails)
428  newValues.add(mapper.writeValueAsString(email));
429 
430  for (String mailStr : mailSetCopy){
431  Email email = new Email();
432  email.setValue(mailStr);
433  email.setPrimary(false);
434  newValues.add(mapper.writeValueAsString(email));
435  }
436 
437  gluuCustomPerson.setAttribute("oxTrustEmail", newValues.toArray(new String[0]));
438 
439  }
440 
441  logger.info(" LEAVING Utils.syncEmailReverse()...");
442 
443  return gluuCustomPerson;
444 
445  }
static Logger logger
Definition: ServiceUtil.java:47
static ObjectMapper getObjectMapper()
Definition: ServiceUtil.java:447
static final ObjectMapper mapper
Definition: ServiceUtil.java:62

メンバ詳解

◆ appConfiguration

AppConfiguration org.gluu.oxtrust.util.ServiceUtil.appConfiguration
private

◆ groupService

IGroupService org.gluu.oxtrust.util.ServiceUtil.groupService
private

◆ logger

Logger org.gluu.oxtrust.util.ServiceUtil.logger = LoggerFactory.getLogger(ServiceUtil.class)
staticprivate

◆ mapper

final ObjectMapper org.gluu.oxtrust.util.ServiceUtil.mapper = new ObjectMapper()
staticprivate

◆ personService

IPersonService org.gluu.oxtrust.util.ServiceUtil.personService
private

◆ random

final SecureRandom org.gluu.oxtrust.util.ServiceUtil.random = new SecureRandom()
staticprivate

◆ serialVersionUID

final long org.gluu.oxtrust.util.ServiceUtil.serialVersionUID = -2842459224631032594L
staticprivate

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