org.acegisecurity.Authentication类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中org.acegisecurity.Authentication类的一些代码示例,展示了Authentication类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Authentication类的具体详情如下:
包路径:org.acegisecurity.Authentication
类名称:Authentication

Authentication介绍

[英]Represents an authentication request.

An Authentication object is not considered authenticated until it is processed by an AuthenticationManager.

Stored in a request org.acegisecurity.context.SecurityContext.
[中]表示身份验证请求。
Authentication对象在由AuthenticationManager处理之前,不会被视为经过身份验证。
存储在请求组织中。无安全性。上下文SecurityContext。

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Checks if the current security principal has the permission to create views within the specified view group.
 * <p>
 * This is just a convenience function.
 *
 * @param c the container of the item.
 * @param d the descriptor of the view to be created.
 * @throws AccessDeniedException if the user doesn't have the permission.
 * @since 1.607
 */
public final void checkCreatePermission(@Nonnull ViewGroup c,
                    @Nonnull ViewDescriptor d) {
  Authentication a = Jenkins.getAuthentication();
  if (a == SYSTEM) {
    return;
  }
  if (!hasCreatePermission(a, c, d)) {
    throw new AccessDeniedException(Messages.AccessDeniedException2_MissingPermission(a.getName(),
        View.CREATE.group.title + "/" + View.CREATE.name + View.CREATE + "/" + d.getDisplayName()));
  }
}

代码示例来源:origin: jenkinsci/jenkins

