use of java.security.PrivilegedAction in project Payara by payara.
the class SecurityMechanismSelector method getTargetName.
// Returns the target_name from PasswordCredential in Subject subj
// subj must contain a single instance of PasswordCredential.
private byte[] getTargetName(Subject subj) {
byte[] tgt_name = {};
final Subject sub = subj;
final Set<PasswordCredential> credset = AccessController.doPrivileged(new PrivilegedAction<Set>() {
@Override
public Set run() {
return sub.getPrivateCredentials(PasswordCredential.class);
}
});
if (credset.size() == 1) {
tgt_name = AccessController.doPrivileged(new PrivilegedAction<byte[]>() {
@Override
public byte[] run() {
Iterator<PasswordCredential> iter = credset.iterator();
PasswordCredential pc = iter.next();
return pc.getTargetName();
}
});
}
return tgt_name;
}
use of java.security.PrivilegedAction in project Payara by payara.
the class ServerLoginCBHUtil method processGP.
private static void processGP(GroupPrincipalCallback gpCallback) {
final Subject fs = gpCallback.getSubject();
final String[] groups = gpCallback.getGroups();
if (groups != null && groups.length > 0) {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
for (String group : groups) {
fs.getPrincipals().add(new Group(group));
}
return fs;
}
});
} else if (groups == null) {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
Set<Principal> principalSet = fs.getPrincipals();
principalSet.removeAll(fs.getPrincipals(Group.class));
return fs;
}
});
}
}
use of java.security.PrivilegedAction in project Payara by payara.
the class RealmAdapter method getSecurityContextForPrincipal.
// Moved from J2EEInstanceListener.java
private SecurityContext getSecurityContextForPrincipal(final Principal p) {
if (p == null) {
return null;
} else if (p instanceof WebPrincipal) {
return ((WebPrincipal) p).getSecurityContext();
} else {
return AccessController.doPrivileged(new PrivilegedAction<SecurityContext>() {
@Override
public SecurityContext run() {
Subject s = new Subject();
s.getPrincipals().add(p);
return new SecurityContext(p.getName(), s);
}
});
}
}
use of java.security.PrivilegedAction in project Payara by payara.
the class CommandSecurityChecker method authorize.
/**
* Reports whether the Subject is allowed to perform the specified admin command.
* @param subject Subject for the current user to authorize
* @param env environmental settings that might be used in the resource name expression
* @param command the admin command the Subject wants to execute
* @return
*/
public boolean authorize(Subject subject, final Map<String, Object> env, final AdminCommand command, final AdminCommandContext adminCommandContext) throws SecurityException {
if (subject == null) {
ADMSEC_AUTHZ_LOGGER.log(Level.WARNING, command.getClass().getName(), new IllegalArgumentException("subject"));
subject = new Subject();
}
boolean result;
try {
if (command instanceof AdminCommandSecurity.Preauthorization) {
/*
* Invoke preAuthorization in the context of the Subject.
*/
result = Subject.doAs(subject, new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return ((AdminCommandSecurity.Preauthorization) command).preAuthorization(adminCommandContext);
}
});
if (!result) {
return false;
}
}
final List<AccessCheckWork> accessChecks = assembleAccessCheckWork(command, subject);
result = (embeddedSystemAdministrator.matches(subject)) || checkAccessRequired(subject, env, command, accessChecks);
} catch (Exception ex) {
ADMSEC_AUTHZ_LOGGER.log(Level.SEVERE, AdminLoggerInfo.mUnexpectedException, ex);
throw new RuntimeException(ex);
}
/*
* Check the result and throw the SecurityException outside the previous
* try block. Otherwise the earlier catch will dump the stack which we
* do not need for simple authorization errors.
*/
if (!result) {
// }
throw new SecurityException();
}
return result;
}
use of java.security.PrivilegedAction in project Payara by payara.
the class EJBSecurityManager method postInvoke.
/**
* This method is used by Message Driven Bean Container to remove
* the run-as identity information that was set up using the
* preSetRunAsIdentity method
*/
public void postInvoke(ComponentInvocation inv) {
if (runAs != null && inv.isPreInvokeDone()) {
final ComponentInvocation finv = inv;
AppservAccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
SecurityContext.setCurrent((SecurityContext) finv.getOldSecurityContext());
return null;
}
});
}
}
Aggregations