Changeset 339:f018669698a8


Ignore:
Timestamp:
09/16/11 20:35:43 (5 months ago)
Author:
xeraph
Branch:
default
Convert:
svn:7c3792e6-d75b-4784-96a6-b298f655ee64/trunk@2773
Message:

added admin login access control by remote ip.

Location:
kraken-dom
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • kraken-dom/pom.xml

    r329 r339  
    1111        <groupId>org.krakenapps</groupId> 
    1212        <artifactId>kraken-dom</artifactId> 
    13         <version>1.2.16</version> 
     13        <version>1.2.17</version> 
    1414        <packaging>bundle</packaging> 
    1515        <name>Kraken DOM</name> 
  • kraken-dom/src/main/java/org/krakenapps/dom/api/impl/AdminApiImpl.java

    r337 r339  
    3737import org.krakenapps.dom.api.OtpApi; 
    3838import org.krakenapps.dom.api.UserExtensionProvider; 
     39import org.krakenapps.dom.exception.AccessControlException; 
    3940import org.krakenapps.dom.exception.AdminLockedException; 
    4041import org.krakenapps.dom.exception.CannotRemoveRequestingAdminException; 
     
    7980        public Admin login(Session session, String nick, String hash, boolean force) throws LoginFailedException { 
    8081                Admin admin = getAdmin(nick, session); 
     82 
     83                // check acl (trust host) 
     84                checkAcl(session, admin); 
     85 
     86                // check password 
    8187                String password = null; 
    82  
    8388                if (otpApi != null && admin.isUseOtp()) 
    8489                        password = Sha1.hash(otpApi.getOtpValue(admin.getOtpSeed())); 
     
    8792 
    8893                if (hash.equals(Sha1.hash(password + session.getString("nonce")))) { 
    89                         OrganizationParameter param = orgParamApi.getOrganizationParameter(admin.getUser().getOrganization() 
    90                                         .getId(), "max_sessions"); 
     94                        OrganizationParameter param = orgParamApi.getOrganizationParameter(admin.getUser().getOrganization().getId(), 
     95                                        "max_sessions"); 
    9196                        if (param != null) { 
    9297                                try { 
     
    111116                        for (LoginCallback callback : callbacks) 
    112117                                callback.onLoginSuccess(admin, session); 
    113                         loggedIn.add(new LoggedInAdmin(admin.getRole().getLevel(), new Date(), session, admin.getUser() 
    114                                         .getLoginName())); 
     118                        loggedIn.add(new LoggedInAdmin(admin.getRole().getLevel(), new Date(), session, admin.getUser().getLoginName())); 
    115119                        return admin; 
    116120                } else { 
     
    122126                        else 
    123127                                throw new InvalidPasswordException(); 
     128                } 
     129        } 
     130 
     131        private void checkAcl(Session session, Admin admin) { 
     132                if (admin.isUseAcl()) { 
     133                        boolean found = false; 
     134                        String remote = session.getRemoteAddress().getHostAddress(); 
     135 
     136                        for (AdminTrustHost h : admin.getTrustHosts()) 
     137                                if (h.getIp() != null && h.getIp().equals(remote)) 
     138                                        found = true; 
     139 
     140                        if (!found) { 
     141                                updateLoginFailures(admin, false); 
     142                                throw new AccessControlException(); 
     143                        } 
    124144                } 
    125145        } 
  • kraken-dom/src/main/java/org/krakenapps/dom/exception/InvalidOtpPasswordException.java

    r328 r339  
     1/* 
     2 * Copyright 2011 Future Systems, Inc. 
     3 *  
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 *  
     8 * http://www.apache.org/licenses/LICENSE-2.0 
     9 *  
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package org.krakenapps.dom.exception; 
    217 
  • kraken-dom/src/main/java/org/krakenapps/dom/exception/LoginFailedException.java

    r314 r339  
     1/* 
     2 * Copyright 2011 Future Systems, Inc. 
     3 *  
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 *  
     8 * http://www.apache.org/licenses/LICENSE-2.0 
     9 *  
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package org.krakenapps.dom.exception; 
    217 
  • kraken-dom/src/main/java/org/krakenapps/dom/exception/MaxSessionException.java

    r323 r339  
     1/* 
     2 * Copyright 2011 Future Systems, Inc. 
     3 *  
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 *  
     8 * http://www.apache.org/licenses/LICENSE-2.0 
     9 *  
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package org.krakenapps.dom.exception; 
    217 
Note: See TracChangeset for help on using the changeset viewer.