protected Boolean _hasPermission(@Nonnull Authentication a, Permission permission) {
    LOGGER.finer("hasPermission(PrincipalSID:"+a.getPrincipal()+","+permission+")=>"+b);
  if(b!=null)
    return b;
  for(GrantedAuthority ga : a.getAuthorities()) {
    b = hasPermission(new GrantedAuthoritySid(ga),permission);
    if(LOGGER.isLoggable(FINER))

代码示例来源:origin: jenkinsci/jenkins

if(existingAuth == null || !existingAuth.isAuthenticated()) {
  return true;
if (existingAuth instanceof UsernamePasswordAuthenticationToken && !existingAuth.getName().equals(username)) {
  return true;

代码示例来源:origin: jenkinsci/jenkins

private CLIUserDetails(Authentication auth) {
    super(auth.getName(), "", true, true, true, true, auth.getAuthorities());
  }
}

代码示例来源:origin: jenkinsci/jenkins

protected int run() {
    Authentication a = Jenkins.getAuthentication();
    stdout.println("Authenticated as: "+a.getName());
    stdout.println("Authorities:");
    for (GrantedAuthority ga : a.getAuthorities()) {
      stdout.println("  "+ga.getAuthority());
    }
    return 0;
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Override
protected void loggedIn(@Nonnull String username) {
  try {
    // user should have been created but may not have been saved for some realms
    // but as this is a callback of a successful login we can safely create the user.
    User u = User.getById(username, true);
    LastGrantedAuthoritiesProperty o = u.getProperty(LastGrantedAuthoritiesProperty.class);
    if (o==null)
      u.addProperty(o=new LastGrantedAuthoritiesProperty());
    Authentication a = Jenkins.getAuthentication();
    if (a!=null && a.getName().equals(username))
      o.update(a);    // just for defensive sanity checking
  } catch (IOException e) {
    LOGGER.log(Level.WARNING, "Failed to record granted authorities",e);
  }
}

代码示例来源:origin: org.jenkins-ci.plugins/credentials

@Override
  public boolean hasPermission(@Nonnull Authentication a, @Nonnull Permission permission) {
    return user.equals(User.get(a.getName())) && user.getACL().hasPermission(a, permission);
  }
};

代码示例来源:origin: jenkinsci/jenkins

/**
 * Persist the information with the new {@link UserDetails}.
 */
public void update(@Nonnull Authentication auth) throws IOException {
  List<String> roles = new ArrayList<String>();
  for (GrantedAuthority ga : auth.getAuthorities()) {
    roles.add(ga.getAuthority());
  }
  String[] a = roles.toArray(new String[roles.size()]);
  if (!Arrays.equals(this.roles,a)) {
    this.roles = a;
    this.timestamp = System.currentTimeMillis();
    user.save();
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Override
@Nonnull
public ACL getACL() {
  ACL base = Jenkins.get().getAuthorizationStrategy().getACL(this);
  // always allow a non-anonymous user full control of himself.
  return ACL.lambda((a, permission) -> (idStrategy().equals(a.getName(), id) && !(a instanceof AnonymousAuthenticationToken))
      || base.hasPermission(a, permission));
}

代码示例来源:origin: jenkinsci/jenkins

public @Nonnull
List<String> getAuthorities() {
  if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
    return Collections.emptyList();
  Authentication authentication;
  try {
    authentication = impersonate();
  } catch (UsernameNotFoundException x) {
    LOGGER.log(Level.FINE, "cannot look up authorities for " + id, x);
    return Collections.emptyList();
  for (GrantedAuthority a : authentication.getAuthorities()) {
    if (a.equals(SecurityRealm.AUTHENTICATED_AUTHORITY)) {
      continue;
    if (n != null && !idStrategy().equals(n, id)) {
      r.add(n);

代码示例来源:origin: jenkinsci/jenkins

private void checkIfNameIsUsed(@Nonnull String newName) throws Failure {
  try {
    Item item = getParent().getItem(newName);
          LOGGER.log(Level.FINE, "Unable to rename the job {0}: name {1} is already in use. " +
              "User {2} has no {3} permission for existing job with the same name",
              new Object[] {this.getFullName(), newName, ctx.getPreviousContext().getAuthentication().getName(), Item.DISCOVER.name} );
      LOGGER.log(Level.FINE, "Unable to rename the job {0}: name {1} is already in use. " +
          "User {2} has {3} permission, but no {4} for existing job with the same name",
          new Object[] {this.getFullName(), newName, User.current(), Item.DISCOVER.name, Item.READ.name} );

代码示例来源:origin: jenkinsci/jenkins

protected final void execute(@Nonnull RunExecution job) {
  if(result!=null)
    return;     // already built.
        listener.started(getCauses());
        Authentication auth = Jenkins.getAuthentication();
        if (!auth.equals(ACL.SYSTEM)) {
          String id = auth.getName();
          if (!auth.equals(Jenkins.ANONYMOUS)) {
            final User usr = User.getById(id, false);
            if (usr != null) { // Encode user hyperlink for existing users
              id = ModelHyperlinkNote.encodeTo(usr);

代码示例来源:origin: jenkinsci/jenkins

@Override
  public boolean shouldTriggerBuild(AbstractBuild build, TaskListener listener,
                   List<Action> actions) {
    AbstractProject downstream = getDownstreamProject();
    if (Jenkins.getInstance().getItemByFullName(downstream.getFullName()) != downstream) { // this checks Item.READ also on parent folders
      LOGGER.log(Level.WARNING, "Running as {0} cannot even see {1} for trigger from {2}", new Object[] {Jenkins.getAuthentication().getName(), downstream, getUpstreamProject()});
      return false; // do not even issue a warning to build log
    }
    if (!downstream.hasPermission(Item.BUILD)) {
      listener.getLogger().println(Messages.BuildTrigger_you_have_no_permission_to_build_(ModelHyperlinkNote.encodeTo(downstream)));
      return false;
    }
    return build.getResult().isBetterOrEqualTo(threshold);
  }
});

代码示例来源:origin: org.jvnet.hudson.plugins/favorite

public String getStar(String job) {
  Authentication authentication = Hudson.getAuthentication();
  String name = authentication.getName();
  User user = Hudson.getInstance().getUser(name);
  FavoriteUserProperty fup = user.getProperty(FavoriteUserProperty.class);
  if (fup == null || !fup.isJobFavorite(job)) {
    return "star.gif";
  } else {
    return "star-gold.gif";
  }
}

代码示例来源:origin: hudson/hudson-2.x

/**
 * Persists the specified authentication.
 */
public void set(Authentication a) throws IOException, InterruptedException {
  Hudson h = Hudson.getInstance();
  // make sure that this security realm is capable of retrieving the authentication by name,
  // as it's not required.
  UserDetails u = h.getSecurityRealm().loadUserByUsername(a.getName());
  props.setProperty(getPropertyKey(), Secret.fromString(u.getUsername()).getEncryptedValue());
  save();
}

代码示例来源:origin: org.jenkins-ci.plugins/collabnet

FilterChain chain) throws IOException, ServletException {
if (Hudson.getInstance().isUseSecurity()) {
  SecurityRealm securityRealm = Hudson.getInstance().getSecurityRealm();
  if (securityRealm instanceof CollabNetSecurityRealm) {
    CollabNetSecurityRealm cnRealm = (CollabNetSecurityRealm) securityRealm;
      if (username != null) {
        if (!username.equals(auth.getName())) {
          auth.setAuthenticated(false);
      if (!auth.isAuthenticated() || auth.getPrincipal().equals("anonymous")) {
        loginHudsonUsingCTFSSO((CollabNetSecurityRealm)securityRealm, httpRequest);

代码示例来源:origin: jenkinsci/jenkins

public RestartJenkinsJob(UpdateSite site) {
  super(site);
  this.authentication = Jenkins.getAuthentication().getName();
}

代码示例来源:origin: jenkinsci/jenkins

Jenkins h = Jenkins.getActiveInstance();
UserDetails u = h.getSecurityRealm().loadUserByUsername(a.getName());
String username = u.getUsername();
  user = null;
} else {
  user = User.getById(a.getName(), false);
UserSeedProperty userSeedProperty = user.getProperty(UserSeedProperty.class);
if (userSeedProperty == null) {
  userSeed = "no-user-seed";

代码示例来源:origin: hudson/hudson-2.x

/**
 * Gets the {@link User} object representing the currently logged-in user, or null
 * if the current user is anonymous.
 * @since 1.172
 */
public static User current() {
  Authentication a = Hudson.getAuthentication();
  if(a instanceof AnonymousAuthenticationToken)
    return null;
  return get(a.getName());
}

代码示例来源:origin: jenkinsci/gerrit-trigger-plugin

/**
 * Standard Constructor.
 * @param event the event.
 * @param silentMode if silentMode.
 * @param context the context.
 */
public GerritUserCause(GerritTriggeredEvent event, boolean silentMode, TriggerContext context) {
  super(event, silentMode, context);
  this.authenticationName = Hudson.getAuthentication().getName();
}

相关文章