You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by mi...@apache.org on 2010/04/01 11:59:11 UTC
svn commit: r929901 - in
/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth:
AuthenticationChecker.java AuthenticationCheckerImpl.java
Author: mir
Date: Thu Apr 1 09:59:10 2010
New Revision: 929901
URL: http://svn.apache.org/viewvc?rev=929901&view=rev
Log:
extracted AuthenticationChecker interface
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationCheckerImpl.java
- copied, changed from r929890, incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationChecker.java
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationChecker.java
Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationChecker.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationChecker.java?rev=929901&r1=929900&r2=929901&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationChecker.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationChecker.java Thu Apr 1 09:59:10 2010
@@ -1,98 +1,41 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ * Copyright 2010 mir.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
*/
+
package org.apache.clerezza.platform.security.auth;
-import java.security.AccessController;
-import java.util.Iterator;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.ontologies.PERMISSION;
import org.wymiwyg.wrhapi.HandlerException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.clerezza.platform.config.SystemConfig;
-import org.apache.clerezza.platform.security.PasswordUtil;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.ontologies.PLATFORM;
-
/**
* A service that checks if a provided username and password matches a
- * username and password stored in the system graph
+ * username and password in credentials store.
*
* @author mir
*/
-@Component
-@Service(value=AuthenticationChecker.class)
-public class AuthenticationChecker {
-
- private final static Logger logger = LoggerFactory.getLogger(AuthenticationChecker.class);
-
- @Reference(target=SystemConfig.SYSTEM_GRAPH_FILTER)
- private MGraph systemGraph;
+public interface AuthenticationChecker {
/**
* Checks if the provided username and password matches a username and
- * password stored in the system graph
+ * password in credentials store.
* @param userName
* @param password
* @return true if the password matched, false otherwise
* @throws org.wymiwyg.wrhapi.HandlerException
* @throws org.apache.clerezza.platform.security.auth.NoSuchAgent
*/
- public boolean authenticate(String userName, String password) throws HandlerException, NoSuchAgent
- {
- AccessController.checkPermission(new CheckAuthenticationPermission());
- NonLiteral agent = getAgentFromGraph(userName);
- String storedPassword = getPasswordOfAgent(agent);
- if (storedPassword.equals(PasswordUtil.convertPassword(password))) {
- logger.debug("password matches");
- return true;
- } else {
- logger.debug("password didn't match ");
- return false;
- }
- }
-
- private NonLiteral getAgentFromGraph(String userName) throws NoSuchAgent {
- NonLiteral agent;
- Iterator<Triple> agents = systemGraph.filter(null, PLATFORM.userName, new PlainLiteralImpl(userName));
- if (agents.hasNext()) {
- agent = agents.next().getSubject();
- } else {
- logger.debug("no user {} in graph", userName);
- throw new NoSuchAgent();
- }
- return agent;
- }
+ boolean authenticate(String userName, String password) throws HandlerException, NoSuchAgent;
- private String getPasswordOfAgent(NonLiteral agent) {
- String storedPassword = "";
- Iterator<Triple> agentPassword = systemGraph.filter(agent, PERMISSION.passwordSha1, null);
- if (agentPassword.hasNext()) {
- storedPassword = ((Literal) agentPassword.next().getObject()).getLexicalForm();
- }
- return storedPassword;
- }
}
Copied: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationCheckerImpl.java (from r929890, incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationChecker.java)
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationCheckerImpl.java?p2=incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationCheckerImpl.java&p1=incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationChecker.java&r1=929890&r2=929901&rev=929901&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationChecker.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticationCheckerImpl.java Thu Apr 1 09:59:10 2010
@@ -44,10 +44,10 @@ import org.apache.clerezza.rdf.ontologie
* @author mir
*/
@Component
-@Service(value=AuthenticationChecker.class)
-public class AuthenticationChecker {
+@Service(value=AuthenticationCheckerImpl.class)
+public class AuthenticationCheckerImpl implements AuthenticationChecker {
- private final static Logger logger = LoggerFactory.getLogger(AuthenticationChecker.class);
+ private final static Logger logger = LoggerFactory.getLogger(AuthenticationCheckerImpl.class);
@Reference(target=SystemConfig.SYSTEM_GRAPH_FILTER)
private MGraph systemGraph;