| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SecurityUtils |
|
| 3.0;3 |
| 1 | /* | |
| 2 | * Copyright 2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php | |
| 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 | */ | |
| 16 | package org.kuali.rice.ksb.security.credentials; | |
| 17 | ||
| 18 | import org.acegisecurity.Authentication; | |
| 19 | import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; | |
| 20 | import org.acegisecurity.providers.x509.X509AuthenticationToken; | |
| 21 | import org.kuali.rice.core.security.credentials.Credentials; | |
| 22 | ||
| 23 | /** | |
| 24 | * | |
| 25 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 26 | * @since 0.9 | |
| 27 | * | |
| 28 | */ | |
| 29 | public class SecurityUtils { | |
| 30 | ||
| 31 | 0 | private SecurityUtils() { |
| 32 | // nothing to do | |
| 33 | 0 | } |
| 34 | ||
| 35 | public static Authentication convertCredentialsToSecurityContext(final Credentials credentials) { | |
| 36 | 0 | if (credentials instanceof X509Credentials) { |
| 37 | 0 | final X509Credentials c = (X509Credentials) credentials; |
| 38 | 0 | return new X509AuthenticationToken(c.getX509Certificate()); |
| 39 | 0 | } else if (credentials instanceof UsernamePasswordCredentials) { |
| 40 | 0 | final UsernamePasswordCredentials c = (UsernamePasswordCredentials) credentials; |
| 41 | 0 | return new UsernamePasswordAuthenticationToken(c.getUsername(), c.getPassword()); |
| 42 | } | |
| 43 | ||
| 44 | 0 | return null; |
| 45 | } | |
| 46 | ||
| 47 | } |