deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dev Khadka <dev.kha...@syntechnepal.com>
Subject Re: simple authentication
Date Tue, 03 Sep 2013 14:32:26 GMT
Please check this blog before moving to shiro
http://balusc.blogspot.com/2013/01/apache-shiro-is-it-ready-for-java-ee-6.html

Dev Khadka
Synergy Tech Software Pvt. Ltd.
e-Mail: dev.khadka@syntechnepal.com
Office: 977-1-5009085, 5526297
Mobile: +9779841358015

On 9/3/2013 7:30 PM, info@softwareentwicklung-hell.de wrote:
> Apache Shiro would be an alternative too.
>
> Quoting Kelly Goedert <kelly.goedert@gmail.com>:
>
>> Thanks. I will try picketlink/box
>>
>>
>> On Tue, Sep 3, 2013 at 10:42 AM, <info@softwareentwicklung-hell.de> 
>> wrote:
>>
>>> Hi,
>>>
>>> DeltaSpike doesn't provide an authentication mechanism.
>>>
>>> You could integrate Picketlink/Box or build your own. With an own 
>>> producer
>>> for current user (Take care of the annotation) you have nearly the same
>>> like seam. And for some role checking you can build an easy helper 
>>> class
>>> too. I did the last way and included something like that:
>>>
>>> @Named(value = "authenticator")
>>> @SessionScoped
>>> public class Authenticator implements Serializable {
>>>
>>>     /**
>>>      * Serial Version UID
>>>      */
>>>     private static final long serialVersionUID = 1L;
>>>
>>>
>>>
>>>     @Inject
>>>     private UserServiceLocal userService;
>>>
>>>     private String loginName;
>>>     private String password;
>>>
>>>     private User currentUser;
>>>
>>>
>>>     public String authenticate() {
>>>         if (null != currentUser) {
>>>             return "home?faces-redirect=true";
>>>         }
>>>         currentUser = userService.findByLoginName(**loginName);
>>>         if (null != currentUser) {
>>>             if(currentUser.getPassword().**equals(password)) {
>>>                 return "home?faces-redirect=true";
>>>             }
>>>             currentUser = null;
>>>         }
>>>         return "index?faces-redirect=true";
>>>     }
>>>
>>>     public String logout() {
>>>         currentUser = null; FacesContext.**getCurrentInstance().**
>>> getExternalContext().**invalidateSession();
>>>         return "index?faces-redirect=true";
>>>     }
>>>
>>>    @Named
>>>     @Produces
>>>     @CurrentUser
>>>     public User getCurrentUser() {
>>>         return currentUser;
>>>     }
>>>
>>>     /**
>>>      * @return the password
>>>      */
>>>     public String getPassword() {
>>>         return password;
>>>     }
>>>
>>>     /**
>>>      * @param password the password to set
>>>      */
>>>     public void setPassword(String password) {
>>>         this.password = password;
>>>     }
>>>
>>>     public String getLoginName() {
>>>         return loginName;
>>>     }
>>>
>>>     public void setLoginName(String loginName) {
>>>         this.loginName = loginName;
>>>     }
>>> }
>>>
>>> @Named
>>> @ViewScoped
>>> public class Security implements Serializable {
>>>
>>>     /**
>>>      * Serial Version UID
>>>      */
>>>     private static final long serialVersionUID = 1L;
>>>
>>>     @Inject
>>>     @CurrentUser
>>>     private User user;
>>>
>>>     @Inject
>>>     private SecurityServiceLocal securityService;
>>>
>>>     private List<String> roleNames;
>>>
>>>     @PostConstruct
>>>     public void init() {
>>>         if (null != user) {
>>>             roleNames = new ArrayList<String>();
>>>
>>>             for (SecurityRole role : 
>>> securityService.loadUserRoles(**user))
>>> {
>>>                 roleNames.add(role.getName());
>>>             }
>>>
>>>         }
>>>     }
>>>
>>>     public boolean hasRole(String roleName) {
>>>         if (null != roleNames && !roleNames.isEmpty() && null
!= 
>>> roleName)
>>> {
>>>             return roleNames.contains(roleName);
>>>         }
>>>         return false;
>>>     }
>>>
>>>     public boolean isAdmin() {
>>>         if (null != roleNames && !roleNames.isEmpty()) {
>>>             return roleNames.contains("ADMIN");
>>>         }
>>>         return false;
>>>     }
>>>
>>>     public boolean isLoggedIn() {
>>>         if (null != user) {
>>>             return true;
>>>         }
>>>         return false;
>>>     }
>>>
>>> Kind Regards
>>> Florian
>>>
>>>
>>> Quoting Kelly Goedert <kelly.goedert@gmail.com>:
>>>
>>>  Hi,
>>>>
>>>> I have a very simple application working with seam 3. It has a 
>>>> login and a
>>>> simple crud. Now I would like to migrate this simple example to
>>>> deltaspike.
>>>> I simply added deltaspike core and security dependencies, but I am 
>>>> missing
>>>> the dependencies for BaseAuthenticator and Authenticator interface.
>>>>
>>>> What dependencies I am missing? Is there an example on doing a simple
>>>> authentication process?
>>>>
>>>> Thanks
>>>>
>>>> Kelly
>>>>
>>>>
>>>
>>
>
>


Mime
View raw message