-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Valentin Delaye <jonesbusy@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
172 additions
and
7 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/main/java/org/jenkinsci/plugins/oic/OicAvatarProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.jenkinsci.plugins.oic; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import hudson.model.User; | ||
import hudson.model.UserProperty; | ||
import hudson.model.UserPropertyDescriptor; | ||
import java.util.logging.Logger; | ||
|
||
public class OicAvatarProperty extends UserProperty { | ||
private static final Logger LOGGER = Logger.getLogger(OicAvatarProperty.class.getName()); | ||
|
||
private final AvatarImage avatarImage; | ||
|
||
public OicAvatarProperty(AvatarImage avatarImage) { | ||
this.avatarImage = avatarImage; | ||
} | ||
|
||
public String getAvatarUrl() { | ||
if (isHasAvatar()) { | ||
return getAvatarImageUrl(); | ||
} | ||
return null; | ||
} | ||
|
||
private String getAvatarImageUrl() { | ||
return avatarImage.url; | ||
} | ||
|
||
public boolean isHasAvatar() { | ||
return avatarImage != null && avatarImage.isValid(); | ||
} | ||
|
||
public String getDisplayName() { | ||
return "Openid Connect Avatar"; | ||
} | ||
|
||
public String getIconFileName() { | ||
return null; | ||
} | ||
|
||
public String getUrlName() { | ||
return "oic-avatar"; | ||
Check warning on line 43 in src/main/java/org/jenkinsci/plugins/oic/OicAvatarProperty.java
|
||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends UserPropertyDescriptor { | ||
|
||
@Override | ||
@NonNull | ||
public String getDisplayName() { | ||
return "Openid Connect Avatar"; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public UserProperty newInstance(User user) { | ||
return new OicAvatarProperty(null); | ||
} | ||
} | ||
|
||
/** | ||
* OIC avatar is standard picture field on the profile claim. | ||
*/ | ||
public static class AvatarImage { | ||
private final String url; | ||
|
||
public AvatarImage(String url) { | ||
this.url = url; | ||
} | ||
|
||
public boolean isValid() { | ||
return url != null; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/jenkinsci/plugins/oic/OicAvatarResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.jenkinsci.plugins.oic; | ||
|
||
import hudson.Extension; | ||
import hudson.model.User; | ||
import hudson.tasks.UserAvatarResolver; | ||
|
||
@Extension | ||
public class OicAvatarResolver extends UserAvatarResolver { | ||
@Override | ||
public String findAvatarFor(User user, int width, int height) { | ||
if (user != null) { | ||
OicAvatarProperty avatarProperty = user.getProperty(OicAvatarProperty.class); | ||
if (avatarProperty != null) { | ||
return avatarProperty.getAvatarUrl(); | ||
} | ||
} | ||
return null; | ||
Check warning on line 17 in src/main/java/org/jenkinsci/plugins/oic/OicAvatarResolver.java
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters