use of org.glassfish.api.admin.Job in project Payara by payara.
the class JobAuthorizationAttributeProcessor method describeAuthorization.
@Override
public void describeAuthorization(Subject subject, String resourceName, String action, AdminCommand command, Map<String, Object> context, Map<String, String> subjectAttributes, Map<String, String> resourceAttributes, Map<String, String> actionAttributes) {
final Matcher m = JOB_PATTERN.matcher(resourceName);
if (!m.matches()) {
return;
}
if (m.groupCount() == 0) {
/*
* The resource name pattern did not match for including a job ID,
* so we will not be able to attach a user attribute to the resource.
*/
return;
}
final String jobID = m.group(1);
final Job job = jobManager.get(jobID);
String userID = null;
/*
* This logic might run before any validation in the command has run,
* in which case the job ID would be invalid and the job manager and/or
* the completed jobs store might not know about the job.
*/
if (job != null && job.getSubjectUsernames().size() > 0) {
userID = job.getSubjectUsernames().get(0);
} else {
if (jobManager.getCompletedJobs(jobManager.getJobsFile()) != null) {
final JobInfo jobInfo = (JobInfo) jobManager.getCompletedJobForId(jobID);
if (jobInfo != null) {
userID = jobInfo.user;
}
}
}
if (userID != null) {
resourceAttributes.put(USER_ATTRIBUTE_NAME, userID);
}
}