本文整理汇总了Java中org.acegisecurity.context.SecurityContextHolder.getContext方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityContextHolder.getContext方法的具体用法?Java SecurityContextHolder.getContext怎么用?Java SecurityContextHolder.getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.acegisecurity.context.SecurityContextHolder
的用法示例。
在下文中一共展示了SecurityContextHolder.getContext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFilter
import org.acegisecurity.context.SecurityContextHolder; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
if(1 + 1 == 2) {
SecurityContext oldCtx = SecurityContextHolder.getContext();
SecurityContextHolder.setContext(null); //
try {
super.doFilter(req, res, chain);
} finally {
SecurityContextHolder.setContext(oldCtx);
}
}
else {
super.doFilter(req, res, chain);
}
}
示例2: retrieveDataElement
import org.acegisecurity.context.SecurityContextHolder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public CommonDataElement retrieveDataElement(Long dataElementId, Float dataElementVersion)
throws ConnectionException {
// Satish Patel informed me that the cadsrApi clears out the SecurityContext after they're done with it,
// they are working on a fix but as a workaround I need to store the context and set it again after
// I am done with all of the caDSR domain objects. --TJ
SecurityContext originalContext = SecurityContextHolder.getContext();
try {
List<Object> cadsrDataElements = searchDataElement(dataElementId, dataElementVersion);
gov.nih.nci.cadsr.domain.DataElement latestCadsrDataElement = getLatestDataElement(cadsrDataElements);
return convertCadsrDataElementToDataElements(latestCadsrDataElement);
} catch (Exception e) {
throw new ConnectionException("Couldn't connect to the caDSR server", e);
} finally {
// Restore context as described above.
SecurityContextHolder.setContext(originalContext);
}
}
示例3: test
import org.acegisecurity.context.SecurityContextHolder; //导入方法依赖的package包/类
@Override
public void test() {
SecurityContext sc = SecurityContextHolder.getContext();
if (sc.getAuthentication() != null)
System.out.println(sc.getAuthentication().getName()
+ " logged by test");
}
示例4: triggerJobs
import org.acegisecurity.context.SecurityContextHolder; //导入方法依赖的package包/类
public GogsResults triggerJobs(String jobName, String deliveryID) {
SecurityContext saveCtx = null;
GogsResults result = new GogsResults();
try {
saveCtx = SecurityContextHolder.getContext();
Jenkins instance = Jenkins.getActiveInstance();
if (instance!=null) {
ACL acl = instance.getACL();
acl.impersonate(ACL.SYSTEM);
BuildableItem project = GogsUtils.find(jobName, BuildableItem.class);
if (project != null) {
Cause cause = new GogsCause(deliveryID);
project.scheduleBuild(0, cause);
result.setMessage(String.format("Job '%s' is executed",jobName));
} else {
String msg = String.format("Job '%s' is not defined in Jenkins",jobName);
result.setStatus(404, msg);
LOGGER.warning(msg);
}
}
} catch (Exception e) {
} finally {
SecurityContextHolder.setContext(saveCtx);
}
return result;
}
示例5: retrieveValueDomainForDataElement
import org.acegisecurity.context.SecurityContextHolder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public ValueDomain retrieveValueDomainForDataElement(Long dataElementId, Float dataElementVersion)
throws ConnectionException {
ValueDomain valueDomain = new ValueDomain();
// Satish Patel informed me that the cadsrApi clears out the SecurityContext after they're done with it,
// they are working on a fix but as a workaround I need to store the context and set it again after
// I am done with all of the caDSR domain objects. --TJ
SecurityContext originalContext = SecurityContextHolder.getContext();
try {
List<Object> cadsrDataElements = searchDataElement(dataElementId, dataElementVersion);
if (!cadsrDataElements.isEmpty()) {
gov.nih.nci.cadsr.domain.ValueDomain cadsrValueDomain =
((gov.nih.nci.cadsr.domain.DataElement) cadsrDataElements.get(0)).getValueDomain();
// Default will be String, Character, Alphanumeric, and Alpha DVG
AnnotationTypeEnum annotationType = AnnotationTypeEnum.STRING;
String cadsrDataType = cadsrValueDomain.getDatatypeName();
if (cadsrDataType.matches("DATE")) {
annotationType = AnnotationTypeEnum.DATE;
}
if (cadsrDataType.matches("NUMBER")) {
annotationType = AnnotationTypeEnum.NUMERIC;
}
valueDomain.setDataType(annotationType);
valueDomain.setLongName(cadsrValueDomain.getLongName());
valueDomain.setPublicID(cadsrValueDomain.getPublicID());
if (cadsrValueDomain instanceof EnumeratedValueDomain) {
retrievePermissibleValues(valueDomain, cadsrValueDomain);
}
}
return valueDomain;
} catch (Exception e) {
throw new ConnectionException("Couldn't connect to the caDSR server", e);
} finally {
// Restore context as described above.
SecurityContextHolder.setContext(originalContext);
}
}
示例6: getLogin
import org.acegisecurity.context.SecurityContextHolder; //导入方法依赖的package包/类
protected String getLogin() {
SecurityContext sc = SecurityContextHolder.getContext();
if (sc.getAuthentication() == null)
return null;
return sc.getAuthentication().getName();
}
示例7: getSecurityContext
import org.acegisecurity.context.SecurityContextHolder; //导入方法依赖的package包/类
private SecurityContext getSecurityContext() {
return SecurityContextHolder.getContext();
}