001    package railo.runtime.tag;
002    
003    import javax.servlet.jsp.tagext.Tag;
004    
005    import railo.commons.io.res.Resource;
006    import railo.runtime.exp.PageException;
007    import railo.runtime.ext.tag.TagImpl;
008    import railo.runtime.listener.ApplicationContext;
009    import railo.runtime.security.CredentialImpl;
010    import railo.runtime.type.KeyImpl;
011    import railo.runtime.type.scope.Scope;
012    
013    /**
014     * 
015     */
016    public final class Loginuser extends TagImpl {
017        private String name;
018        private String password;
019        private String[] roles;
020    
021            @Override
022            public void release()   {
023                    super.release();
024                    name=null;
025                    password=null;
026                    roles=null;
027            }
028    
029        /**
030         * @param name The name to set.
031         */
032        public void setName(String name) {
033            this.name = name;
034        }
035        /**
036         * @param password The password to set.
037         */
038        public void setPassword(String password) {
039            this.password = password;
040        }
041        /**
042         * @param oRoles The roles to set.
043         * @throws PageException
044         */
045        public void setRoles(Object oRoles) throws PageException {
046            roles=CredentialImpl.toRole(oRoles);
047        }
048        
049            @Override
050            public int doStartTag() throws PageException    {
051                    Resource rolesDir = pageContext.getConfig().getConfigDir().getRealResource("roles");
052                CredentialImpl login = new CredentialImpl(name,password,roles,rolesDir);
053                pageContext.setRemoteUser(login);
054                
055                Tag parent=getParent();
056                    while(parent!=null && !(parent instanceof Login)) {
057                            parent=parent.getParent();
058                    }
059                    ApplicationContext appContext = pageContext.getApplicationContext();
060                    if(parent!=null) {
061                        int loginStorage = appContext.getLoginStorage();
062                        String name=Login.getApplicationName(appContext);
063                        
064                        if(loginStorage==Scope.SCOPE_SESSION && pageContext.getApplicationContext().isSetSessionManagement())
065                            pageContext.sessionScope().set(KeyImpl.init(name),login.encode());
066                        else  {//if(loginStorage==Scope.SCOPE_COOKIE)
067                            pageContext.cookieScope().setCookie(KeyImpl.init(name),login.encode(),
068                                            -1,false,"/",Login.getCookieDomain(appContext));
069                        }
070                    }
071                    
072                
073                    return SKIP_BODY;
074            }
075    
076            @Override
077            public int doEndTag()   {
078                    return EVAL_PAGE;
079            }
080    }