本文整理汇总了Java中hudson.security.SecurityRealm类的典型用法代码示例。如果您正苦于以下问题:Java SecurityRealm类的具体用法?Java SecurityRealm怎么用?Java SecurityRealm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SecurityRealm类属于hudson.security包,在下文中一共展示了SecurityRealm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validAnonymousViewStatusAccess
import hudson.security.SecurityRealm; //导入依赖的package包/类
/**
*
* @throws Exception
*/
@Test
public void validAnonymousViewStatusAccess() throws Exception {
final SecurityRealm realm = j.createDummySecurityRealm();
j.jenkins.setSecurityRealm(realm);
GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy();
auth.add(VIEW_STATUS, "anonymous");
j.getInstance().setSecurityRealm(realm);
j.getInstance().setAuthorizationStrategy(auth);
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();
try {
// try with wrong job name
wc.goTo("buildStatus/buildIcon?job=dummy");
fail("should fail, because there is no job with this name");
} catch (FailingHttpStatusCodeException x) {
assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
}
wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
j.buildAndAssertSuccess(project);
}
示例2: doImpersonate
import hudson.security.SecurityRealm; //导入依赖的package包/类
@RequirePOST
public HttpResponse doImpersonate(StaplerRequest req, @QueryParameter String name) {
Authentication auth = Jenkins.getAuthentication();
GrantedAuthority[] authorities = auth.getAuthorities();
if (authorities == null || StringUtils.isBlank(name)) {
return HttpResponses.redirectToContextRoot();
}
GrantedAuthority authority = null;
for (GrantedAuthority a : authorities) {
if (a.getAuthority().equals(name)) {
authority = a;
break;
}
}
if (authority == null) {
return HttpResponses.redirectToContextRoot();
}
if (!SecurityRealm.AUTHENTICATED_AUTHORITY.equals(authority)) {
ACL.impersonate(new ImpersonationAuthentication(auth, authority, SecurityRealm.AUTHENTICATED_AUTHORITY));
} else {
ACL.impersonate(new ImpersonationAuthentication(auth, SecurityRealm.AUTHENTICATED_AUTHORITY));
}
return HttpResponses.redirectToContextRoot();
}
示例3: createSecurityComponents
import hudson.security.SecurityRealm; //导入依赖的package包/类
@Override
public SecurityComponents createSecurityComponents() {
return new SecurityRealm.SecurityComponents(new AuthenticationManager() {
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
if (authentication instanceof DeepinAuthenticationToken) {
return authentication;
}
throw new BadCredentialsException("Unexpected authentication type: " + authentication);
}
}, new UserDetailsService() {
public UserDetails loadUserByUsername(String username) throws UserMayOrMayNotExistException, DataAccessException {
throw new UserMayOrMayNotExistException("Cannot verify users in this context");
}
});
}
示例4: fromUsernameAndEmail
import hudson.security.SecurityRealm; //导入依赖的package包/类
public static AppsCodeUserDetails fromUsernameAndEmail(String username, String email) {
return AppsCodeUserDetails.newBuilder()
.setUsername(username)
.setPassword("")
.setEmail(email)
.setEnabled(true)
.setAccountNonExpired(true)
.setCredentialsNonExpired(true)
.setAccountNonLocked(true)
.setAuthorities(new GrantedAuthority[]{SecurityRealm.AUTHENTICATED_AUTHORITY})
.build();
}
示例5: fromUser
import hudson.security.SecurityRealm; //导入依赖的package包/类
@Test
public void fromUser() throws Exception {
AppsCodeUserDetails expected1 = new AppsCodeUserDetails(testUserName, "", "[email protected]",
true, true, true, true, new GrantedAuthority[]{SecurityRealm.AUTHENTICATED_AUTHORITY});
AppsCodeUserDetails actual1 = AppsCodeUserDetails.fromUser("user1");
assertEquals(expected1, actual1);
AppsCodeUserDetails expected2 = new AppsCodeUserDetails(testUserName, "", "[email protected]",
true, true, true, true, new GrantedAuthority[]{SecurityRealm.AUTHENTICATED_AUTHORITY});
AppsCodeUserDetails actual2 = AppsCodeUserDetails.fromUser("hello");
assertNotEquals(expected2, actual2);
}
示例6: buildRoles
import hudson.security.SecurityRealm; //导入依赖的package包/类
private static GrantedAuthority[] buildRoles(AccessToken accessToken) {
List<GrantedAuthority> roles;
roles = new ArrayList<GrantedAuthority>();
if (accessToken != null && accessToken.getRealmAccess() != null) {
for (String role : accessToken.getRealmAccess().getRoles()) {
roles.add(new GrantedAuthorityImpl(role));
}
}
roles.add(SecurityRealm.AUTHENTICATED_AUTHORITY);
return roles.toArray(new GrantedAuthority[roles.size()]);
}
示例7: getSecurityRealm
import hudson.security.SecurityRealm; //导入依赖的package包/类
public final T getSecurityRealm() throws InvalidSecurityRealmException {
final SecurityRealm securityRealm = JenkinsDescriptorImpl.getJenkinsInstanceOrDie().getSecurityRealm();
if (isRegistrationForSecurityRealm(securityRealm)) {
//noinspection unchecked
return (T) JenkinsDescriptorImpl.getJenkinsInstanceOrDie().getSecurityRealm();
} else {
throw new InvalidSecurityRealmException();
}
}
示例8: getSecurityRealmRegistration
import hudson.security.SecurityRealm; //导入依赖的package包/类
@Override
@Nonnull
public SecurityRealmRegistration getSecurityRealmRegistration() {
final Jenkins jenkins = JenkinsDescriptorImpl.getJenkinsInstanceOrDie();
final SecurityRealm realm = jenkins.getSecurityRealm();
final List<SecurityRealmRegistration> allRegistrations = PluginModule.getDefault()
.getExtensionsProvider().getSecurityRealmRegistrations();
for (SecurityRealmRegistration instance : allRegistrations) {
if (instance.isRegistrationForSecurityRealm(realm)) {
return instance;
}
}
return StubSecurityRealmRegistration.INSTANCE;
}
示例9: getRedmineManager
import hudson.security.SecurityRealm; //导入依赖的package包/类
/**
* Return instance of {@link RedmineManager}
*
* @return
*/
RedmineManager getRedmineManager() {
SecurityRealm realm = Jenkins.getInstance().getSecurityRealm();
if (!(realm instanceof RedmineSecurityRealm)) {
LOGGER.error("Redmine manager not found");
return null;
}
return ((RedmineSecurityRealm) realm).getManager();
}
示例10: getGroups
import hudson.security.SecurityRealm; //导入依赖的package包/类
private GrantedAuthority[] getGroups(User user) {
Set<GrantedAuthority> groups = new HashSet<GrantedAuthority>();
for (Group group : user.getGroups()) {
groups.add(new RedmineGroupDetails(group.getName()));
}
groups.add(SecurityRealm.AUTHENTICATED_AUTHORITY);
return groups.toArray(new GrantedAuthority[groups.size()]);
}
示例11: getDescriptor
import hudson.security.SecurityRealm; //导入依赖的package包/类
@Override
public Descriptor<SecurityRealm> getDescriptor() {
return DESCRIPTOR;
}
示例12: newInstance
import hudson.security.SecurityRealm; //导入依赖的package包/类
@Override
public SecurityRealm newInstance(StaplerRequest req, JSONObject formData)
throws hudson.model.Descriptor.FormException {
return super.newInstance(req, formData);
}
示例13: isRegistrationForSecurityRealm
import hudson.security.SecurityRealm; //导入依赖的package包/类
@Override
public boolean isRegistrationForSecurityRealm(SecurityRealm realm) {
return HudsonPrivateSecurityRealm.class.isInstance(realm);
}
示例14: isRegistrationForSecurityRealm
import hudson.security.SecurityRealm; //导入依赖的package包/类
@Override
public boolean isRegistrationForSecurityRealm(SecurityRealm realm) {
return false;
}
示例15: getSecurityRealm
import hudson.security.SecurityRealm; //导入依赖的package包/类
@Nullable
SecurityRealm getSecurityRealm();